Questions tagged [stateful]

When using batch Apex, each batch keeps a separate state. So if we define a property in the class, it usually gets reset in each batch. In order to create a property that will maintain state across all batchs we need to implement the Database.Stateful keyword.

Filter by
Sorted by
Tagged with
-1 votes
2 answers
60 views

Finish method in batch is invoked after every batch

I've recently implemented a class with Batchable in apex. There has been multiple issues, but the biggest is the finish method being invoked after every batch. I have tested by sending email from the ...
user avatar
  • 39
0 votes
2 answers
41 views

Database.Stateful, Non-Static Variable Is Null in Finish Method?

I can't figure out what I'm doing wrong here. So, I have a batch class, when I call it, it instantiates a new List<Database.SaveResult>() which is non-static and since I'm implementing Database....
user avatar
0 votes
1 answer
62 views

transient List of Database.Error becomes null in finish

I have a list to to accumulate All dB Errors, I need to use that list in finish. But the transient variable is null in finish. Here is My class: global class BatchToDoSomething implements Database....
user avatar
0 votes
1 answer
103 views

How Can A Batch Transaction Be Executed From A Nested Loop To Update Variables In The Outer Loop?

How can we update a variable in an outer loop from a Batch transaction in an inner loop? For example, consider a example scenario where you must track the even Apples (per Basket) inside multiple ...
user avatar
0 votes
0 answers
129 views

How do I test static variables using Database.Stateful across batch runs

I am using a class that implements Database.Batchable<sObject>, Database.Stateful and I need to test it. In the finish() function, I generate and store some records based on information ...
user avatar
0 votes
1 answer
315 views

How to check for the heap-size limit in batch apex?

I have a batch class that uses Database.Batchable<SObject>. How can I programmatically check for the heap-size limit in my batch? At the point where my check returns true and I'm either close ...
user avatar
  • 620
0 votes
1 answer
94 views

Database.Stateful in Batch gives errors

I have tried an aggregate query, but the result size is too large. So I built a new batch to run over the data and create an aggregation over Account and Product. Condition is that the Revenue/...
user avatar
2 votes
1 answer
142 views

How update 120,000 Contacts which must be sorted in a specific order

As part of the Artisan Hub processing (global directory of Certified Salesforce Professionals) we need to run a daily process which assigns everyone a rank based on their total Artisan Hub points. ...
user avatar
1 vote
0 answers
1k views

maintain selected checkbox state in LWC

Problem:: I’m not able to maintain the checkbox state if lightning-datatable records are changing. Background:: I have a dropdown with the values ‘All’, ‘Opportunity’, ‘myCustomObject’. Default value ...
user avatar
  • 405
6 votes
4 answers
1k views

Database.Stateful does not work as expected when using instance variable of another class

We have private field service which is instance of HelperService. HelperService is pretty heavy class, that performs several callouts, transforms responses into Salesforce objects and logs errors ...
user avatar
0 votes
1 answer
43 views

Batch Generated CSV attachement is cut

I designed a Stateful batch to some data and send it as CSV via email. And I don't know why but the attachement received in the email doesn't contains all the expected data, the CSV file il cut in the ...
user avatar
  • 333
2 votes
1 answer
2k views

Batch Apex - Static List not available in finish method

The issue I am facing is that I have a global static list declared in the batchClass. This list is populated after the values are obtained from a third party webservice. I am not able to ...
user avatar
  • 1,760
3 votes
3 answers
2k views

Batch - Sending data from one batch to another

I having a little issue to understand the concept of passing params via batches. I have two batches which I would like to send data between them. Batch A creates a Map<sObject,Set<String>&...
user avatar
  • 961
0 votes
1 answer
141 views

Sending data from one batch to another with amount of data

I have 2 Batches: Batch_A and Batch_B. I'm calling Batch_B in the finish method of Batch_A. I Implemented Database.Stateful to do so, and I'm wondering : How much Data can I send from one batch to ...
user avatar
  • 961
0 votes
1 answer
418 views

Dynamic IF condition check

I have a requirement to check in an IF condition the various State names and then add each of the records in separate maps with respect to the state names. So each map will have the records of that ...
user avatar
0 votes
1 answer
969 views

Apex Batch Job ignores Records

