function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Melinda KayMelinda Kay 

Reportable Notes relation to account after lead conversion

I want users to make reportable notes on leads- but after lead conversion, the notes need to be reassociated to the account... I am having the same challenge with attachments- which also should be reassociated to the account upon lead conversion.  Here is a trigger for the lead- can someone help me identify the problems with it working?  Thank you!

trigger AssociateLeadReportableNoteToAccount on Lead (after update) {
    List<Lead> leads = trigger.new;
    for (Lead lead : leads) {
        if (lead.IsConverted) {
            List<Reportable_Note__c> reportablenote = [Select Reportable_Note__c.Related_to_Account__c From Reportable_Note__c Where Reportable_Note__c.Lead__c =: lead.Id];
            for (Reportable_Note__c reportablenote : reportablenotes) {
                reportablenote.Related_to_Account__c = lead.convertedAccountId;
                update reportablenote;
            }
        }
    }
}
Best Answer chosen by Melinda Kay
Swayam@SalesforceGuySwayam@SalesforceGuy
Hey,

You update the code : Refer Below -- 
 
trigger AssociateLeadReportableNoteToAccount on Lead (after update) {

    List<Lead> leadList = new List<Lead>();
     
	for(Lead lead : trigger.new)
	{
		if(lead.IsConverted)
		{
			leadList.add(lead);
		}
	}
	List<Reportable_Note__c> updateReportableList = new List<Reportable_Note__c>();
    for (Reportable_Note__c reportablenote : [Select  Id, Reportable_Note__c.Related_to_Account__c From Reportable_Note__c Where Reportable_Note__c.Lead__c IN : leadList.Id] )
     {
	 Reportable_Note__c reportablenoteObj = new Reportable_Note__c();
	 reportablenote.Related_to_Account__c = lead.convertedAccountId;
     updateReportableList.add(reportablenote);
	 }
   
	Update updateReportableList;
}

Hope this helps, let me know in case of any issue


-- 
Thanks,
Swayam
@salesforceguy

All Answers

Swayam@SalesforceGuySwayam@SalesforceGuy
Hey,

You update the code : Refer Below -- 
 
trigger AssociateLeadReportableNoteToAccount on Lead (after update) {

    List<Lead> leadList = new List<Lead>();
     
	for(Lead lead : trigger.new)
	{
		if(lead.IsConverted)
		{
			leadList.add(lead);
		}
	}
	List<Reportable_Note__c> updateReportableList = new List<Reportable_Note__c>();
    for (Reportable_Note__c reportablenote : [Select  Id, Reportable_Note__c.Related_to_Account__c From Reportable_Note__c Where Reportable_Note__c.Lead__c IN : leadList.Id] )
     {
	 Reportable_Note__c reportablenoteObj = new Reportable_Note__c();
	 reportablenote.Related_to_Account__c = lead.convertedAccountId;
     updateReportableList.add(reportablenote);
	 }
   
	Update updateReportableList;
}

Hope this helps, let me know in case of any issue


-- 
Thanks,
Swayam
@salesforceguy
This was selected as the best answer
Melinda KayMelinda Kay
Thanks Swayam!