Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. global class UpdateContactAcoount implements Database.Batchable<sObject> {
  2.  
  3. global Database.QueryLocator start(Database.BatchableContext bc) {
  4. return Database.getQueryLocator(
  5. 'SELECT ID,name,Accountnumber, (SELECT ID, lastname, accountid FROM Contacts) FROM Account Where Accountnumber = '123''
  6. );
  7. }
  8. global void execute(Database.BatchableContext bc, List<Account> scope){
  9. account a = [select id,name,(select id,firstname,lastname from contacts) from account where name=:'Test'];
  10. List<Contact> contacts = new List<Contact>();
  11. for (Account account : scope) {
  12. for(contact c : account.contacts){
  13. system.debug('Contact:'+c);
  14. c.accountid = a.id;
  15. contact eCopy = c.clone(false, false, false, false);
  16. contacts.add(eCopy);
  17. }
  18. }
  19. insert contacts;
  20. }
  21. global void finish(Database.BatchableContext bc){
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement