I am working on detail javascript button in the lead object. But now I am facing the below issue.
Javascript code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
var parent = "{!Lead.Parent_LeadId__c}";
If(parent === "")
{
alert("pop up");
}
else
{
sforce.apex.execute("SwapRecords","ChangeMaster",{ID:"{!Lead.Id}",ID:"{!Lead.Parent_LeadId__c}"});
}
Apex class:
global class SwapRecords {
webservice static void ChangeMaster(Id changetomaster,Id CurrentMaster)
{
List<Lead> UpdateLeads = new List<Lead>();
for(Lead ls:[Select id,Parent_Lead__c from lead where Parent_Lead__c=:CurrentMaster OR id=:CurrentMaster ])
{
If(ls.Id == changetomaster)
{
ls.Parent_Lead__c='';
UpdateLeads.add(ls);
}
else
{
ls.Parent_Lead__c=changetomaster;
UpdateLeads.add(ls);
}
}
If(UpdateLeads !=null && !UpdateLeads.isEmpty() )
{
update UpdateLeads;
}
}
}
Please help where I did wrong
Parent_Lead__c
? I suspect it's a String and contains a quotation mark.