Question:

Custom settings cant access

Everly: 2 weeks ago

CLASS

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?

Answer:
Paisley: 2 weeks ago

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;
    }
}