Skip to main content
Hello everyone.

I am not a Salesforce developer but have some basic knowledge on SOQL and Apex Triggers.  I need help from someone on an Apex trigger.  We'd like to update a checkbox field on Account object when there is a File that starts with "DA" that is added/attached to the specific account record.  is this doable?  any help will be greatly appreciated.  thank you.
6 件の回答
  1. 2021年1月13日 6:48
    Hi,

    Use below code:-

    trigger ContentDocumentLinkTrigger on ContentDocumentLink ( after insert, after update, after delete ) {

        

        List<ContentDocumentLink> cdls = ( Trigger.new == null ? Trigger.old : Trigger.new );

        

        Set<ID> parentIds = new Set<ID>();

        

        for (ContentDocumentLink cdl : cdls) {

            parentIds.add( cdl.LinkedEntityId );

        }

        

        for (List<Account> account : [SELECT Id, (SELECT Id FROM ContentDocumentLinks LIMIT 1) 

                                      FROM Account WHERE Id IN :parentIds]) {

            

            for (Account acc : account) {

                acc.Cb__c = ( acc.ContentDocumentLinks.size() > 0 );

            }

            UPDATE account;   

        }   

    }

    Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

    Thanks.
0/9000