- 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){
}
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