• Kingslee Velu
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Give an example of why you would use a trigger over a workflow or process builder to accomplish an update to a field?

Is there any pros/cons apart from below, Please share your thoughts.
  • If we need to perform an update on fields by validating the before/after validations of any other fields save to database then Triggers can be used instead of Workflow/Process Builder
  • Workflow/Process Builder cannot handle delete and undelete DML. Whereas Apex triggers can handle all DML operations.
  • Errors reported in Workflow/Process Builder is more generic which makes it difficult to find the origin of the error. With Apex triggers, exception handling can be made more specific.
  • It is all or none in case of Workflow/Process Builder failure. But with Apex triggers partial success is possible
Email manager class 

public class EmailManager {

    public void sendMail(string Address,string subject, string body)
    {
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
    string [] toaddress = new string[]{address};
    email.setToAddresses(toaddress);
    email.setSubject(subject);
    email.setPlainTextBody(body);
    }
}


developer console 
EmailManager e = new EmailManager();
e.sendMail('xxx@domain.com','test email', 'test apex');
  • September 05, 2015
  • Like
  • 0