Hi Evan, Please give a try with below code. It worked for me when I attached note to Account using "New Note" in both classic and lightnning and tested in my org.
Hope this helps! Please mark as best if it solves your problem.Thankstrigger updateAccountField on Note (after insert, after Update) {
set<id> Accountids=new set<id>();
list<Account> accUpdate =new list<Account>();
for(Note n:Trigger.New){
// Gathering all the Account Ids to which notes are attached
if(String.valueOf(n.parentId).startsWith('001') && n.Title.Contains('Client Health')){
Accountids.add(n.parentId);
}
}
if(Accountids.size()>0){
accUpdate =[Select id,Most_recent_Note__c from Account where id in :Accountids];
}
// Comparing with note id and Account id and updating the Last_Note__c field wit note body
for(Note nt : Trigger.new){
for(integer i=0;i<accUpdate.size();i++)
{
if(nt.parentId==accUpdate.get(i).id)
{
accUpdate.get(i).Most_recent_Note__c= nt.LastModifiedDate;
}
}
}
if(!accUpdate.isEmpty()){
try{
update accUpdate;
}catch(DmlException de ){
System.debug(de);
}
}
}
1 resposta