Skip to main content

How do I notify the opportunity owner when a file has been uploaded to an opportunity by a certain user that they own in salesforce?

 

I tried searching for the the object of file, but didn't find it. It seems to only appear as a related list on the opportunity page, so I am struggling with how to trigger the flow. 

2 answers
  1. Jul 18, 2024, 5:50 AM

    @Savita Ebube 

    Trigger will be  ContentDocumentLink  object  & event will be after Insert.

    here is following codes of helper class

     

    Set<Id> opportunityIds = new Set<Id>();    List<Messaging.SingleEmailMessage> emails = new List<Messaging.SingleEmailMessage>();    for (ContentDocumentLink cdl : Trigger.new) {        if (cdl.LinkedEntityId.getSObjectType() == Opportunity.SObjectType) {            opportunityIds.add(cdl.LinkedEntityId);        }    }    // Query Opportunities and their Owners    List<Opportunity> opportunities = [        SELECT Id, Owner.Email, Owner.Name         FROM Opportunity         WHERE Id IN :opportunityIds    ];    for (Opportunity opp : opportunities) {        if (opp.Owner.Email != null) {            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();            email.setToAddresses(new String[] { opp.Owner.Email });            email.setSubject('File Uploaded to Your Opportunity');            email.setPlainTextBody('A file has been uploaded to the Opportunity: ' + opp.Name);            emails.add(email);        }    }    // Send the email notifications    if (!emails.isEmpty()) {        Messaging.sendEmail(emails);    }
0/9000