function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdclearnsfdclearn 

using Product name in a filter in an account workflow rule

Hi,

 

   I have a workflow rule in the Account object .

     if Accountstatus='new'

        then this rule triggers an email template to the customer.

 

    Now I would like to include the product name in the workflow. 

    which includes if(product name='xxx') then send the more specific template.(with the product name included on it).

 

    I believe this cannot be accomplished with a workflow rule as Account can have multiple opportunities and each opportunity is tied to several products.

    But is there a way to address this?

 

Thanks in advance for help!

  

 

TrinayTrinay

Hi sfdclearn,

 

    You can done this by writing Trigger(after update) for Account object.

 

refer following sample trigger: 

 

trigger sendEmail on Account(after update) 

{
   for(Account a : Trigger.new)
  {  
      if (a.status == 'new')//you can add some more condition here
      {
           List<Opportunity> aps = [SELECT Id,Email FROM Opportunity WHERE AccountId = :a.Id];
           for (Opportunity ap : aps)
           {
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

                mail.setTargetObjectId(ap.Id);
                mail.setTemplateId('your template id here');
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

           }

      }
  }

}

 

reference for sending  email using trigger:

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm?SearchType=Stem&Highlight=email

sfdclearnsfdclearn

but how can we include the product name in the template when we write this trigger