Questions tagged [batch]

Classes implementing the `batchable` interface are used when there is a need to operate on a large number of data records which would normally be problematic due to the imposed governor limits.

Filter by
Sorted by
Tagged with
1 vote
0 answers
35 views

Managing state in object graph spawned by Batchable

Prelude I understand the following regarding batch Apex: State Variable Values stateful static are reset for each batch execute() run instance (non-static) are maintained across all batch execute() ...
Moonpie's user avatar
  • 2,544
0 votes
0 answers
66 views

Pass Map from Batch Apex to VisualForce email template and iterate on it

I have a Batch Job called ContractExpirationNotificationJob and it identifies expiring contracts and sends the owners a list of expiring contract records by email. Currently, I am using a method ...
selman's user avatar
  • 1
-2 votes
0 answers
107 views

Parent Child For loop in batch class causing "too many query rows" error

Below Parent Child for loop is hitting the too many query rows limit when running in a batch class. Global class GAUBatchPaymentRollups implements Database.Batchable<sObject>, Schedulable { ...
Trace's user avatar
  • 93
0 votes
2 answers
37 views

Test Class coverage on execute method of Batch Apex which is Scheduled to run at specific interval of time

I have a Batch class, which queries Lead records that were created 1 day before. I have created a custom Label 'More_Than_1_days' which has the value 1. I was using this custom label in that batch ...
Mohd hasim's user avatar
0 votes
0 answers
37 views

Several updates on Case record withing short period of time causing "duplicate value found: <unknown>"

I have pretty complex process starting with scheduled Batch Apex, calling my Mulesoft endpoint to retrieve some data and save it on Case record: Batch apex request from Salesforce to Mule is ...
Michal Piatek's user avatar
0 votes
0 answers
34 views

Batch Class - Performance Optimization

I have a batch class which converts attachments to Files for old records in the system. We are running with batch size of 20 to 25 for the attachments to convert to Files but the conversion process is ...
RedDevil's user avatar
  • 7,803
0 votes
1 answer
55 views

Working with regex on big Strings (Avoiding Regex too complicated error)

Is there a way to divide/simplify a pattern match to avoid getting this error ? Sometimes the Json String that I'm trying to match is way too long and it causes errors on a batch a class. I am ...
peepoCode's user avatar
-3 votes
1 answer
50 views

System.FinalException: SObject row does not allow errors on Batch

i am trying to create a batch that prevent from creating duplicate records. This is my classes and trigger Class batchCheckDoublonContact : global class batchCheckDoublonContact implements Database....
Amir Bouzid's user avatar
1 vote
1 answer
76 views

SSJS script is timing out at 30 minutes. How to I build series of scripts using rownum to parse the DE sequentially?

We have an SSJS script that is calling an API to fetch price of items and writing it into a DE. The API call is taking time and in 30minutes the script is only able to retrieve the price for ~6000 ...
Anay Shrikar's user avatar
0 votes
0 answers
69 views

How to store large amount of data in a variable for a batch bypassing heap size exception

I am stuck with the following error: 'Batchable instance is too big: ProductDiscountsFormatterBatch' I have a junction object called Account_Product_Discounts__c with the information of, for each ...
Arnau LS's user avatar
1 vote
1 answer
54 views

Test System.Limit Exception Handling with BatchApexErrorEvent

I want to provoke a System.LimitException in a test method, so I can test BatchApexErrorEvent trigger that is supposed to handle uncatchable exceptions like CPU-Timeout etc. However the LimitException ...
Robert Méndez's user avatar
0 votes
1 answer
157 views

Error while creating a test class - DML operation Insert not allowed on Survey [duplicate]

I have created a apex batch class to create survey invitations, subject records & send the unique survey links to participants. Trying to write a test class to cover it by inserting a surveybut ...
SMorse's user avatar
  • 39
0 votes
1 answer
44 views

Salesforce System.AsyncException - scheduled class calls Queueable apex do a callout and then calls batch apex

I have a schedule apex class that calls Queueable apex which calls a class that do a callout and then execute batch. I receive System.AsyncException: Database.executeBatch cannot be called from a ...
Muhammad Refaat's user avatar
-1 votes
1 answer
91 views

Can we do a callout inside for loop in batch class

Callout class Public class calloutValidation{ public static string CalloutCheck(String Email{ try{ //There are some logic HttpRequest req = new HttpRequest(); ...
SFL's user avatar
  • 1
-2 votes
1 answer
168 views

Which is a better approach when updating records using batch class, to place it in execute or finish method?

Sorry but I am new to this and I just wander, do you think it is better to put all the millions of records inside the Map object which is process by the execute method, however the dml where the ...
Kato's user avatar
  • 1
1 vote
2 answers
90 views

Batch Apex Class Invoked From Before Delete Trigger is not deleting Files Attached to accounts

I have written a batch class to delete the files related to an account whenever an account is being deleted. When I have tried the same code and logic without batch class it works fine. But in batch ...
Ameer's user avatar
  • 21
-2 votes
1 answer
82 views

Can we do DML in batch APEX start method [closed]

Is there a possibility to insert records in the batch Apex's start method?
sfdcDev's user avatar
  • 27
-1 votes
1 answer
224 views

How to fix Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch

Apex class : public static List<AggregateResult> calculOppN1(String userId, List<Id> filialeIds, List<Id> marketIds , Integer count , Date startDateN1 , Date endDateN1){ ...
Fark's user avatar
  • 17
1 vote
1 answer
332 views

I have an Accounts with multiple related Contacts. How can I retrieve only one Contact for each Account?

I have an Accounts with multiple related Contacts. My requirement is to retrieve one contact record for each account. If one Account has multiple Contact, I just want to retrieve one Contact record. I ...
newbieApexLWCDev's user avatar
-1 votes
1 answer
206 views

Create Excel file in Batch Apex Class

I am updating some records in my Batch Apex. I want to add those all records in some excel file and mail it. I am able to do this if i add all those details in a csv file instead of xml file by using ...
tycoon's user avatar
  • 3
1 vote
1 answer
56 views

Why is my batch showing error in test class but not in actual execution?

I have a batch that has a callout and it goes something like this. public with sharing class MyBatch implements Database.Batchable<Connection__c>, Database.AllowsCallouts, Database.Stateful { ...
Carl Ortiz's user avatar
1 vote
2 answers
490 views

Dynamic SOQL Error: Unexpected Token ':' - I have searched for two days, what could I be missing?

I have a batch class that will be performing some actions over selected Case records. The only problem with this batch class is the Start method. When the query is returned and processed, it returns ...
Emmanuel_M's user avatar
0 votes
0 answers
76 views

SOQL query error on CPU TImeout for Batch Apex

I have a Batch Apex operation that is part of a managed package that is failing in the start() method or soon after since the start() log is the last one displayed. I run a SOQL query that gets all ...
bswartz's user avatar
  • 27
-3 votes
1 answer
46 views

SOQL to get 3 months no stage movement on the opptuity

I want to make a batch class to auto closed lost opportunity if 3 months no stage movement Now I made this SOQL in Database.QueryLocator start: SELECT Id, Name FROM Opportunity WHERE Id IN (SELECT ...
Mustika Farma's user avatar
0 votes
0 answers
54 views

Unexpected behaviour when firing a apex method

I have this piece of code: public static void initTraitementBillingApi() { String methodName = 'traitementDPF'; ObjectUtil.debugLogBegin(CLASSNAME, methodName, ''); //String periode = ...
Fabien Braconnier's user avatar
0 votes
0 answers
35 views

Apex CPU limit exceeded on Batch start method

I have an scheduled batch that processes records but I'm hitting CPU limit exceeded error on start method. This is my code (SortLogicBatchQuery retrieves ~500000 records): public BatchSortProjects(){ ...
molinet's user avatar
  • 905
1 vote
1 answer
97 views

batch vs queueable for pseudobulkification of an app

I'm testing out an app that uses a callout to check some info in a government database and writes back any hits to a custom object. The app is designed to be used via an action on a record page, but I ...
gorav's user avatar
  • 4,517
0 votes
0 answers
135 views

Bulk API 2.0: Can I insert AND upsert in one csv request?

Edited to clarify: Background info on what I'm working on – we're going to be receiving email lists from clients, and we want to create new Leads or update existing Leads in Salesforce with the info ...
Brittany Layne Rapheal's user avatar
0 votes
0 answers
71 views

Async-safe mass delete of children with Batch

How to write in Apex a mass deletion (over 10 000 records, even up to 150 000) of related records that can be safely called from async context, like Batch? I have two custom objects, lets call them ...
zanstaszek9's user avatar
0 votes
1 answer
107 views

Execute a batch with custom delay between each batch processing

I have a batch class which update the primary field on the quote object using batch size of 1. I need to do this in such a way that each batch is processed 30 seconds after the previous one(there ...
Tony Jude's user avatar
0 votes
1 answer
33 views

Email in batch class

I am able to send email in batch class.But email is being send to Gmail only.It is not getting send to other type of email like company email. Execute method is working fine for other type mail but ...
Guest's user avatar
  • 3
-1 votes
1 answer
115 views

How to schedule an apex batch job at the end of each quarter

I want to write a cron expression to schedule a batch job at the end of each quarter i.e. 31st March,30th June,30th Sep and 31st Dec but unable to figure out how to do so. Has anyone done so ?
Aniket Srivastava's user avatar
0 votes
1 answer
111 views

Usage of Database.getQueryLocator

I am new to the batch class working, and I have a somewhat weird question. When I write this in the start method of a batch class: return Database.getQueryLocator([ SELECT Id, ...
RVK SF's user avatar
  • 9
-3 votes
1 answer
195 views

Hot to prevent Too many query rows: 50001 for a batch method

I have a batch class which I use to update a field of all historic records of an object. I have a trigger on the same object to update the same field when a record is updated. The trigger does exactly ...
Thomas's user avatar
  • 2,294
0 votes
1 answer
181 views

getContentAsPDF() from batch Apex request works in scratch org but not production

I have a Batch class that calls a Visualforce page using getContentAsPDF() to generate a single PDF. This works flawlessly in a scratch org and in the developer logs I can see a separate call made to ...
Dan's user avatar
  • 195
0 votes
0 answers
54 views

Salesforce Batch – Limitations (semi-joins, governor limits)

I need to write a Batch class to delete records from Child to Parents objects: Child__c --> Parent__c --> Parent_Of_Parent__c Every object has approximately 5 million records to delete, so I ...
Alessia's user avatar
-3 votes
1 answer
289 views

Send 1 Million records data to external system using batch class

I am trying to send the data to external system from batch class.. Where data include 1 million records.. I wrote below batch class. In batch class I am making callout to the external system and ...
K Sravanthi's user avatar
0 votes
1 answer
72 views

How to sum the values of an aggregated query

I have a parent object Account with related contacts these related contacts have (several) related statuses i.e. A B C. These are all the statuses a contact has had. On the parent Account I need to ...
Thomas's user avatar
  • 2,294
0 votes
2 answers
285 views

Is it guaranteed that First submitted Queueable or Batch class will run first?

We have to send case create and update data via API to third party. For create case: In trigger we are collecting all the case ids in set and calling queueable class if cases created are less than 100 ...
Sukruti's user avatar
  • 450
0 votes
1 answer
124 views

Deleting and re-inserting EmailMessage records along with Attachments

I have the following requierement: I need to recover some space in my org by taking all the EmailMessage records older than certain date and stripping the HTMLValue from them while keeping their ...
David de León's user avatar
1 vote
1 answer
82 views

System.LimitException: Too many query rows: 50001 when Using AggregateResult interface in batch class?

I want to aggrgate Average of Quality Score of Account object based on User's Market and I want to those summary details in one of Custom Object. I have written a batch class where I am using Iterator ...
SFDCDJ's user avatar
  • 1,834
0 votes
2 answers
81 views

A batch to insert 41000 task records [closed]

I want to insert task records around 41k. I used below batch class. This seems running but I can't find any records creating. public class BatchInsert implements Database.Batchable<Task> { ...
Sushil's user avatar
  • 3
0 votes
2 answers
239 views

Is each chunk of a batch Apex class transaction gets shared among the trigger which runs before/after each DML of the batch?

If a batch apex is called with size say 200 (default size). And we have a DML operation (say update) in execute method of the batch. So the trigger which is set to run before/after update will share ...
ItsVicky's user avatar
0 votes
0 answers
15 views

When will Aysnc method or Class will execute? [duplicate]

We have a case object subject field. When the case is created, Trigger fires and update the subject, then flows fire to update subject again..Now i have a future method or Queueable class or batch ...
Sukruti's user avatar
  • 450
-1 votes
1 answer
60 views

Independent Bulkification vs Batched Processing

I have been acquiring quite a bit of information about how bulkification and batch record processing works in salesforce (bits and pieces - salesforce documentation does not seem exhaustive). While I ...
Luke Sharon's user avatar
-1 votes
1 answer
47 views

Batch Processing

I have a batch class which is searching roughly 5000 leads and making a callout to an API depending on lead values. after the start batch the scope has roughly 1000 records to loop, and making a ...
CalDe's user avatar
  • 3
0 votes
2 answers
416 views

How do you pass a List of records to a batch apex class to be inserted?

I need to clone +10000 records. Yes,I'm aware of all of the limits and pitfalls associated with tying a trigger to a batch apex class. I'm accounting for it as only 1-2 people will be able to perform ...
Andrew Bloch's user avatar
1 vote
1 answer
896 views

Able to query deleted records from recycle bin but not to undelete them with system admin no role

How i deleted parent account (which caused related event or task records deleted itself): I've run a batch, which do dml and send other sobject records to be dml in other batch from finish. I had to ...
Ankit's user avatar
  • 19
0 votes
1 answer
69 views

Apex Batch stops after 2000 records

We have an Apex batch class which processes 2950 records of contacts, sending them emails with Messaging.SingleEmailMessage method(The query has a filter for IsEmailBounced = FALSE AND Email != NULL). ...
DavidS's user avatar
  • 37
0 votes
0 answers
15 views

Receiving Email body and Subject but unable to receive Opportunity Details

I have been getting email but only the subject and body but not receiving any details of the for loop their is no error showing and the batch class is running proprerly list<String> oppids = ...
Mr_Moon's user avatar

1
2 3 4 5
41