Apex Class:
global class ApexMethodFromButton {
webservice static void updateLead(Id leadId) {
Lead newLead = [select id,Name,LastName,company from Lead where id=:leadId];
if(newLead != null && newLead.LastName != null) {
if(newLead.name.contains('test')) {
newLead.company = newLead.LastName ;
update newLead;
}
}
}
}
Custom Button :
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var r = confirm("Are you sure want to update the company?");
if(r == true)
{
sforce.apex.execute("ApexMethodFromButton","updateLead",{leadId:"{!Lead.Id}"});
location.reload(true);
}
Output:
global class ApexMethodFromButton {
webservice static void updateLead(Id leadId) {
Lead newLead = [select id,Name,LastName,company from Lead where id=:leadId];
if(newLead != null && newLead.LastName != null) {
if(newLead.name.contains('test')) {
newLead.company = newLead.LastName ;
update newLead;
}
}
}
}
Custom Button :
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var r = confirm("Are you sure want to update the company?");
if(r == true)
{
sforce.apex.execute("ApexMethodFromButton","updateLead",{leadId:"{!Lead.Id}"});
location.reload(true);
}
Output:
No comments:
Post a Comment