Convert Lead Automatically Using Trigger:-
Scenario:- Convert Lead Automatically when Convert_Now__c check box is true in Lead record.
Step 1:- Create Convert_Now__c check box custom field in Lead object
Step 2:- Write a Trigger in Lead object
trigger convert_Lead on Lead (after insert,after update) {
for(Lead led : Trigger.New){
Lead ledold=Trigger.Isinsert?new Lead() : trigger.oldmap.get(led.id);
if(led.Convert_Now__c!=ledold.Convert_Now__c && led.Convert_Now__c==true){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(led.id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.convertLead(lc);
}
}
}
The Above Trigger Converts the Lead Record when Convert_Now__c check box is true.
No comments:
Post a Comment