public with sharing class AccountUpdate {
  public static void doAfterUpdate(List<Account> newRecs){
        Account_Source_Value__c other = Account_Source_Value__c.getValues('Other');
        Account_Source_Value__c partnerReferral = Account_Source_Value__c.getValues('Partner Referral');
        Account_Source_Value__c phoneInquiry = Account_Source_Value__c.getValues('Phone Inquiry');
        Account_Source_Value__c purchasedList = Account_Source_Value__c.getValues('Purchased List');
        Account_Source_Value__c web = Account_Source_Value__c.getValues('Web');

        Set<Account> acctIds = new Set<Account>(newRecs);
        //unordered list of acctIds =(newRecs)
        List<Contact> cntctRecs = new List<Contact>([SELECT Id,Account.Name,Account.BillingCity,Account.BillingPostalCode,NewField__c
        FROM Contact 
        WHERE (Account.Id IN:acctIds)]);
        // select list of contact sequence of element's 

            for(Contact cntctRec:cntctRecs){
                if( match the value of account source to my custom settings)
                 cntctRec.NewField__c = ' the value of the match'

        update cntctRecs;

I have a problem i dont know how to match the account source to my custom settings. can someone please help me with the codes?

  • 1
    It's hard to tell what you actually mean here, what do you mean by not being able to access the custom settings?
    – Matt Lacey
    Commented Feb 24, 2015 at 3:12
  • In this line if( match the value of account source to my custom settings) what is the account source field name? If you want to match by this source, why haven't you selected this field in the soql? Commented Feb 24, 2015 at 4:14
  • What's the model and data in your custom setting ? Please consider that you have to explain us what you're trying to do and provide some context to unable us to understand your question and design. Without that it's often not easy to give the best answer. Commented Feb 24, 2015 at 9:43

1 Answer 1


Your question is not very clear so trying to suggest based on assumption of your intent.

If you want to match a value of an account to a configured custom setting, then you would want to select the custom setting matching the value of the account in the loop as shown below. This should give you the value of the setting matching specified value of an account.

for (Contact cntctRec:cntctRecs){
    Account_Source_Value__c setting = Account_Source_Value__c.getValues(cntctRec.Account.<source column>__c);
    if (setting != null) {
        cntctRec.NewField__c = setting.<setting column>__c;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .