You need to sign in to do that
Don't have an account?
MilesS
Bulkify Content Documents
Hey,
I am trying to bulkify some code on Salesforce for the new "Content" objects. I want to either count or add a link to the opportunity when a new document/file is inserted or deleted if the phrase “RFAssessment” is contained in the Title. I have successfully built a trigger & class to take care of this, but the SOQL & DML statements are currently within my for loop. My knowledge of code is a 101 class to C++, python & GTSOOI (Google the sh!t out of it). If I should be looking at a different trigger object or if someone could show me how every content object is related (because ContentDocumentLink & ContentDocument seem to be left out of most descriptions) I will be extremely grateful!
The following bit of code produces an error...
!!!!!ERROR MESSAGE!!!!!
(SELECT Id,Title FROM ContentDocument)
^ERROR at Row:2:Column:61
Didn't understand relationship 'ContentDocument' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names."
The following code works, but at a cost of 5 SOQL quieres per file. Not good for bulk uploading.
I am trying to bulkify some code on Salesforce for the new "Content" objects. I want to either count or add a link to the opportunity when a new document/file is inserted or deleted if the phrase “RFAssessment” is contained in the Title. I have successfully built a trigger & class to take care of this, but the SOQL & DML statements are currently within my for loop. My knowledge of code is a 101 class to C++, python & GTSOOI (Google the sh!t out of it). If I should be looking at a different trigger object or if someone could show me how every content object is related (because ContentDocumentLink & ContentDocument seem to be left out of most descriptions) I will be extremely grateful!
The following bit of code produces an error...
trigger ContentDocLink_TEST on ContentDocumentLink (before insert) { List<ContentDocumentLink> CDL = [SELECT Id,LinkedEntityId,ContentDocumentId, (SELECT Id,Title FROM ContentDocument) FROM ContentDocumentLink WHERE Id IN :Trigger.newMap.keySet()]; }
!!!!!ERROR MESSAGE!!!!!
(SELECT Id,Title FROM ContentDocument)
^ERROR at Row:2:Column:61
Didn't understand relationship 'ContentDocument' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names."
The following code works, but at a cost of 5 SOQL quieres per file. Not good for bulk uploading.
I have through your question. The error in code is because you are using the wrong inner query. The inner query will only work when you will access the child with a parent.
But in your code, you are trying to access the parent with child.
To correct your code please use the query given below:--
List<ContentDocument> CDL = [SELECT Id,Title,(SELECT Id,LinkedEntityId,ContentDocumentId FROM ContentDocumentLinks)
FROM ContentDocument];
System.debug('ContentDocument--->'+CDL);
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
LinkedEntityId,ContentDocumentId FROM ContentDocumentLink)
^
ERROR at Row:2:Column:88
Didn't understand relationship 'ContentDocumentLink' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.