You need to sign in to do that
Don't have an account?
Batch Class help needed for Contacts not related to Case
Hi Team,
Can anyone help me to fix this issue to Batch Class for Contacts not related to Case ASAP?
Thanks & Regards,
Karthikeyan Chandran
Can anyone help me to fix this issue to Batch Class for Contacts not related to Case ASAP?
Thanks & Regards,
Karthikeyan Chandran
As Amit says, if you post your code, it can help us to identify where is your error.
Regarding Charisse code, is doing the process in the other way around. It is removing cases that are not related with a contact. In addition, Batch process must override 3 methods, start, execute and finish and above code doesn't include finish one. For more information take a look here (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm).
In any case, this is an example of what I would do.
Hope this helps.
Agustina
All Answers
Any idea about this?
Have you tried something like this?
Please post your code so that we can help you
As Amit says, if you post your code, it can help us to identify where is your error.
Regarding Charisse code, is doing the process in the other way around. It is removing cases that are not related with a contact. In addition, Batch process must override 3 methods, start, execute and finish and above code doesn't include finish one. For more information take a look here (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm).
In any case, this is an example of what I would do.
Hope this helps.
Agustina
Here my code,
In that case, Agustina's code looks correct. The only issue is that in the start method, the query needs to use the "NOT" statement like this: This is because contactId is a set of all the Contacts that do have Cases. So you want to select all the Contacts that are not in that set.
1) http://amitsalesforce.blogspot.com/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.
Agustina's code looks perfect as per your requirement . Just change the code like below
Let us know if this will help you
It's working now.
Thanks @All for the help!!!