+ Start a Discussion

Batch: update contact value based on custom settings calculation

Help me to create a batch on Contact object.

So I have two Custom Settings (Hierarchy):
1. Contact Score Fields - inside this, it has custom fields with the value of Contact’s field API (example, the custom field is MyField and the value is Score__c)
2. Decay Field - it has custom field of Decay and a value of 3

I have to subtract the two Custom Fields and it will update the Contact’s Score__c field value as the answer.

Thanks in advance for the help!
Kamal ThakurKamal Thakur

Hi ForceRookie,

What you're asking is a complete solution and It would not be wise if we do a job for you. What we could help you with is if you are facing any issues in your code, you can post your code here and we can try to solve it. 

You can start with below links - 


Asking for the complete solution will do good for neither you nor us. 



Hello Kamal, I know how to create a batch but I’m just confused on how to update the Contact’s field. Do you have any idea how to query it?
Hello @ForceRookie,

There are three methods you need to call for creating the batch classes named as Start, Execute and Finish.

In the start Method, You need to write the query to get the records which will help you to update the records.

Example the query returns 1000 records, In the Execute method, it will receive only 200 records at once.

In the Execute Method, You need to write the logic for calculating the values. You can update the records in the end of Execution method.

Or if you know the count of update records and those are in limits then you can write update code in finish method.

Jolly Birdi

Please mark this as best answer if you find it positive.
Hi Jolly,

I know that.
What I’m trying to figure out is.. on how can I get the custom settings’ values and then update the Contact’s record. It just confused me.
I’m thinking of the solution rn.
Hello Rookie,

To get the Custom Settings value you need to check the Api of the label that you have created in custom settings. Let it be CustomSetting1__c

Then Under Manage of CustomSetting1 you have created the Name with Value and Let name would Name1 and its value is true.

Then your code would be to receive the value is below:

CustomSetting1__c customSettingVal = CustomSetting1__c.getValues('Name1');
String Value = customSettingVal.value__c;

Jolly Birdi.
Please mark this as best answer if you find it positive.