+ Start a Discussion
sfdc augsfdc aug 

trigger & worflow & batchapex

I am New to salesforce , I have alway try to find a solution for When we go for the triggers apart from Workflow and Batch apex? plese give me atleast  2 Real time Scenarios 
Best Answer chosen by sfdc aug
Sunil MadanaSunil Madana

Hi,
Triggers against Workflow
Triggers work on multiple objects, so in situations where you want to work on multiple objects simultaneously, you have to use triggers. If its on a single object, you can accomplish it with workflow.

Batch Apex agains Triggers
Triggers execute immediately after any defined action (Before insert, before update, after insert, after update, before delete, after delete) whereas, Batch Apex is something like the last resort for Apex developers to circumvent limitations of the Salesforce Platform when working with "Large" data volumes. When using Batch Apex as the asynch backbone of a bigger system you soon find obvious drawbacks:

  • Jobs are put in a queue, but when that queue is full (Max. 5 concurrent batches), the job fails instead of being scheduled for later processing.
  • Jobs of different Batches might work on the same data and produce conflicts. There is no locking mechanism or guaranteed order.
  • Poor support to handle party failed batch runs. Its really hard to find out where and why a single job failed and to restore data consistency.
Scenario:
Triggers are used when you want update Account object whenever a new Contact is inserted.
Workflow is used when you want sent email notifications after an Opportunity stage is changed to "Closed Won"
Batch Apex is used to update all Account records "daily revenue" field value after close of business everyday which involves data processing from different custom (or) standard objects and finally updating Account object.

Hope the above explanation helps.

All Answers

Sunil MadanaSunil Madana

Hi,
Triggers against Workflow
Triggers work on multiple objects, so in situations where you want to work on multiple objects simultaneously, you have to use triggers. If its on a single object, you can accomplish it with workflow.

Batch Apex agains Triggers
Triggers execute immediately after any defined action (Before insert, before update, after insert, after update, before delete, after delete) whereas, Batch Apex is something like the last resort for Apex developers to circumvent limitations of the Salesforce Platform when working with "Large" data volumes. When using Batch Apex as the asynch backbone of a bigger system you soon find obvious drawbacks:

  • Jobs are put in a queue, but when that queue is full (Max. 5 concurrent batches), the job fails instead of being scheduled for later processing.
  • Jobs of different Batches might work on the same data and produce conflicts. There is no locking mechanism or guaranteed order.
  • Poor support to handle party failed batch runs. Its really hard to find out where and why a single job failed and to restore data consistency.
Scenario:
Triggers are used when you want update Account object whenever a new Contact is inserted.
Workflow is used when you want sent email notifications after an Opportunity stage is changed to "Closed Won"
Batch Apex is used to update all Account records "daily revenue" field value after close of business everyday which involves data processing from different custom (or) standard objects and finally updating Account object.

Hope the above explanation helps.
This was selected as the best answer
sfdc augsfdc aug
Thanks