I'm working on creating a button on the lead object that will insert the fields into a custom object.
I can't get my trigger to work, and I'm not sure what I'm doing wrong. Here is the code for the button:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}
//Calling Class and Method
var result = sforce.apex.execute(
"LeadConversion",
"copyAppDetails",
{
LeadId : "{! Lead.Id }"
}
);
if(result=="Error")
{
window.alert("Copy Failed! Error has occurred");
}
else
{
window.alert(
'The Application details have been successfully copied to the Contact'
);
}
Here is my trigger:
global class LeadConversion{
webService
static String copyAppDetails(Id LeadId){
List<Lead> lstLead =
[
SELECT
Id,
Name
FROM
Lead
WHERE
Id = :LeadId
];
List <Application__c> lstApp = new List<Application__c>();
for(Lead app : lstLead){
lstApp.add(
new Application__c(
Id = app.Id,
Name = app.Name
)
);
}
try{
INSERT lstApp;
return lstApp[0].Id;
}
catch (Exception ex){
return('Error');
}
}
}
Here is my error message when I click the button:
{faultcode:'soapenv:Client', faultstring:'System.TypeException: Invalid id value for this SObject type: 00Q7A00000259eJUAQ
Class.LeadConversion.copyAppDetails: line 22, column 1', }