You need to sign in to do that
Don't have an account?
sumit d
Batch to set checkbox field to true on lead object
Hi All,
i have a requirement in which i have a field on lead object called ToBeDeleted__c, which should be true when one of the following condition is true :-
1.lead name contains 'test'
2.The owner of the lead is inactive.
3.lead has duplicate records than last created record need to be checked.
4.lead is created 1 year or more than one year ago.
I want to create a batch which set the checkbox field true when above condition met.
How to do it ?Can someone guide me with it?
Thanks
i have a requirement in which i have a field on lead object called ToBeDeleted__c, which should be true when one of the following condition is true :-
1.lead name contains 'test'
2.The owner of the lead is inactive.
3.lead has duplicate records than last created record need to be checked.
4.lead is created 1 year or more than one year ago.
I want to create a batch which set the checkbox field true when above condition met.
How to do it ?Can someone guide me with it?
Thanks
As per my perception, this code will work for you. If you found it useful please appreciate my efforts and mark it as the best answer.
LinkedIn: https://www.linkedin.com/in/soyab-hussain-b380b1194/ (https://www.linkedin.com/in/soyab-hussain-b380b1194/ )
Regards,
Soyab
All Answers
I did not understand the third point, Can you please give more description of the same.
Regards,
Soyab
Third point is if two lead records has same name than the record which has created later will have the checkbox field set to true.
Hope you can guide me with it?
Thanks
Form your query and the update on the result.
Something like this will do 1 and 4.
You need a sub query to get inactive owner.
Duplicate records is much more complex...
Hope this helps a little.
It's a good idea to check your query in the Query Editor as I just did.
The correct syntax is
My batch is given below:-
public class BatchLeadCleansing implements Database.Batchable<sObject>{
//Run method to check the Batch on one record
public static void run( Set<Id> leadIds ) {
List<Lead> leadRecords = [SELECT id,ToBeDeleted__c,CreatedDate,Name,Owner.IsActive
FROM Lead
WHERE ID IN : leadIds
];
executeHelper( leadRecords );
}
public Database.querylocator start(Database.BatchableContext BC){
String query ='SELECT id,ToBeDeleted__c,CreatedDate,'+
'Name,Owner.IsActive' +
'FROM Lead';
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC, List<lead> leads ){
executeHelper( leads );
}
public static void executeHelper( List<Lead> leads ) {
List<Lead> leadListToBeUpdated = new List<Lead>();
for(Lead l : leads ) {
if(l.CreatedDate >= System.today().addDays(-365)
|| l.Owner.IsActive != True
|| l.Name.contains('Test')
|| l.Name.contains('test')
)
{
l.ToBeDeleted__c = true;
}
}
}
public void finish(Database.BatchableContext BC){
}
}
Can you guide me to move ahead and also please tell me about duplicate records?
As per my perception, this code will work for you. If you found it useful please appreciate my efforts and mark it as the best answer.
LinkedIn: https://www.linkedin.com/in/soyab-hussain-b380b1194/ (https://www.linkedin.com/in/soyab-hussain-b380b1194/ )
Regards,
Soyab