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
4
votes
1answer
1k views

Can you run Batch Apex after a callout?

I have a callout that is scheduled every hour to import data. Upon finishing the import, I would like to call a Bach Class that works with the imported data. Right now, I get an error saying Database....
2
votes
1answer
159 views

Heuristics to decide if to run an operation sychronous or asynchronous

Im our app we recently had to switch many operations from short running synchronous calls to asychronous Batch or future calls. It helps us overcome the many limits but also introduces many other ...
11
votes
2answers
5k views

Catching Limit Exception: “Attempted to schedule too many concurrent batch jobs”

I've got a Visualforce page that allows the user to fire a batch job manually, using this action method: public void FireBatch() { try { Database.ExecuteBatch(new AutobotBatch()); ...
2
votes
1answer
291 views

UserInfo keeps returning noreply@salesforce.com

Ok so like I explained in a previous post were having an issue getting UserInfo inside a batchable that is scheduled to run every so often. The code below outlines how were are trying to access the ...
5
votes
1answer
552 views

Getting UserInfo in Scheduled Batchable

Suppose you have an app that schedules Batchables to run. If you wanted to access say the user ID and their email inside a batchable, so specifically in the execute(), how exactly can this be done? ...
2
votes
1answer
2k views

SOQL Query in Batch Apex start() times out even with multiple filter statements

In my SOQL query in my Apex Batch start() methods I query and order SELECT TextField__c FROM MasterDetailChildWith4MillionRecords__c WHERE Active__c = 'Yes' AND Revenue__c != 0 AND Lookup__c = '...
6
votes
1answer
4k views

State variables in Apex Batch - Do they have to be public or global?

Apex Batch classes by implementing the Database.Stateful interface can maintain state via the different Batch jobs. Just keept the state information in a member variable. The example code from the ...
3
votes
1answer
249 views

Error in inserting a sobject in batch apex and passing the same object in webservice call

i need to Insert a List of Sobject Pass the ID of SObject that has been inserted in to a webservice call. This has to be done in Batch Apex since it needs to run on a daily basis. Now i have done ...
19
votes
3answers
4k views

Cool, we can chain batches now! But we can't test them. Do we?

I just used the new feature that allows me to call a SecondBatchable class from the finish() method of the FirstBatchable class. global with sharing class FirstBatchable implements Database....
4
votes
1answer
5k views

Batch Issues Invalid Query Locator When Accessing Sub Query

I'm rolling out a new batch process and started getting Invalid Query Locator error messages on certain batches (4 out of 85). Am I doing something wrong? Start Method String query = 'select ...
3
votes
1answer
1k views

Why does this batch method fail every time?

I am writing a batch method for a client that just updates a couple of field based on the date. I used this example as a guide. Here's my code: global class BatchUpdateFiscalMonth implements ...
8
votes
2answers
1k views

Install Script Batch Job failing (sObject type 'Contact' is not supported)

This is my scenario: I have a managed package, with quite some logic in it, and 2 triggers on normal SObjects, Lead and Contact the 2 triggers populate a field (included in the managed package) on the ...
2
votes
1answer
143 views

Writing Unit Test for OnInstall script

Here is the scenario. I have a custom field on Contact, which gets auto-populated in a trigger before-insert and before-update. All fine, but this is a field in an Managed Package. Where the package ...
3
votes
1answer
160 views

How to capture the no of orders done for an account for at given month?

I have a few thousand records of historical orders say from 2006 for multiple accounts. I need to somehow capture the no of orders done for an account for every month from 2006. I can do a query to ...
1
vote
1answer
3k views

Argument must be an object that implements Database.Batchable

I have wrote a batch class and now i am writing test class for it but i am getting this error. Argument must be an object that implements Database.Batchable Batch class global class ...
12
votes
2answers
11k views

NO_MASS_MAIL_PERMISSION Error from Unit Test on SingleMailMessage

