Skip to main content
I am new to salesforce development i got this scenario 

 

 

  1. Consider there are 1 Lac Account records in the system. Each account record has 2 child Contact records. You have a requirement to update child Contact record address fields (Mailing City, Mailing Country) same as parent Account address fields(Billing City, Billing Country) and if there is no address, populate 'Not available' string in address fields.

 

and tried my pogram as it is but i am confusion in which one i need to populate in for loop, please help me in this and thanks in advance

 

global class batch1 implements DataBase.Batchable<Sobject>{

 

      global dataBase.queryLocator start(Database.batchableContext bc){

 

        string query= 'select id, billingCity,BillingCountry, Account.mailingCity, account.mailingCountry from contact';

 

             return DataBase.getqueryLocator(query);

 

global void execute(database.batchblecontext bc list<contact> scope){

 

          

 

   for(contact c:scope){

 

      if(account.billingCity != null && account.billingCountry != null){

 

          c.mailingCity = ________;

 

          c.mailingCountry= _______;

 

          }else{

 

            c.mailingCity= 'not available';

 

            c.mailingcountry= 'not available;

 

            }

 

       update scope;

 

      }

 

global void finsh(database.batachablecontext bc){

 

}      
답변 1개
  1. 2020년 8월 24일 오전 10:42

    Hi Prashanth, 

    Here's what you need to do 

     

     

    global class batch1 implements DataBase.Batchable<Sobject>{

    global dataBase.queryLocator start(Database.batchableContext bc){

    string query= 'select id, Account.BillingCity, Account.BillingCountry, MailingCity, MailingCountry from Contact';

    return DataBase.getqueryLocator(query);

    }

    global void execute(database.batchblecontext bc list<Contact> scope){

    for(Contact c: scope){

    if(c.Account.BillingCity != null && c.Account.BillingCountry != null ){

    c.MailingCity = c.Account.BillingCity;

    c.MailingCountry = c.Account.BillingCountry;

    }

    else{

    c.MailingCity= 'not available';

    c.MailingCountry= 'not available;

    }

    }

    update scope;

    }

    global void finsh(database.batachablecontext bc){

    }

    }

     

    Hope this helps :)

     

    Best,

    Vishal

0/9000