You need to sign in to do that
Don't have an account?
Steve Berley
Batch Apex workaround for - Semi join sub-selects are not allowed with the 'OR' operator
I'm trying to do a query such as below. Granted the SOQL itself is silly but it gets the point across
The challenge is, how do you accomplish this type of goal in batch apex?
The only idea I've come up with is to split the query into two parts
How have you all solved this problem?
Thanks,
SELECT id, name FROM Account WHERE name = 'whatever' OR id IN ( SELECT accountID FROM contact WHERE lastname = 'something' )No surprise that it yields the error:
MALFORMED_QUERY: Semi join sub-selects are not allowed with the 'OR' operator
The challenge is, how do you accomplish this type of goal in batch apex?
The only idea I've come up with is to split the query into two parts
Query A: SELECT id FROM Account WHERE id IN ( SELECT accountID FROM contact WHERE lastname = 'something' )
Query B: SELECT id, name FROM Account WHERE name = 'whatever'
- Make the batch class stateful and in the init store the results of Query B to a map.
- Make Query A the one returned by the batch start() method.
- In the execute() method, process the scope (from query A) and as all records from the map of query B as they're processed.
- In the finish() method process records that remain in the map of query B after all query A results handled in the batches.
How have you all solved this problem?
Thanks,
Steve Berley
With the help of some nice wine, I've come come up with a better approach.
- Still make the class stateful
- A is still the interated query the batch loops through, but this time, as each record is processed in the execute() method its id is recorded in a set of ids.
- Query B is still processed in the finish() method, but it's modified to be