You need to sign in to do that
Don't have an account?
Austin Lewis 12
Before Update trigger not firing
I am entirely new to APEX and a novice to coding in general. I have a apex trigger on the ContentDocumentLink object that calls a flow, but I am unable to get the trigger to fire on udpates as well as inserts. Here is my trigger below
trigger SaveNote on ContentDocumentLink (before insert, before update, after insert) {
IF(Trigger.isBefore){
IF(Trigger.isInsert){
ContentDocumentLink [] newnote=Trigger.new;
mySaveNote.SaveNote(newnote);
}
IF(Trigger.isUpdate){
ContentDocumentLink [] newnote=Trigger.new;
mySaveNote.SaveNote(newnote);
}
}
}
Here is my class
public class mySaveNote {
public static void SaveNote (ContentDocumentLink [] newnote){
for(ContentDocumentLink n: newnote){
Map<String, Object> params = new Map<String, Object>();
params.put('ContentDocumentLinkID',n.Id);
Flow.Interview.CCOF_Note_Create_and_Udpate CCOF_Note_Create_and_UdpateFlow = new Flow.Interview.CCOF_Note_Create_and_Udpate(params);
CCOF_Note_Create_and_UdpateFlow.start();
}
}
}
trigger SaveNote on ContentDocumentLink (before insert, before update, after insert) {
IF(Trigger.isBefore){
IF(Trigger.isInsert){
ContentDocumentLink [] newnote=Trigger.new;
mySaveNote.SaveNote(newnote);
}
IF(Trigger.isUpdate){
ContentDocumentLink [] newnote=Trigger.new;
mySaveNote.SaveNote(newnote);
}
}
}
Here is my class
public class mySaveNote {
public static void SaveNote (ContentDocumentLink [] newnote){
for(ContentDocumentLink n: newnote){
Map<String, Object> params = new Map<String, Object>();
params.put('ContentDocumentLinkID',n.Id);
Flow.Interview.CCOF_Note_Create_and_Udpate CCOF_Note_Create_and_UdpateFlow = new Flow.Interview.CCOF_Note_Create_and_Udpate(params);
CCOF_Note_Create_and_UdpateFlow.start();
}
}
}
Can you please make use of below code and give it a try
Could you please verify that flow is working as expected on updates manually..!!
I am confused by your latest comment. The trigger calls a flow that runs whenever a ContentDocumentLink is created (and is supposed to work when the record is also updated), which then automatically runs the flow which updates a specific account (which I am using to check to see if the flow has run). Currently my flow runs when i manually create a ContentNote which creates a ContentDocumentLink (by SF default), but it seems that my flow is not triggered when i update a ContentNote. All inserts or updates of notes are manual
Sadly updating the trigger to ELSE IF (Trigger.isUpdate) instead of IF(Trigger.isUpdate) did not trigger my flow upon a record update.
Is there a chance that the test class could be causing these errors? Odd that it fires on insert
From your comment noticed these line " Currently my flow runs when i manually create a ContentNote which creates a ContentDocumentLink (by SF default), but it seems that my flow is not triggered when i update a ContentNote. All inserts or updates of notes are manual"
you should perform an update on ContentDocumentLink that causes the trigger to fire and in turn initiates the flow to update account
Thank you! For some reason this helped something click in my head. I was wondering, do you know / is it possible to reference another object in a trigger other than the object that the trigger is on?
You can get the old values usning Trigger.old context variable