Im trying to querry the ContentDocumentLink object and althogh I have a ContentDocumentId with a valid ID it wont populate the querry.

for(ContentDocument cd: newList){
    derp = cd.id;
    system.debug('los ids'+derp);
    system.debug('map'+newMap.get( derp ).ID);
    Set<Id> newSet = newMap.keySet();
    list<ContentDocumentLink> cdls = [SELECT Id, ContentDocument.Title, ContentDocumentId, LinkedEntityId, LinkedEntity.type  from ContentDocumentLink where  ContentDocumentId in:newSet];

enter image description here

  • When I execute the anonymous window with the hardcoded Id it does populate the querry. – Estanislao Velazquez Jun 18 at 15:52
  • Please edit your post with any clarifications rather than posting them in the comments. – Adrian Larson Jun 18 at 15:56
  • 1
    The code is looking broken; only the very last ContentDocument's ID will be kept and used in the newMap.get because you iterate all documents and assign all their IDs to one string/Id variable derp one after another. If you fix that in a trivial way, you'll then have a query in a loop. You need to restructure how you do your querying. – Phil W Jun 18 at 16:00
  • (Also the execution log doesn't match the sample code making it basically irrelevant) – Phil W Jun 18 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.