Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. trigger NoteCopy on Note (after insert, after update) {
  2. // Notes attached to leads
  3. Note[] leadNotes = new Note[0];
  4. // Just notes for leads...
  5. for(Note record: Trigger.new) {
  6. if(record.ParentId != null && record.ParentId.getSObjectType() == Lead.SObjectType) {
  7. leadNotes.add(record);
  8. }
  9. }
  10. // No notes to process? We're done.
  11. if(leadNotes.isEmpty()) {
  12. return;
  13. }
  14. // Update Lead records with new notes.
  15. Map<Id, Lead> records = new Map<Id, Lead>();
  16. for(Note record: leadNotes) {
  17. records.put(record.ParentId, new Lead(Id=record.ParentId, Note__c=record.Body));
  18. }
  19. update records.values();
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement