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
-2 votes
0 answers
31 views

System.debug() is not displaying when running a batch class

I have a batch class that is just querying for some records, and have included some system.debug so i can see what is being outputted, though in the logs, the 5 logs that are being created, none of ...
Omi in a hellcat's user avatar
1 vote
1 answer
51 views

Retrieve Batch Class Name from Trigger

In order to cover a specific requirement, I need to determine that the DML action of inserting the records of an sObject has been triggered through a batch. The System class provides the isBatch() ...
Tzinm's user avatar
  • 21
2 votes
1 answer
53 views

Batch job sporadically not updating/creating some records

I have an issue where my batch job seems to be choosing a random amount of records to not update/create. There is no error thrown from what ive seen, and I do not have a try/catch that would allow for ...
Trace's user avatar
  • 127
1 vote
0 answers
28 views

Create Opportunity & related OpportunityHistory Test Data

I've written a batch job which queries a bunch of Opportunity records and their related OpportunityHistory records to capture data from the history records on the Opportunity. This is working as ...
VaroutSP's user avatar
  • 341
-1 votes
0 answers
12 views

how to use Lastlogindata test code

Last Login data is readonly, so the field cannot be changed. So how can I write test code for that field? I have a batch code that excutes and processes the lastlogindate from a certain period of time ...
ga rok's user avatar
  • 1
0 votes
1 answer
23 views

If an underlying record changes before a batchable gets to the record is it still run/uses the latest values?

two examples I am running the query [SELECT Id From Account] to select all accounts. The batchable gets to the account (Name='Steve') and in the mean time the underlying record has changed to (Name='...
KarlLivesey's user avatar
0 votes
0 answers
28 views

Best practice to deal with HATEOAS api callouts

I'm creating an connector between Salesforce and a ticketing system that exposes a REST API based on HATEOAS. I need to synchronize tickets everyday and insert/update them as Cases. Salesforce is ...
Yan Imensar's user avatar
0 votes
0 answers
31 views

What is the difference between SingleEmailMessage and MassEmailMessage?

While i'm sending Email for 30 records both are getting Limit exceed Exception Through Batch apex i give batch size as 10 but still getting exception.This is my code global class ...
user147601's user avatar
0 votes
1 answer
31 views

CSV report generation using apex batch

I am trying to generate the csv report by fetching the data from ApexTestResult obj. But the column 'message' in the apextestresult obj is overlapping and automatically divided the message and showing ...
RKCY's user avatar
  • 313
2 votes
1 answer
71 views

LWC Export query results to Excel/csv where rows > 2000 prior to delete

I have an LWC where I run a query to clean up/delete records. The LWC works fine for showing 2000 rows at a time in a datagrid (although 2000 is a bit of a big grid so I set 2000 as the max but ...
Irene's user avatar
  • 1,811
0 votes
1 answer
32 views

How to test Batch Apex Heap Size Logic?

I have a batch class that implements Database.Stateful and it is filling a Map collection at the execute method alongside other things. This map is then utilized to send emails related to the records ...
selman's user avatar
  • 25
0 votes
1 answer
57 views

Mocking a Batch class?

Is there any way to mock a batch class for unit testing and predefine the scope passed to execute method? I am using a selector class method for Database.getQueryLocator at start method. public class ...
selman's user avatar
  • 25
0 votes
1 answer
46 views

LWC delay refreshApex until batch job completes

I have a datatable in an LWC where rows can be selected for deletion. The delete process is done via a batch job due to multiple triggers running for the object being deleted. Once I've kicked off the ...
Irene's user avatar
  • 1,811
1 vote
0 answers
37 views

Error : unable to obtain exclusive access to this record while posting the Invoices

I have build the custom logic to post all the invoices by clicking on Lightning Button. It retrieve the Invoice Run Id and get all the invoices that are in Draft stage. I am sending in batch size of 5 ...
Tayyaba Noor's user avatar
1 vote
0 answers
41 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,624
0 votes
0 answers
80 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
  • 25
0 votes
2 answers
43 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
43 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
37 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,811
0 votes
1 answer
80 views

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

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
60 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
103 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
77 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
74 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
234 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
50 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
117 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
363 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
91 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
105 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
  • 37
-1 votes
1 answer
298 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
  • 27
1 vote
1 answer
600 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
271 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
63 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
511 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
99 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
49 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
37 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
  • 915
1 vote
1 answer
108 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,527
0 votes
0 answers
151 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
79 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
123 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
35 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
148 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
145 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
354 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
205 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
60 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
333 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

1
2 3 4 5
41