Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save SalesforceBobLightning/6ec46247cec0208df439e1d743d72d0c to your computer and use it in GitHub Desktop.

Select an option

Save SalesforceBobLightning/6ec46247cec0208df439e1d743d72d0c to your computer and use it in GitHub Desktop.
Get Custom Object Related Files using Salesforce Apex
public Set<Id> getFiles(Id recordId) {
List<ContentDocumentLink> files = [SELECT ContentDocumentId
FROM ContentDocumentLink
WHERE LinkedEntityId IN ( SELECT Id FROM CUSTOM_OBJECT_NAME__c )
AND LinkedEntity.Type='CUSTOM_OBJECT_NAME__c'
AND LinkedEntityId = :recordId];
if (files.size() > 0) {
return (new Map<Id, ContentDocumentLink>(files)).keySet();
}
return new Set<Id>();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment