function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ForceRookieForceRookie 

Batch that will update contact field based on custom settings

Somebody please help me on how to update Contact’s field value if I subtract two Custom Setting’s fields?
GauravGargGauravGarg

Hi Rookie,

How will you trigger Contact on changes of Custom setting, we cannot write trigger or class based on the custom setting. 

You need to put it in Object that can throw some event on the update of records. 

Thanks,

Gaurav
Skype: gaurav62990

ForceRookieForceRookie
Hi Gaurav, thanks for the reply.. so here’s the scenario: Two custom settings: 1. Contact score fields - it has custom field with value of Contact API field (example, MyField and the value is Score__c) 2. Decay Field - it has custom field Decay and has a value of 4. I’m just wondering too on how it will update the Contact field Score__c after calculating these two custom settings.
GauravGargGauravGarg
Hi Cristelle,

How will you identify which records should get updated with the value stored in both Custom setting? I can understand, you have two custom setting 
  1. The first custom setting contains a field API name and the value. 
  2. The second custom setting has field Decay API name and the value. 
Thanks,
Gaurav
Skype: gaurav62990
ForceRookieForceRookie
Hi Gaurav, The first Custom Setting has custom field (MyField) with the value of Contact’s field (Score__c) The second Custom setting has a custom field (Decay) with numeric value (example, 4) So in my batch, I have to subtract those custom fields and then update the Contact field (Score__c) with it’s answer. I’m just confused on how to query that on Contact batch for me to update the Contact field (Score__c) I will be glad if you can help me, thanks!
GauravGargGauravGarg
Hi, 

There might be 100 or 1000 or lacs of Contact records in org, how will you identify the single or list of records to get updated based on the custom setting?

In batch:
//Cacluate score value.
Integer cs1 = myfield.getValue(Score__c);
integer cs2 = Decay.getValue(decay);

Query Contact
List<Contact> contactToUpdate = new list<Contact>();
for(contact c :[SELECT id, Score__c FROM Contact])
{
   c.score__c = cs1-cs2;
contactToUpdate.add(c);
}
update contactToUpdate;

Hope this helps you to identify your solution. 

Thanks,
Gaurav
 
ForceRookieForceRookie
Hi Gaurav,

All of the Contact will be updated since all of those have Score__c field.

I’m just curious on how can my batch will
identify that I’m getting the value from custom settings and update the Contact field.

Thanks for the reply!
Will update you later after I test the batch.
GauravGargGauravGarg
Hi Cristelle,

Did you get any updated on this. 

Thanks,
Gaurav
 
ForceRookieForceRookie
Hi Gaurav,

I have already figured out the answer for this. But thanks btw.

Will it be possible to delete my unresolved questions here?
GauravGargGauravGarg
I am afraid NOT, but, you can post the Solution you found and mark it as "best answer" to close it off.