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.

276 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
94
votes
0answers
3k views

When are the Queueable/Batchable penalties going to be enforced?

According to The New Apex Queueable Interface, from October 2014, we were told that chained Queueable calls would be exponentially delayed up to 64 seconds, chaining Batches would be exponentially ...
9
votes
1answer
107 views

Non-Selective Query Async (fails) vs Sync (works) - Is that supposed to happen?

Running into the following issue only during async processes (i.e. Batch Apex): Code used is same for both sync and async apex. Both essentially pass a single record into the method Batch scope is 1 ...
7
votes
0answers
381 views

Total Batches increase during the run of a batch (again)

I experienced a batch that changed (increased) the #TotalBatches during its execution. 104 total batches Reload. 106 total batches I experienced this year ago (see this question Total number of ...
6
votes
0answers
140 views

How many child records can a parent cascade delete (documented limit)?

I have a CustomObject__c which has childrens 2 level deep. Together a single parent object can have many 10.000 child records. Would it work to auto-delete the thousands ob child records just using a ...
6
votes
0answers
728 views

Append content to a document

I need to create a huge document. Naturally I face up the apex's limits such that heap size and string length. I can split the creation of the document using a batch job. I thought to create the rows ...
6
votes
0answers
2k views

error from test method - “apex job is already scheduled for execution”

I have a batch apex which starts itself after x mins. this is done in finish() method using , system.scheduleBatch() method. below is how the batch looks like, global class my_ProcessPurge_Batch ...
5
votes
0answers
57 views

Does 'Deploy with Active Jobs' work for managed packages?

So there's this new feature: 'Deploy with Active Jobs' It lets you deploy batches and schedules even if they're running. This is great for changesets. Does it work with managed packages?
4
votes
0answers
45 views

Can we work around Owner related fields not being retrievable via SOQL in apex tests?

Background: Recently I wrote a very simple Batch to run on the 1st of every month. Its purpose is to query for any Project__c records that aren't Complete, and create a related "Carry-Over" record in ...
4
votes
0answers
86 views

mixed_dml on batch execution on unknown standard object

I'm running a batch that updates several custom objects. Sometimes I get a mixed_dml error but it's not something I can reproduce, It's an intermittent error. The message that is thrown is: ...
4
votes
0answers
495 views

Batch jobs sitting in “Holding” status after flex queue turned on

