Skip to main content
Mohankumar B が「#Data Management」で質問
Hi all,

 

I have 2 objects Lead and Notes.Lead is Parent and Notes is Child.In that I have created 2 custom fileds in Lead object Name as Addvalue and Latest value.when i am create lead record with add value field this field value is automatically populated to create new Notes record in Notes object that value will be populated to the lead Latest value field this requirement i have done.

 

But i want know when i am delete the recent Notes record in notes object it will be automatically populated to old Notes value in Lead latest value field it will be achive through trigger can anyone help me...

 

Thanks in advance!!!
10 件の回答
  1. 2019年10月17日 5:58
    Hi Mohan, 

     

    You can try with below trigger:

     

    Trigger UpdLead on Notes(After Delete) {

     

         Set<ID> LeadIDList = new Set<ID>();

     

         for(Note DltNote:Trigger.Old) {

     

             // Validate if Notes is attached to a Lead record

     

             if(DltNote.WhatId.contains('00Q'))

     

                    LeadIDList.add(DltNote.WhatID);

     

             }

     

         }

     

         Set<Lead> UpdLead = new Set<Lead>();

     

         List<Note> NoteList = [select id, whatID, AddValue from Note where whatID IN: LeadIDList ];

     

         for(Note OldNote : NoteList) {

     

               Lead NewLD = new Lead(id = OldNote.whatID, LatestValue = OldNote.AddValue);

     

               UpdLead.add(NewLD);

     

         }

     

     

         Update UpdLead;

     

    }

     

    Hope this may help. You may need to refine it.
0/9000