Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trigger NoteCopy on Note (after insert, after update) {
- // Notes attached to leads
- Note[] leadNotes = new Note[0];
- // Just notes for leads...
- for(Note record: Trigger.new) {
- if(record.ParentId != null && record.ParentId.getSObjectType() == Lead.SObjectType) {
- leadNotes.add(record);
- }
- }
- // No notes to process? We're done.
- if(leadNotes.isEmpty()) {
- return;
- }
- // Update Lead records with new notes.
- Map<Id, Lead> records = new Map<Id, Lead>();
- for(Note record: leadNotes) {
- records.put(record.ParentId, new Lead(Id=record.ParentId, Note__c=record.Body));
- }
- update records.values();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement