Hot answers tagged

5

If you are getting back the child job ID, why don't you obtain the parent job ID this way: SELECT ParentJobId FROM AsyncApexJob WHERE Id = :event.AsyncApexJobId (Clearly you would want to actually bulkify this in real life)


2

It's a weird behavior with the compiler. Change it to Database.Batchable<sObject> instead. Notes: You don't need to copy the list before deleting it. Use an inline query. Don't query fields you don't need. global Class Batchsample implements Database.Batchable<sObject>{ global Database.QueryLocator start(Database.BatchableContext BC){ ...


2

The batches are generated at the beginning (during the start method). As such, each subsequent batch would query any records that haven't yet updated. The solution is to re-query the accounts in the execute method to see if they still require the additional logic to be executed: public void execute(Database.BatchableContext context, Account[] scope) { ...


1

A few things here. First, scope is a list, so you need to iterate over the list of campaigns passed in: for(Campaign campaignRecord: scope) { Second, your query should filter by status instead of querying the entire database: Contact[] contactRecords = [SELECT Id FROM Contact WHERE Status__c = 'Closed Lost']; Third, it's much more likely that you'd want to ...


1

Salesforce does not allow callouts in triggers or future methods from the batch class. I think your current code requires a little restructuring where you can make the callouts directly from the batch by isolating the logic that is being called in the trigger and calling it from the batch instead. The other way to do that would add identification (like a ...


1

Somewhere in the execute method of your batch there seems to be type mismatch error like variable declared as integer getting a string type value assignment. I would suggest you to put the try catch block in your execute method and in catch try to print the complete error message and stack trace and then check the logs after execution you might be able to ...


1

You've got it wrong. You need to add the batchables to a list to execute, then pop off those values and execute them later. The instant you call Database.executeBatch, it queues that batch, and the return value is just the Job Id. That said, there's a better way to do this. You can create a chainable job design. One such design looks like this: public class ...


1

Your records in the execute block will be stale. You retrieved a Database.QueryLocator in the start method, and records will be chunked as if you queried them all at that time. However, these updates from the user will not remove the record from the QueryLocator either, it will still get chunked eventually. So if you just re-query the records in your execute ...


1

Each invocation of execute() takes place in a single transaction, and is subject to all of the standard limits for an asynchronous context. That includes the DML Rows limit at 10,000 records. If you must insert this many records per Account, you'll need to reduce your batch size to 1 or 2. That said, I'd seriously consider reevaluating this data model. Are ...


1

You missed a semi-colon at the end of line 3. List<Purchase_Order__Share> sharesToDelete = [SELECT Id FROM MyCustomObject__Share WHERE RowCause = 'Manual']; You also missed the second parameter's data type from the execute method, and misspelled execute. global void execute(Database.BatchableContext bc, Purchase_Order__Share[] sharesToDelete){ ...


1

Given that CSV's have a reasonably simple format defined in RFC 4180 it can be surprising complicated to actually implement a parser that is both correct to the spec and efficient for larger CSV files. Support for possibly embedded line breaks, double quotes, and commas makes it more complicated. There isn't an easy way to divide the workload up in Apex ...


1

I had the same problem. This was recently resolved here. The resolution (copied from that link) involves splitting the init() call into separate configure() and handshake() calls so that websocketEnabled can be disabled. Note: I was also getting an appendMessageTypeToURL error which the following code fixes by adding an additional requestHeader. $.cometd....


Only top voted, non community-wiki answers of a minimum length are eligible