Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class UpdateContactAcoount implements Database.Batchable<sObject> {
- global Database.QueryLocator start(Database.BatchableContext bc) {
- return Database.getQueryLocator(
- 'SELECT ID,name,Accountnumber, (SELECT ID, lastname, accountid FROM Contacts) FROM Account Where Accountnumber = '123''
- );
- }
- global void execute(Database.BatchableContext bc, List<Account> scope){
- account a = [select id,name,(select id,firstname,lastname from contacts) from account where name=:'Test'];
- List<Contact> contacts = new List<Contact>();
- for (Account account : scope) {
- for(contact c : account.contacts){
- system.debug('Contact:'+c);
- c.accountid = a.id;
- contact eCopy = c.clone(false, false, false, false);
- contacts.add(eCopy);
- }
- }
- insert contacts;
- }
- global void finish(Database.BatchableContext bc){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement