You need to sign in to do that
Don't have an account?
Phani PYDIMARRY 11
Compare Account Name inside a Batch class to process records
I would want to write a batch class to consider some Account records which have a flag unchecked and then compare them with a duplicate Account records created with the same name which are checked to update other values. I am new to APEX please let me know how can I frame the code.
Global class myBatch implements Database.Batchable<sobject>{ Global myBatch(){ } global Database.Querylocator start(Database.Bachablecontext context){ return Database.getQuerylocator([Select ID, Name from Account where BATCH_PROCESS__c = FALSE]); } global void execute(Database.BatchableContext BC, List<Account> scope){ //I would want to get those Account names which have a BATCH_PROCESS__c AS TRUE to compare list<Account> acc = ([Select Name from Account where BATCH_PROCESS__c = TRUE]); set<string> st = new set<string>(); for(Account act: acc){ st.add(act.name); } try{ for(Account active:scope){ //I am struck here on how to compare the values from the string } }catch(Exception e){} } }
Hello, Phani. You can have the start() method return the list of unprocessed Accounts. The execute() method can create a set of Account names and then query processed Accounts with the same name.
Use bellow code for compare the values from the string
Global class myBatch implements Database.Batchable<sobject>{
Global myBatch(){
}
global Database.Querylocator start(Database.Bachablecontext context){
return Database.getQuerylocator([Select ID, Name from Account where BATCH_PROCESS__c = FALSE]);
}
global void execute(Database.BatchableContext BC, List<Account> scope){
//I would want to get those Account names which have a BATCH_PROCESS__c AS TRUE to compare
list<Account> acc = ([Select Name from Account where BATCH_PROCESS__c = TRUE]);
set<string> st = new set<string>();
for(Account act: acc){
st.add(act.name);
}
try{
for(Account active:scope){
// Check current Account name in your Set Which has checked Account Name
if(st.contains(active.Name)){
// Do Something
}
}
}catch(Exception e){}
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Sachin Arora
www.sachinsf.com
Like me
https://naukrimint.com/
I am trying to fin the Accounts with a combination of name and tracking number. Then I would want to update the records