New answers tagged

1 vote
Accepted

Im getting error Comparison arguments must be compatible types: String, NULL

tl;dr: you wanted to use != instead of !==. !== is used for strict inequality checks. You can use it for things like: Account a = new Account(); Account b = new Account(); System.assert(a!==b); ...
user avatar
  • 438k
0 votes

I want make test class for batch apex

You need to create a list of solutions__MessageType__c, and pass that in: solutions__MessageType__c[] records = new solutions__MessageType__c[0]; // Add some records to the list, then... ...
user avatar
  • 438k
1 vote

how to pass the value in test class

Your query is filtering with: Id NOT IN (SELECT Billing_Scheme__c FROM Account_Allowances__c) Which appears to exclude all of the Billing Scheme records you created. Consequently, the execute method ...
user avatar
  • 438k
0 votes

Batch class to remove duplicate records

You Need to Approach the Problem Differently You shouldn't loop over records to merge duplicates like this. Even though the logic is wrong I'm not attempting to fix it since it needs to be re-written ...
user avatar
0 votes

Database.executeBatch cannot be called from a batch

Use a static variable in both classes called IsExecuting. Now in the run function of each batch make sure it is set to true. Finally, add a conditional where you're firing your other batch to make ...
user avatar
1 vote

How to fix "QUERY_TIMEOUT: Your query request was running for too long." error

I don't know how many of those fields are indexed, but there is another reason for your query to take that long: too many records to be returned by the database. In this case you should look into ...
user avatar
1 vote
Accepted

Error in Dynamic SOQL when binding a variable

Let's say your class is like this: public inherited sharing class MyFirstBatch implements Database.Batchable<SObject> { String query; public MyFirstBatch(objName, fromDate, toDate) {...
user avatar
  • 3,603
1 vote

Testing a batch class where I need to modify System fields?

If you Enable the 'Create Audit Fields' permission, make sure your user has this permission assigned (perhaps by Permission Set), then perform an insert DML operation, you can set the dates as you ...
user avatar
  • 438k
0 votes

How to differentiate the batch class based on the different parameters passed and fire different email based on the parameters when batch class fails

If you continue using the BatchApexErrorEvent to track errors (I understand that catching exceptions locally in the batch isn't always possible, especially if the batch is exceeding limits) then you ...
user avatar
  • 28.1k
0 votes

Error Message need to display in email body in Batchable Apex Job

you are almost there, you just need to make a few changes on your finish method: global void finish(Database.BatchableContext bc){ // check if you got any errors during the execution (no need ...
user avatar
  • 407
0 votes

How to fix "QUERY_TIMEOUT: Your query request was running for too long." error

The query can be optimized using the SOQL query optimization mechanisms described e.g. in this Trailhead: https://trailhead.salesforce.com/content/learn/modules/database_basics_dotnet/...
user avatar
0 votes

Batch apex. How to query custom object id that have lookup on different custom object

You are passing the query as String and you query contains String evaluation in the Where condition. In these scenerios you have to use \' where you want to use the single quotation. So the query ...
user avatar
0 votes

how to delete record in Contact field have other picklist value

I'm not sure I understood your requirements 100%, but let's try! If I'm not mistaken, your question is regarding the two Contact query Strings in the start method. Although you're stating the field ...
user avatar
2 votes
Accepted

How to pass variable from helperclass to finish method in batchclass

Since we can't call the finish method from our code and it gets called from SFDC end after all the batches are processed, you can't pass a member variable of the helper class to the finish method. In ...
user avatar
2 votes

Finish method in batch is invoked after every batch

Salesforce batch class is designed in a way that start(Database.BatchableContext bc) and finish(Database.BatchableContext BC) runs only once in the entire context of batch class run. It is the execute(...
user avatar
1 vote

Finish method in batch is invoked after every batch

As mentioned in the comment you are calling the Batch class from AfterInsert context in trigger. When there are more than 200 records trigger processes in chunks of 200 records and so your batch is ...
user avatar
0 votes

Set in Batchable Apex

Assuming you need to update only those contacts which are linked to Training Logs Create a Map of contact Id and Contact records Query all the T Logs which have the flag true and are linked to ...
user avatar
4 votes

When I will change a class on Production (via change set deployment), then I need to delete and add "Scheduled Job"?

It depends on if you enable "Allow deployments of components when corresponding Apex jobs are pending or in progress". When false, deployments will automatically fail if any jobs are pending....
user avatar
  • 438k
-1 votes
Accepted

how to merge two For Loop

set set_nonDeleteId = new Set(); if(sObjectType == 'Order') { for(SObject obj : s_object){ order__c order = (order__c)obj; if(order != null){ ...
user avatar
0 votes
Accepted

How to get field value sobject in batch class

Your this line: for(Case c : obj.cases){ Just above this line you are typecasting the obj to Contact. And obj is SObject, so it does not have any reference to cases Try for(Case c : contacts.cases){ ...
user avatar
0 votes

How to get field value sobject in batch class

Unfortunately, some Salesforce documentation encourages the use of dynamic - string based - queries in Batchable classes. As in most other places static - compiler checked - queries are the better ...
user avatar
  • 130k
2 votes
Accepted

Can I pass several variables (set and maps) to finish method of batch

Please implement Database.Stateful interface and create instance variable in the class to hold the map or list. Same can be used in finish method. Salesforce Developer Guide around Database.Stateful ...
user avatar

Top 50 recent answers are included