0

Im facing below error:

Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator. PFB Code:

public class AttachmentController {    
    @AuraEnabled
    public static void updatePicturePath(String recordId){
        system.debug('recId  '+ recordId);
        //In Lightning Experience, Attachments are stored in ContentDocuments
        try{ 
            ContentDocumentLink docLink =[SELECT ContentDocumentId
                                          FROM ContentDocumentLink
                                          WHERE LinkedEntityId = :recordId];

            //ContentVersion Id uniquely identifies the attachment
            ContentVersion ver = [SELECT Id FROM ContentVersion Where 
                                  ContentDocumentId = :docLink.ContentDocumentId];
            //Update the Picture_Path field with the url of the image
            Speaker__c speaker = [SELECT Id FROM Speaker__c WHERE Id = :recordId];
            speaker.Picture_Path__c = '/sfc/servlet.shepherd/version/download/'+ ver.Id; 
            upsert speaker;
        }catch(Exception e){
            system.debug('In Catch block');
        }
    }
}
  • do you have multiple ContentDocumentLink related to the same recordId ? – Tarique Shamim Feb 27 at 12:16
  • I dont know much about content documentLink have not worked on it before.... im following the trailhead steps. – Priya Feb 27 at 12:30
  • @Priya Can you please confirm if you are getting the value in recordId ? – Vijay Ganji Feb 27 at 12:46
  • No im not getting value ,its null – Priya Feb 27 at 12:48
  • You need to make sure that you pass valid Id as a parameter to your method. Can you post the code from where you are calling this method ? – Vijay Ganji Feb 27 at 13:31
1

The reason you are getting this error is because you are getting null value in recordId parameter (As mentioned by you in your comment).

The solution for your problem is to make sure that you pass a valid Id parameter to your method from wherever it is being called.

Salesforce SOQL ignores the where clause when you filter on required Lookup fields by null. And as LinkedEntityId is a required lookup field on ContentDocumentLink, and you are trying to filter it by null, it ignores the entire where clause which leads to no filter at all in SOQL and that leads to below error.

Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator.

SOQL ignores : WHERE RequiredLookup__c = null is the idea on community, you can promote it, although in your case LinkedEntityId should always have a value, just that you are not passing the parameter properly.

  • You can't run a query without filters against ContentDocumentLink.
  • You can't filter on ContentDocument fields if you're filtering by ContentDocumentId. You can only filter on ContentDocument fields if you're filtering by LinkedEntityId.
  • You can't filter on the related object fields. For example, you can't filter on the properties of the account to which a file is linked. You can filter on the properties of the file, such as the title field.

You can find further help on ContentDocumentLink at this link

  • Thanks a lot rechecking for valid Id parameter to your method from wherever it is being called has solved an issue. Problem was i used setParam instead of setParams This caused not setting recordId properly as parameter to server side function. Thanks a lot. – Priya Feb 28 at 9:27
  • That's great !! – Vijay Ganji Feb 28 at 9:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.