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
0answers
27 views

Best way to process huge amount of data to create small amount of records?

In need of some advice on this if someone has implemented anything similar cause I sure as hell haven't. I will not post code cause I wouldn't know where to begin, plus I am more interested in the ...
0
votes
1answer
28 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....
0
votes
1answer
34 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 ...
0
votes
0answers
61 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 ...
0
votes
1answer
120 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 ...
0
votes
1answer
54 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/...
2
votes
1answer
91 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. ...
1
vote
0answers
923 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 ...
6
votes
4answers
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 ...
0
votes
1answer
37 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 ...
2
votes
1answer
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 ...
3
votes
3answers
1k 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>&...
0
votes
1answer
120 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 ...
0
votes
1answer
333 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 ...
0
votes
1answer
820 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 ...
2
votes
1answer
638 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 ...
1
vote
1answer
654 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<...
1
vote
1answer
394 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 ...
7
votes
2answers
642 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&...
3
votes
1answer
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 ...
-1
votes
1answer
1k 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<...
5
votes
1answer
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 ...
3
votes
1answer
6k 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 ...
1
vote
1answer
769 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&...
0
votes
0answers
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 ...
2
votes
1answer
75 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....
1
vote
1answer
216 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 ...
19
votes
1answer
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 ...
4
votes
1answer
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 ...
5
votes
1answer
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 ...
7
votes
1answer
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 ...