You need to sign in to do that
Don't have an account?
sumit d
Batch to update a checkbox field on duplicate lead records
Hi All,
I am creating a batch for the requirement in which if lead has duplicates based on name than a checkbox field named ToBeDeleted__c should set to true on the duplicate of a lead records.
Can anyone guide me with this requirement?
Thanks in advance
I am creating a batch for the requirement in which if lead has duplicates based on name than a checkbox field named ToBeDeleted__c should set to true on the duplicate of a lead records.
Can anyone guide me with this requirement?
Thanks in advance
* Please refer through below code it is as per your requirement:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
All Answers
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
* This Batch Class works as per your requirement, Please refer through it:
Batch Class--->
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Can you explain the Set<String> orderObj = new Set<String>();
How you use this set?
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 any of above condition met.
How to do it ?Can you guide me with it?
i created a batch given below but its not working ,can you help me with what i am missing?
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'+
'ORDER BY CreatedDate Asc';
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>();
Map<String,Lead> mapDuplicateLeadName = New Map<String,Lead>();
for(Lead l : leads ) {
if(mapDuplicateLeadName.containskey(l.Name) )
{
l.ToBeDeleted__c = True;
leadListToBeUpdated.add(l);
}
else
{
mapDuplicateLeadName.put(l.Name, l);
}
if(l.CreatedDate <= System.today().addDays(-365)
|| l.Owner.IsActive != True
|| l.Name.contains('%Test%')
|| l.Name.contains('%test%')
)
{
l.ToBeDeleted__c = true;
leadListToBeUpdated.add(l);
System.debug('Checkbox'+l.ToBeDeleted__c);
}
}
if(leadListToBeUpdated.size()>0) {
update leadListToBeUpdated;
System.debug('dupLeads**'+leadListToBeUpdated);
}
}
public void finish(Database.BatchableContext BC){
}
}
* Please refer through below code it is as per your requirement:
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com