You need to sign in to do that
Don't have an account?
kj Smith
Trigger to update a long text field with available Notes bodies for that object record
I have a object called Incident__c and a custom field called Notes__c (Long Text Area).
Whenever a New Note is added to a Incident__c record, I want to populate Notes__c field with Note body.
If there are several Notes added to the Incident__c record, Notes__c field should be appended with each Note bodies.
Once a Note body is updates Note__c field should also be updated accordingly.
I'm currently struggling to make progress on this as i'm new to this scenario! How can I do this ?
Whenever a New Note is added to a Incident__c record, I want to populate Notes__c field with Note body.
If there are several Notes added to the Incident__c record, Notes__c field should be appended with each Note bodies.
Once a Note body is updates Note__c field should also be updated accordingly.
I'm currently struggling to make progress on this as i'm new to this scenario! How can I do this ?
Hi Smith,
Try with below trigger your functionality will be achieved.
If this solves your Problem, Mark it as the Best Answer.
Thanks,
SFDC Beginner.
I want to seperate out the trigger and use a helper class, so I modified the code as below,
-----------------Helper Class--------------------------
public with sharing class NoteTriggerHelper {
public static void insertNotesBodyToTextField(){
Set<Id> incid = new Set<Id>();
List<Note> notes = [SELECT Body FROM Note WHERE ParentId IN(SELECT Id FROM grc__Incident__c)];
for(Note n : notes){
incid.add(n.ParentId);
}
Map<Id, grc__Incident__c> incidents = new Map<Id, grc__Incident__c>([Select Id,Notes__c from grc__Incident__c where Id IN :incid]);
for(Note n : notes){
if(incidents.size() > 0 && incidents.containsKey(n.ParentId)){
incidents.get(n.ParentId).Notes__c = n.Body;
}
}
update incidents.values();
}
}
-----------------------Trigger-----------------------
rigger NoteTrigger on Note (after insert, after update) {
if(Trigger.isAfter){
if(Trigger.isInsert){
NoteTriggerHelper.insertNotesBodyToTextField(Trigger.newMap);
}
if(Trigger.isUpdate){
NoteTriggerHelper.insertNotesBodyToTextField(Trigger.newMap);
}
}
}
but i'm getting an error when saving the trigger which says "NoteTrigger.trigger: Method does not exist or incorrect signature: NoteTriggerHelper.insertNotesBodyToTextField(Map<Id,Note>) (Line: 4, Column: 4)"
Now the only issue is, when a new Note is added to the record my field updates the value without appending Note bodies. i'm trying to work around, how can I fix it ?
Try to Modify the line which I Have Underlined your functionality willl be achieved.
Thanks,
SFDC Beginner