I am currently working in a Config-Only sandbox. I have a unit test that is continually failing with the following error message: System.EmailException: SendEmail failed. First exception on row 0; ...
5
votes
2answers
2k views

Data Loader CLI and Encryption

We wanted to use Data Loader CLI (scheduled nightly) to push records into SFDC from a CSV file; however one key requirement is to encrypt (using AES256) while the data is pushed from the Data Loader ...
10
votes
3answers
8k views

Rollback whole Batch on error

I am using an APEX batch to process and insert large amounts of data. Essentially I would like it to process every row to catch any errors with the data and then rollback the entire batch if a single ...
-4
votes
1answer
2k views

Testing batch apex [closed]

Help me in writingTest class for Batch apex I created Batch apex to send emails to owners of the lead based on certain conditions. I have to write a test class to test gov limits. Thanks in advance
8
votes
3answers
5k views

Cascading batch jobs

I want to run 2 batch jobs in series i.e. 2nd batch should start running just after 1st batch finishes. Can I do that?
1
vote
1answer
483 views

Integration Approach

We are supposed to design the Integration approach between Salesforce App and an Enterprise System. The characteristics of the Integration is as below: Baches of data to be moved from the Source ...
4
votes
2answers
3k views

SerialBatchApexRangeChunkHandler : Too many email invocations : 11

I am working on sending mails to 50 clients at one go( basically at lead genration). I was able to send 11 mails until I used static body through SetHtmlBody() of my Batch class having Database ...
3
votes
1answer
495 views

Iterable Batch class to page through an variable number of web service results

Is it possible to use a iterable batch job to page through a web services result set? I need to import a potentially large number of records into Salesforce via a third party web service. They ...
9
votes
1answer
1k views

Cannot execute batch class from a managed beta?

My project has a batch class. Before I package my project into a managed beta, I test I can run the batch class from the Developer console. My_Batch b = new My_Batch(); Database.executeBatch(b); ...
3
votes
1answer
177 views

Too many script statements (in a patch org only - OK in dev org)

