+ Start a Discussion
Danielle Pulley 10Danielle Pulley 10 

How to add more then one lead source in Apex Code ?

Here is my trigger. I am not sure how to reference 3 different lead sources for the Lead to sutomatically convert. 

I need only the Leads whose lead source = Academy Regisatration, User Registration or  Organization Registration. 

Any help is appreciated!




I now got it to work. But how do I add more than one lead source? I only want it to run when the lead source is Academy Registration, User Registration or Organization Registration. 

trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.LeadSource = 'Academy Registration')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Qualified';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(true);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
        }
        }
}
Amit Chaudhary 8Amit Chaudhary 8
Try like below
trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
	List<String> LeadNames = new List<String>{};
		for(Lead myLead: Trigger.new){
		if((myLead.isconverted==false) && ( myLead.LeadSource = 'Academy Registration' ||  myLead.LeadSource =='User Registration ' || myLead.LeadSource =='Organization Registration' )) 
		{
			Database.LeadConvert lc = new database.LeadConvert();
			lc.setLeadId(myLead.Id);
			lc.convertedStatus = 'Qualified';
			//Database.ConvertLead(lc,true);
			lc.setDoNotCreateOpportunity(true);
			Database.LeadConvertResult lcr = Database.convertLead(lc);
			System.assert(lcr.isSuccess());
		}
	}
}

Let us know if this will help you