Guest User

Untitled

a guest
Jan 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. trigger invoiceAccountInsert on invoice__c (before insert) {
  2. Set<String> accountNames = new Set<String>();
  3. Map<String, Id> accountNameToId = new Map<String, Id>();
  4. for(invoice__c record: Trigger.new) {
  5. accountNames.add(record.Account__c);
  6. System.debug('Account__c >>>>>>' + record.Account__c);
  7. }
  8.  
  9. list<Account> acclist = new list<Account>();
  10. acclist = [SELECT Id, Name FROM Account WHERE Name IN :accountNames];
  11.  
  12. for(Account acc:acclist)
  13. {
  14. accountNameToId.put(acc.Name, acc.Id);
  15. System.debug('acc.Name >>>>>>' + acc.Name);
  16. System.debug('acc.Id >>>>>>' + acc.Id);
  17. System.debug('accountNameToId >>>>>>' + accountNameToId);
  18. insert acc;
  19. }
  20. }
Add Comment
Please, Sign In to add comment