function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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

 
Thomas Shelby 26Thomas Shelby 26
Welcome to our comprehensive and dependable roadside assistance services for both people and businesses. 
https://www.drogowapomoc.com.pl/