Since turning on the flex queue, I am seeing batch jobs that previously executed near-instantly now sitting in the "Holding" status for a very long time. It appears that only one job per hour (on the ...
4
votes
0answers
101 views

Batch Apex: Invalid field StageName for OpportunityHistory

In my SalesForce managed package I have a Batch Apex job that queries OpportunityHistory and does some post-processing (basically serialize them and posts to external Web Service) When I schedule and ...
3
votes
0answers
61 views

Why does BatchableContext.getChildJobId() return null inside Database.Batchable.execute()?

Per the docs, BatchableContext.getChildJobId() should return the id of the current batch chunk; when running in Database.Batchable.execute() I would expect that to always be populated. I'm using it ...
3
votes
0answers
75 views

AsyncApexJob: TotalJobItems != JobItemsProcessed + NumberOfErrors

I'm running into an odd issue where AsyncApexJobs (from Batch Apex) are finishing with a status of "Complete" but the TotalJobItems != JobItemsProcessed + NumberOfErrors. Should I be concerned that ...
3
votes
0answers
96 views

Scheduler test class fails while packaging

Scheduler Class: global with sharing class Demo_Scheduler implements Schedulable { global void execute(SchedulableContext sc) { Database.executeBatch( new Demo_Batch(new List&...
3
votes
0answers
102 views

Execute Method in Batchable Class does not execute on all records returned in Start method Querylocator

I am seeing a very similar issue to the one discussed in this question, which was due to a bug in Spring '17. The Querylocator returned by the Start method returns 9,989 records, which I can verify ...
3
votes
1answer
1k views

Webservice callout - Test class - not working

I have batch class that makes a HTTP callout to a remote web service. To deploy into production, I have created a test class with StaticResourceCalloutMock. I am executing the test class in a full ...
3
votes
0answers
621 views

Future callouts when trigger fires from batch job

I have a batch job that goes through a list of a custom objects and updates certain field. This is working correctly. The custom object is part of a managed packaged. On the custom object is a ...
3
votes
0answers
582 views

Queueable interface to chain Apex batch jobs

Can we use the Apex Queueable interface to chain batch jobs? I am planning to invoke a Apex Queueable interface from the finish method of a batch job. The Queueable interface would queue the Apex ...
3
votes
0answers
1k views

Best way to bulk update data in salesforce

We have created a trigger that generates some information for a column on the Opportunity object. We now want all 400,000 existing opportunities to have the same information. The logic is encapsulated ...
3
votes
0answers
49 views

Will (Minor) Push upgrades conflict with running batches?

What will happing to running Apex Batch jobs when I perform a Push (Minor) Upgrade (Patch) into a customer org? Is that save to do? Under which circumstances? I could not find documentation or any ...
3
votes
0answers
322 views

Why does this Batch always and only abort in Production?

I have a long running asynchronous process that process millons of records in a CustomObject__c. To prevent other limits we have split this into 2 Batch classes that work on this table in parallel. So ...
2
votes
0answers
56 views

“LimitException: Batchable instance is too big” when scheduled batch runs at night

Note: This is not a duplicate of the other similar questions. We checked them before. So please don't close this as a duplicate! When calling this batch class in a production org: global class ...
2
votes
1answer
38 views

Source of an erroneous “You have uncommitted work pending” error in Test?

From the top, I do understand how "You have uncommitted work pending" errors happen, but the following is very strange behaviour from Salesforce... It seems that for one org we have, creating an ...
2
votes
0answers
44 views

Apex Batch Test - works if I populate only one account, fails in setup with 2 accounts

I have written my first Apex batch processing class. It works when I manually create records and run it in my sandbox. It is very simple. We've added a set of fields that can have up to 3 values: '...
2
votes
0answers
52 views

Tasks with TaskRelations not showing up in SOQL query results

I have written a batch which stamps the first activity date on contact records with the first created date of task or event on that record. My SOQL query is excluding tasks with Allow Users to ...
2
votes
1answer
423 views

Unable to insert records using Iterable Batch class

I'm trying to create an Iterable Batch class for inserting records. I'm able to insert my records in my normal class. I have created the Batch class and am trying to call it my current class in the ...
2
votes
1answer
89 views

Getting Encoded Vertical Line (“|”) character when querying in Batch Class

I have created a text field SP_Login_Name__c on user in which i am saving the sharepoint login name which i have to use for some further api requests. Sharepoint login name is saved in the following ...
2
votes
0answers
242 views

Manually aborting a job in a test class

For the purpose of testing some code, I want to be able to simulate a batch job run and abort in the middle of execution. How can I do this from an apex test? I tried using a boolean flag to abort ...
2
votes
0answers
517 views

Why doesn't Dataloader use specified 10k batch size when Bulk API is selected?

I have this sample CSV file containing 10,000 records (with 33 columns) I'd like to import it via Dataloader into Case object at my sandbox environment. I tried using these settings below with Bulk-...
2
votes
0answers
102 views

Unlock parent, then update child, then again lock back the parent

I have a batch class that is used to update a Field1 of Obj1. Obj1 is child of Obj11. Inorder to update Obj1, I need to unlock its parent Obj11 first. [by updating lock__c=false]. Then update ...
2
votes
1answer
91 views

SOQL Limit Hit - Aggregrate

My query hit the 50,000 record limit. Can someone help me rework the query so it operates within the limits. For reference, we have one account that has 92,000 active employees. The aggregate ...
2
votes
1answer
200 views

Testing Batch Class that triggers Chatter Post

I have a batch class that needs a test class. In creating the test records, the insertion of a necessary object record triggers a Chatter Post via another trigger. That chatter post references a ...
2
votes
0answers
2k views

INSUFFICIENT_ACCESS_OR_READONLY error when sending email from scheduled class

I have a batch job that send emails on user anniversaries. It works when I run it in the execute anonymous window from SF's developer window. I'm sending it through the org-wide email address and I've ...
2
votes
1answer
289 views

Rollback complete batch process

I want to roll back a complete batch related transaction if there is any exception while processing anywhere during batch execution I can roll back that specific transaction, but not sure if I can ...
2
votes
0answers
449 views

Get first row of CSV data in salesforce and use for mapping

I want to get data from csv and upload it to salesforce. I use this link http://www.blueengine.com.au/?p=40#comment-271 and http://developer.financialforce.com/customizations/importing-large-csv-...
2
votes
1answer
484 views

“Access to entity 'MatchingInformation' denied” on batch

I have a batch that's been running for years that started failing because of First error: Access to entity 'MatchingInformation' denied. I've searched around and can't find anything about this and I ...
2
votes
0answers
46 views

How can I run batch apex inside of batch apex?

Here's the requirement: Rolls up the number of cases created within the last 30 days to the Account. global class ZW_BatchCaseNumberRollup implements Database.Batchable<sObject>,Database....
2
votes
0answers
827 views

Finish method in batch job not invoked after an exception is thrown and caught

I'm using Database.update in my batch class. This is wrapped around by a try/catch block. When I run the batch job some error occurs which is caught as I'm throwing a custom exception and catching it. ...
2
votes
0answers
2k views

Apex code to Export Csv file to ftp server

I have to write an apex batch scheduler to send user information csv to some ftp server. I am able to generate the csv file with user records but I don't know how to send this csv file to ftp server ...
2
votes
2answers
339 views

Performance impact of relationship queries in batch start

For a new batch process I have a choice between immediately selecting relevant records in the start function (but using several [field]__r comparisons as they are junction objects being queried) or ...
2
votes
0answers
658 views

Apex batch does not update scope

I just created a batch that set some null values in some fields, what I notice is that the batch sets the nulls but it does not update the Object. I need to Edit and Save in order to see the new ...
2
votes
0answers
958 views

I want to insert, update and second time when I run Batch Class it should not add inserted records

I want to sync all Users record with Contact. I have only one Account where I want to sync all the User records. Now I am able to insert the records with Insert call of batch apex. But I am not able ...
2
votes
2answers
132 views

Good practice in querying very large data from different objects inside batch process

Good day everyone, I have created an apex class which will save data from csv to account and contact object in salesforce. The concept of this class is that it will read the column in my csv and will ...
1
vote
0answers
28 views

How can I work with both QueryLocator and List<SObject> in a single batch class (not a single instance)?

I've been working on a chainable batch class. The constructor can take in either a service & query or a service & list of records. In almost all cases, the service/query are passed in. In ...
1
vote
1answer
35 views

Can i improve code coverage for loop in batch apex

Firstly I wanna protect my organization code coverage, My scenario is as follows; I wrote 1 batch apex process, for calculate cycleTime to every products, am getting %80 covarage with this code but ...
1
vote
0answers
26 views

How does flow accept input parameters from batch class

I have an apex trigger and a batch class. I am running apex trigger on contact, sending it to batch class and from batch class sending the parameters to flow. Trigger: trigger BulkContactsLoad on ...
1
vote
1answer
23 views

Clone Data of big Object into another big Object

I have roughly 10 million records in Big Object and now I need to move the data/clone the records in another big Object. The reason why I am doing this is that I need to modify/add more fields to the ...
1
vote
0answers
37 views

Testing Batch Apex with Big Objects

I have a batch apex class that uses Big Objects for processing. However, when running tests on this batch class, Salesforce throws an error not allowing Big Objects to be inserted for testing: https:/...
1
vote
0answers
33 views

'uncommitted work pending' callout exception thrown in *tests only*

I am converting a lead in the Execute method of a batch class, then making 2 callouts with those results in the Finish() method. It works gloriously and throws no errors. However, in the test ...
1
vote
0answers
45 views

Optimised way to display batch job status on Visualforce page

In my Visualforce page, the user can schedule a job and after monitor the status of the job whether it is in progress or completed. Right now, I am querying AsyncApexJob table periodically to know ...

1 2 3 4 5 6