Skip to main content
Hello,

Trying to share a file with the grandchild record.

How can I share the contentdocumentlionk?

So file is uploaded to account.

Acount has multiple Contacts.

Contacts have multiple Invoices.

Need to share the file with Invoice records.

Thank you,

P
3 个回答
  1. 2022年11月17日 15:18
    Hello Swetha,

    This is what I have so far:

    if(Trigger.isInsert){

    Set<Id> getAccts = new Set<Id>();

    Map<String,String> m_accts = new Map<String,String>();

    for(ContentDocumentLink contDocLink : (List<ContentDocumentLink>)Trigger.new){

    if(contDocLink.LinkedEntityId.getSObjectType().getDescribe().getName() == 'Account'){

    if(!getAccts .contains(contDocLink.LinkedEntityId)){

    getAccts .add(contDocLink.LinkedEntityId);

    }

    }

    }

    if(!getAccts .isEmpty()){

    Map<Id, Contact> m_accts= new Map<Id, Contact>([

    SELECT Id, ,

    (SELECT Id, Account, category__c FROM Invoices__r WHERE category__c = 'Date Received')

    FROM Contact WHERE Account IN: getAccts

    ]);

    system.debug('m_accts' +m_accts);

    List<ContentDocumentLink> linkList = [ SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: getAccts ];

    system.debug('linkList ' +linkList);

    if( !linkList.isEmpty() ){

    for( ContentDocumentLink link : linkList ){

    List<ContentDocumentLink> links = this.linkMap.containsKey( link.ContentDocumentId )

    ? this.linkMap.get( link.ContentDocumentId ) : new List<ContentDocumentLink>();

    links.add( link );

    this.linkMap.put( link.ContentDocumentId, links );

    }

    }

    system.debug('linkList ' +linkList);

    List<ContentDocumentLink> linkList = [ SELECT Id, ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: getAccts];

    Just not sure how to get the LinkedEntityId  assigned to the invoice record.  Any suggestions?​​
0/9000