-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathUpdateContactAddress
More file actions
33 lines (29 loc) · 1.1 KB
/
Copy pathUpdateContactAddress
File metadata and controls
33 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
global class UpdateContactAddress implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext bc)
{
return Database.getQueryLocator(
'SELECT ID,BillingStreet,BillingCity,BillingState,'+
'BillingPostalCode,(Select id,MailingStreet,MailingCIty,'+
'MillingState,MailingPostalCode from Contacts) From Account'+
'Where BillingState=\'CA\''
);
}
global void execute(Database.BatchableContext bc,List<Account> scope)
{
List<Contact> contacts=new List<Contact>();
for(Account account:scope){
for(Contact contact: account.contacts)
{
contact.MailingStreet=account.BillingStreet;
contact.MailingCity=account.BillingCity;
contact.MailingState=account.BillingState;
contact.MailingPostalCode=account.BillingPostalCode;
contacts.add(contact);
}
}
update contacts;
}
global void finish(Database.BatchableContext bc)
{
}
}