You need to sign in to do that
Don't have an account?
Drebin
Trigger to delete a chatter file when the status of a lead change
Hi everyone,
I realized an app which take photos and create leads with it. I save the image in a ContentVersion. To show it in my new lead, i created two custom fields, one which store the ContentVersion ID of the image and another one with the formula to display the image in the lead detail with the following formula : IMAGE('/sfc/servlet.shepherd/version/download/' & PhotoLead_Image__c, "Chatter Image", 250, 250).
Now, i need that when the status of a lead changes to "Converted", the image corresponding to this lead is deleted.
I tried to create a trigger for this but I'm completely blocked.
Can you help please me with this trigger ?
Thanks.
I realized an app which take photos and create leads with it. I save the image in a ContentVersion. To show it in my new lead, i created two custom fields, one which store the ContentVersion ID of the image and another one with the formula to display the image in the lead detail with the following formula : IMAGE('/sfc/servlet.shepherd/version/download/' & PhotoLead_Image__c, "Chatter Image", 250, 250).
Now, i need that when the status of a lead changes to "Converted", the image corresponding to this lead is deleted.
I tried to create a trigger for this but I'm completely blocked.
Can you help please me with this trigger ?
Thanks.
Thanks for your reply.
In the meantime, I managed to find an answer to my question, which I share the solution : As you stated, I had to get the ContentDocumentID and not the ContentVersionId.
All Answers
Hi Frederic,
How are you storing the ContentVersion ID to the field? You need to save the ContentDocument Id, as Delete DML operation is not allowed on ContentDocument as per the SOAP API developer guide: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm.
So, you need to save the ContentDocument Id(069) instead of ContentVersionId (068).
Reply if you need help with trigger logic.
Thanks.
Kindly mark it as an answer if it works so that we can close the thread.
Thanks for your reply.
In the meantime, I managed to find an answer to my question, which I share the solution : As you stated, I had to get the ContentDocumentID and not the ContentVersionId.