You need to sign in to do that
Don't have an account?
Rishabh Patel 1
Convert Apex class to Batch Apex
I have an apex class that gets the Leads from the Query in the metadada and does some basic updates on leads and adds them in campaign
The class is working fine, But I wanter to make is Batchable in case I get more than 100 records.
Here is my apex class -
public with sharing class leadtester implements Schedulable { public list<Lead> quo{get;set;} public void execute(SchedulableContext ctx){ Leads__mdt [] leadVals = [SELECT Final_Query__c FROM Leads__mdt ]; list<Leads__mdt> u = [SELECT Retention_Updated_Queue__c,Add_to_Campaign__c FROM Leads__mdt ]; quo= Database.query(leadVals[0].Final_Query__c ); for(Lead ldt :quo){ if(ldt != null ) { //Update those leads with new owner ID string test = ldt.OwnerId; list<Group> v = [Select name from Group where ID =:test]; ldt.Previous_Lead_Owner__c = v[0].name; ldt.Lead_Status_at_Last_Retention__c = ldt.Status; ldt.OwnerId = u[0].Retention_Updated_Queue__c; ldt.Last_Retention_Date__c = Datetime.now(); ldt.Retention_Count__c = ldt.Retention_Count__c +1 ; if(u[0].Add_to_Campaign__c !=Null){ CampaignMember mem = new CampaignMember (campaignid=u[0].Add_to_Campaign__c, leadid=ldt.id); database.insert (mem, false); } } update quo; } } }
All Answers