I have a schedulable class in my managed application. (I feel that some of the code I am about to discuss is not good code so in my defence I want to clarify that I did not write this code - I just ...
0
votes
2answers
1k views

Getting handle to data in finish method of batch job

I have a batch job which gets a number of users in the start interface. So I implement the following APIs global Database.QueryLocator start(Database.BatchableContext bc) global void execute(...
3
votes
3answers
2k views

Is Batch APEX the only way to execute an Apex class

I need to loop over a bunch of records from a custom object and set a value on a new field. I expect the total number of records at about 1000-1200 only. Is batch apex the only way to do this? I ...
5
votes
2answers
5k views

Want to show result after apex batch process is completed

I need to show a alert message after the batch process is completed. For that i have create a static boolean varible in a class and in my batch process finish i am calling this varible and changing ...
1
vote
1answer
6k views

What does an HTTP Response with a Status Code of -1 indicate?

I am making a web callout in a Batch Apex class and occasionally I am receiving an HTTPResponse with a StatusCode = -1 and a Status = null. Any ideas on what this indicates? Below are the entries ...
1
vote
1answer
1k views

Apex batch job is not moving

I am running a batch job but it gets stuck in middle and not moving further. Has anyone faced similar thing before?
0
votes
1answer
924 views

Can/should we use assert statement in a test class for batch processes?

I have a Batch process which updates a field on Account. I have also written a test class for it. I have an assert statement to check if the field is getting updated. Unfortunately this assert fails,...
29
votes
5answers
17k views

Workaround for the 10 web service callout limit in apex?

What are the workarounds for the 10 web service callout limit in apex. If you need to make, say 50 callouts, how do you batch them so that you can execute them all asynchronously? Is there a good ...
5
votes
2answers
6k views

Problem creating Iterable Batch Class

I am trying to create an Iterable Batch Apex Class that Allows Callouts and is Stateful. When I try to save the class I keep getting an error message that says: Save error: Type arguments do not ...
6
votes
4answers
4k views

Processing batches with a delay

I have an interesting challenge, I'm sure there are a few decent solutions but I'd like to get some input from the community. I am building a tool that will allow my users to use the Angel IVR ...
2
votes
2answers
993 views

Database.getQueryLocator sorting

Does Database.getQueryLocator respect order by clause while running a batch? I am using following code Database.getQueryLocator([select id,name from account order by industry asc]) Will this batch ...
5
votes
3answers
2k views

Data loader - each batch a discrete operation/transaction?

I am currently designing a solution which will likely include upload (insert/upsert) of 1000s of records per upload. I am doing some calculations to evaluate how far the solution might be from ...
4
votes
3answers
2k views

Count of Salesforce batches used in the Org

When I look at the "Monitor Bulk Data Load Jobs" link in my salesforce org, I see a count of batches consumed in the last 24 hours. An example is shown below. Your organization has processed **821 ...
0
votes
1answer
2k views

Best approach for sending daily email reminders

I use scheduler + batch apex + Messaging.SingleEmailMessage to send out reminder emails every 2 weeks to a specific set of users in a public group!!! Is this a decent approach/ is there any other ...
2
votes
1answer
160 views

How to add several entries at once using a related list?

How can I add several entries at once in a related list? Say, I have a custom object gifts where I want to save which (christmas) gifts a certain account likes. Now I have created a junction table ...
2
votes
3answers
3k views

How do I convert a method to Batch Apex?

hoping I can get some help with Batch Apex as I have zero experience with it and the docs aren't all that good. I have a class that does the following: 1. Constructs a Set of Account Ids 2. ...
1
vote
2answers
1k views

Batch Apex Average Time

I scheduled a batch apex class to delete around 350,000 records on Friday evening, the process has been running over the weekend and this morning it's still on the batch 416 out of 1668, is it normal ...
8
votes
3answers
4k views

Schedule apex class to run every minute as there can only be 5 batch jobs

I have a need to execute the Apex class every minute. I have a Sites VF page and in that I have link called "Export to Excel" which exports bulk data (say 50000 records of my wrapper class type) ...
5
votes
3answers
549 views

Field Describes in a Trigger causing scalability problems

I have a trigger (simplified sample code below) that is using field describes to determine what fields were changed to conditionally update some other field on the same record. The problem is that ...
3
votes
2answers
1k views

What are the limitations on using a semi-join in a batch apex query locator?

I have a relativley complex batch apex process that needs to pull in a large number of master objects based on a field on the master OR the detail object. However in my apex logic I need to ensure ...
5
votes
1answer
3k views

How to send a reminder email, X days before task due date in a managed package

I need to send a reminder email to task owner x days before due date. Please tell me the ways to crack this requirement. Some thoughts Time triggered workflows, But I doubt they can't be part of ...
6
votes
1answer
2k views

What is the difference between SerialBatchApexRangeChunkHandler and Batch-Apex

We're working on an organisation with quita a few batch processes. Monitoring some of the batch operations in testing I noticed that under the Operation column, there are both ...
48
votes
3answers
20k views

Why use Batch Apex?

What is the point of batch apex? I've been trying to do some research but everything I find just tells me how to use it or goes over scenarios where it might be useful - without telling me why I would ...
22
votes
2answers
8k views

What are the implications of implementing Database.Stateful?

I've recently implemented a batch apex class that initially did not implement Database.Stateful. After using it for a while as-is I decided to implemente better error handling via a simple Map to ...
7
votes
1answer
4k views

Handling Record Errors in a Batch Process

How does one handle individual record errors in a Batch Process? Tried the following example below, but once I iterate through wlist after the batch has completed (checking the job status through an ...
7
votes
4answers
3k views

Can't use getContent() in a batch, future method, trigger etc

I have a VF page which has a method in the controller that generates PDF and sends it out via email. It's all working fine when I trigger off the method from a custom button on the page, which is the ...