If you have a business logic to send an email 180 days before the Contract expiration, we want to notify the User that the Contract is going to expire.
If we have only 180 days is the criteria then we can achieve this using Time based Workflow. But for this we need to touch the records as least once.
If we have additional criteria along with 180 days less than and also should work for all existing records as well then we will use some concept which should run the background where there is no need of user modifying the record.
In this situation we will go with Batch Apex, which will run everyday night and check all the Contracts which are expiring in next 180 days and send an email to the Contact person.
Please go through the below links for more information:
If you have a business logic to send an email 180 days before the Contract expiration, we want to notify the User that the Contract is going to expire.
If we have only 180 days is the criteria then we can achieve this using Time based Workflow. But for this we need to touch the records as least once.
If we have additional criteria along with 180 days less than and also should work for all existing records as well then we will use some concept which should run the background where there is no need of user modifying the record.
In this situation we will go with Batch Apex, which will run everyday night and check all the Contracts which are expiring in next 180 days and send an email to the Contact person.
Please go through the below links for more information:
Please check below post for Batch job:- 1) http://amitsalesforce.blogspot.in/2016/02/batch-apex-in-salesforce-test-class-for.html
Batch Apex A Batch class allows you to define a single job that can be broken up into manageable chunks that will be processed separately.
When to use Batch Apex One example is if you need to make a field update to every Account in your organization. If you have 10,001 Account records in your org, this is impossible without some way of breaking it up. So in the start() method, you define the query you're going to use in this batch context: 'select Id from Account'. Then the execute() method runs, but only receives a relatively short list of records (default 200). Within the execute(), everything runs in its own transactional context, which means almost all of the governor limits only apply to that block. Thus each time execute() is run, you are allowed 150 queries and 50,000 DML rows and so on. When that execute() is complete, a new one is instantiated with the next group of 200 Accounts, with a brand new set of governor limits. Finally the finish() method wraps up any loose ends as necessary, like sending a status email.
Sample Batch Apex 1) Start method is automatically called at the beginning of the apex job. This method will collect record or objects on which the operation should be performed. These record are divided into subtasks & passes those to execute method.
2) Execute Method performs operation which we want to perform on the records fetched from start method.
3) Finish method executes after all batches are processed. Use this method to send confirmation email notifications.
hii mahesh Can u eloborate thisplease ..? If you have a business logic to send an email 180 days before the Contract expiration, we want to notify the User that the Contract is going to expire.
If we have only 180 days is the criteria then we can achieve this using Time based Workflow. But for this we need to touch the records as least once.
If we have additional criteria along with 180 days less than and also should work for all existing records as well then we will use some concept which should run the background where there is no need of user modifying the record.
In this situation we will go with Batch Apex, which will run everyday night and check all the Contracts which are expiring in next 180 days and send an email to the Contact person.
Requirement is to send an email 180 days before the Contract expiration.
To implement this, we can proceed with 2 ways:
(1) Time based Workflow: If we go with this route, it will affect only if we touch the records otherwise it will not fire. Also, if we have any other complex criteria to analyse then it will not be possible here.
(2) Batch Apex: If we go with this route then it will be scheduled everyday to execute and identify the matching records to send an email. Here we don't need to touch the existing records and it runs Asynchronously.
Here is the realtime scenario.
If you have a business logic to send an email 180 days before the Contract expiration, we want to notify the User that the Contract is going to expire.
If we have only 180 days is the criteria then we can achieve this using Time based Workflow. But for this we need to touch the records as least once.
If we have additional criteria along with 180 days less than and also should work for all existing records as well then we will use some concept which should run the background where there is no need of user modifying the record.
In this situation we will go with Batch Apex, which will run everyday night and check all the Contracts which are expiring in next 180 days and send an email to the Contact person.
Please go through the below links for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_intro.htm
http://www.infallibletechie.com/2013/01/simple-batch-apex-example-in-salesforce.html
http://www.salesforcetutorial.com/what-is-batch-apex/
http://www.salesforcetutorial.com/running-batch-apex-example/
https://www.youtube.com/watch?v=PmvpMakxpm8
http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html
http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html
https://www.minddigital.com/how-to-call-batch-apex-by-scheduler-class-within-salesforce/
Please do let me know if it helps you.
Regards,
Mahesh
All Answers
Here is the realtime scenario.
If you have a business logic to send an email 180 days before the Contract expiration, we want to notify the User that the Contract is going to expire.
If we have only 180 days is the criteria then we can achieve this using Time based Workflow. But for this we need to touch the records as least once.
If we have additional criteria along with 180 days less than and also should work for all existing records as well then we will use some concept which should run the background where there is no need of user modifying the record.
In this situation we will go with Batch Apex, which will run everyday night and check all the Contracts which are expiring in next 180 days and send an email to the Contact person.
Please go through the below links for more information:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm
https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_batch_intro.htm
http://www.infallibletechie.com/2013/01/simple-batch-apex-example-in-salesforce.html
http://www.salesforcetutorial.com/what-is-batch-apex/
http://www.salesforcetutorial.com/running-batch-apex-example/
https://www.youtube.com/watch?v=PmvpMakxpm8
http://blog.shivanathd.com/2013/01/how-to-write-batch-class-in.html
http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html
https://www.minddigital.com/how-to-call-batch-apex-by-scheduler-class-within-salesforce/
Please do let me know if it helps you.
Regards,
Mahesh
Also find the below useful information:
Please check below post for best practice
Please check below post for Batch job:-
1) http://amitsalesforce.blogspot.in/2016/02/batch-apex-in-salesforce-test-class-for.html
Batch Apex
A Batch class allows you to define a single job that can be broken up into manageable chunks that will be processed separately.
When to use Batch Apex
One example is if you need to make a field update to every Account in your organization. If you have 10,001 Account records in your org, this is impossible without some way of breaking it up. So in the start() method, you define the query you're going to use in this batch context: 'select Id from Account'. Then the execute() method runs, but only receives a relatively short list of records (default 200). Within the execute(), everything runs in its own transactional context, which means almost all of the governor limits only apply to that block. Thus each time execute() is run, you are allowed 150 queries and 50,000 DML rows and so on. When that execute() is complete, a new one is instantiated with the next group of 200 Accounts, with a brand new set of governor limits. Finally the finish() method wraps up any loose ends as necessary, like sending a status email.
Sample Batch Apex
1) Start method is automatically called at the beginning of the apex job. This method will collect record or objects on which the operation should be performed. These record are divided into subtasks & passes those to execute method.
2) Execute Method performs operation which we want to perform on the records fetched from start method.
3) Finish method executes after all batches are processed. Use this method to send confirmation email notifications.
Please do let me know if it helps you.
Regards,
Mahesh
If you have a business logic to send an email 180 days before the Contract expiration, we want to notify the User that the Contract is going to expire.
If we have only 180 days is the criteria then we can achieve this using Time based Workflow. But for this we need to touch the records as least once.
If we have additional criteria along with 180 days less than and also should work for all existing records as well then we will use some concept which should run the background where there is no need of user modifying the record.
In this situation we will go with Batch Apex, which will run everyday night and check all the Contracts which are expiring in next 180 days and send an email to the Contact person.
To implement this, we can proceed with 2 ways:
(1) Time based Workflow: If we go with this route, it will affect only if we touch the records otherwise it will not fire. Also, if we have any other complex criteria to analyse then it will not be possible here.
(2) Batch Apex: If we go with this route then it will be scheduled everyday to execute and identify the matching records to send an email. Here we don't need to touch the existing records and it runs Asynchronously.
Please do let me know if it clear to you.
Regards,
Mahesh