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.

321 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
98
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
113 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
530 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 ...
7
votes
1answer
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 ...
6
votes
0answers
159 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
806 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 ...
5
votes
0answers
59 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
199 views

AsyncApexExecutions Limit exceeded different errors

We have a batch that is running queueable inside batch execute. And we are testing this framework with volume data to know its limits. To give an example, if I test it using 1000 records with 1 scope ...
4
votes
0answers
135 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
88 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
525 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
107 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
112 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
132 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
124 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
104 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
0answers
658 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-...
3
votes
1answer
255 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 ...
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
712 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
632 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
51 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
327 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
39 views

Batchable Apex: Querying records that follow 2 sets of criteria in start and then doing 2 separate things with each set of records in execute

I'm writing a batch job that queries for Contact records following 2 sets of criteria and then adds them to an export object with corresponding flags of whether they fulfilled criteria set 1 or 2. My ...
2
votes
1answer
53 views

Prevent limits in a callout intensive process where client can only receive one request at a time?

I have a callout intensive process where the client can only receive one request at a time and I'm having a hard time identifying what is the best practice for asynchronous solutions to handle this ...
2
votes
0answers
89 views

Apex Job Gets Stuck Processing

I have the following problem. There is an Apex Scheduled job that runs everyday at 2AM that gets stuck during processing. As seen in the image below, the batch process reaches 330 and then stalls ...
2
votes
0answers
44 views

order of records received in batches for batch class

I have a batch class where i need to grab the records sequentially. It looks like if i am querying regularly in salesforce and system.debugging the outputs, the records do not seem to be in any ...
2
votes
0answers
139 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
41 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
55 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
101 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
696 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
177 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
292 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
103 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
92 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
0answers
3k 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
381 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
470 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
0answers
1k views

INVALID_CROSS_REFERENCE_KEY, invalid cross reference id on Lead update

I am trying to run a batch apex to update a list of leads, i get this error 'INVALID_CROSS_REFERENCE_KEY, invalid cross reference id:' only for few of the apex jobs, the other jobs of the batch ...
2
votes
1answer
616 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
897 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
2answers
394 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
744 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
1k 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
167 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
24 views

Even with KnowledgeUser I get: Be sure the action is valid for the current state of the article, and that you have permission to perform it, exception

I have the below test class: @isTest public static void batchManagementDraftTest() { User u = TestDataFactory.createUserWithRoleLeader(); User u2 = TestDataFactory....
1
vote
1answer
37 views

SOQL Query on Collaboration Group fails only in live code, not in Execute Anonymous Window or Query Tab of Developer Console

Simple SOQL Query fails to yield results in live Apex code, but succeeds in Developer Console Execute Anonymous Window and in Query Editor Tab. public void importProgramCollaborationGroupTable(){ ...

1
2 3 4 5
7