You need to sign in to do that
Don't have an account?
Michael M
Help with SOQL query in Trigger
My use case is that I have a picklist on a custom object, and one of the values on the picklist is "files uploaded". So I need to build an 'after insert' trigger that when a file is uploaded to this object (not any other objects), the value of that picklist automatically gets updated to "files uploaded". So 2 questions:
1. What Object should the trigger be built on?
2. How would the SOQL query be written to say that it's only for files related to this one specific custom object's records?
Any help is greatly appreciated.
1. What Object should the trigger be built on?
2. How would the SOQL query be written to say that it's only for files related to this one specific custom object's records?
Any help is greatly appreciated.
I am assuming you are trying to upload files on the custom object using "Upload file' functionality on files related list. If thats the case the trigger would be on "ContentDocumentlink" Object. When you upload a file to custom object record the value in LinkedEntityId is the record to which the file is uploaded to.
Below SOQL query gives you all the files linked to the Custom Object.
Please refer to sample codes below on Account Object. Modify the code as per your requirement on custom object. In below example when a new file is uploaded to account object record the "CustomField__c " field is updated with File Uploaded text. When you try to update your picklist make sure you give correct API names to the field. To identify only files uploaded to Account object we are using String.valueOf(nt.LinkedEntityId ).startsWith('001'). As the Account record Id starts with 001, same way give your custom record id start digits.
Trigger code:
Apex Class:
Hope this helps! Please mark as best if it does
Thanks
All Answers
I am assuming you are trying to upload files on the custom object using "Upload file' functionality on files related list. If thats the case the trigger would be on "ContentDocumentlink" Object. When you upload a file to custom object record the value in LinkedEntityId is the record to which the file is uploaded to.
Below SOQL query gives you all the files linked to the Custom Object.
Please refer to sample codes below on Account Object. Modify the code as per your requirement on custom object. In below example when a new file is uploaded to account object record the "CustomField__c " field is updated with File Uploaded text. When you try to update your picklist make sure you give correct API names to the field. To identify only files uploaded to Account object we are using String.valueOf(nt.LinkedEntityId ).startsWith('001'). As the Account record Id starts with 001, same way give your custom record id start digits.
Trigger code:
Apex Class:
Hope this helps! Please mark as best if it does
Thanks