I have created a stateful Apex Batch Job which is processing Permission Sets defined by a Set of Ids. I want to process each Permission Set individually so the batch size is 1. The batch job creates ...
user avatar
2 votes
1 answer
707 views

Schedulable equivalent of Database.Stateful?

I'm looking to implement a class that I can schedule every 5 minutes. This class will carry out some basic monitoring activity. But in order to know what to monitor, my scheduled class will need to ...
user avatar
  • 651
1 vote
1 answer
726 views

Stateful Batch Apex with logic outside of the execute() method

I'm not even sure how to ask this question, but here goes: I have Batch class that needs to maintain state. The class looks something like this: global class myBatch implements Database.Batchable<...
user avatar
  • 384
1 vote
1 answer
440 views

How do I maintain state for Dom.Document type variables between Start and execute method of a batch [closed]

I want to create a XML Head in start method of a batch class. I was getting "System.SerializationException: Not Serializable: dom.Document" error for DOM. To handle this I declared all the variables ...
user avatar
7 votes
2 answers
676 views

Why do static and non-static lists behave differently in batch and test contexts?

Given the following batch code: global without sharing class POCBatch implements Database.Stateful, Database.Batchable<Sobject>{ public static List<String> staticList = new List&...
user avatar
  • 2,700
3 votes
1 answer
2k views

Passing a set of record Ids from a Stateful batch class to another batch class

I have an ever-evolving set of custom rollups from Tasks to Accounts, Contacts, and Leads. When I add a new rollup to the code, sometimes I need to calculate the value for all parent records. I've ...
user avatar
  • 1,194
-1 votes
1 answer
2k views

Put a counter in batch apex class

I have a batch class in which i need to put a counter to count all the records that are processed successfully. My code is as follows: global class BatchUpdate implements Database.Batchable<...
user avatar
5 votes
1 answer
2k views

Database.Stateful and Database.SaveResult in a Batchable class giving internal errors

Usually when I write a class that implements Database.Batchable I end up saving errors in a variable(s) to sort through in the finish method and send out something about successes and failures. This ...
user avatar
3 votes
1 answer
7k views

Batch finish method getting null values

I'm implementing an apex batch process. public class BatchName implements Database.Batchable<XYZClass.wrapper>,Database.Stateful{ I have declared an integer variable as public and assigning ...
user avatar
  • 2,146
1 vote
1 answer
913 views

Batch Job Callout You have uncommitted work pending. Please commit or rollback before calling out

I'm getting You have uncommitted work pending. Please commit or rollback before calling out global class BatchTransactionSurvey implements Database.Batchable<ManualSurveyController.SurveyData&...
user avatar
  • 3,006
0 votes
0 answers
38 views

Finish block of apex is not running i think.Mail is not being sent

I am not getting any error but now Finish method is not executing i think as i am not getting system.debug logs for log statement added in the finish method.Any idea why i am not getting any finish ...
user avatar
2 votes
1 answer
85 views

Getting error in batch apex on runtime

I am getting runtime error with null pointer exception.In the debug logs it is showing value of idofacc is null. Please help its urgent. Batch Apex: global class testbatch implements Database....
user avatar
1 vote
1 answer
251 views

Efficient way to get the first data in batch process iteration

This problem is quite related to my first question in this link Get Data from batch iterable I have created a functionality that will upload data to salesforce object using csv. My problem at the ...
user avatar
  • 1,213
19 votes
1 answer
2k views

Batch performance impact of Database.Stateful

I know that a Batch will generally run faster when the Database.Stateful marker interface is not used. What I don't know is, how badly the serializing and deserializing of state between each execute ...
user avatar
4 votes
1 answer
7k views

How do I pass an external variable into batch Apex?

I have a map variable that I am trying to pass into a batch class. This variable was created and populated in another batch class (which is why I can't just create it in the Start() method of the ...
user avatar
  • 3,472
5 votes
1 answer
7k views

Accessing Non-Static Variables in Static Methods of a Visualforce Controller

I have a scenario where I have one Vf page called 'myVisualforce' and a custom controller 'myController'. In myController I have some non-static variables for example 'var1' and 'var2' and I have few ...
user avatar
7 votes
1 answer
1k views

keeping a running count (rollup) with batch apex

Is it possible to keep a running count of all tasks by whoId in batch apex? I want to aggregate all tasks for a contact, but how do you prevent the count from resetting after each batch? global ...
user avatar
  • 2,353