Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

On the Contact object I have a custom formula field call Prioirity__c that is defined as:

IF(ISPICKVAL(Account.Rating, 'Very Hot'), 'High', '') 

I also have a trigger defined for the contact object as follows:

trigger testFormula on Contact (before update) {
    for( Contact c : Trigger.new ) {
        if( c.Priority__c == 'High' ) {
            // do something
        }
    }
}

My question is will this trigger "do something" with Contact records where the Account.Rating == 'Very Hot' or do I have to run a SOQL query to get the value of Account.Rating for the Contact records being processed by the Trigger?


Edit:

After testing it does appear Apex Triggers have access to formula fields. Does anyone know of where this might be documented? I would like to verify this is indeed as intended and not something that could change in the future.

share|improve this question

1 Answer

up vote 5 down vote accepted

This will work without having to query the Account object. Formula field values are calculated when read so you'll have the most up to date value available in the trigger.

On a side note, you probably want to change your if statement to have == not =.

share|improve this answer
Thanks for the note about using == instead of = in the if statement. I have updated my question. – sfelf Feb 6 at 2:12
Any idea if Apex triggers having access to formula feeds are documented some where? I asked this question here because my tests proved this was true but I had been told in the past that they don't have access to formula fields values. – sfelf Feb 6 at 2:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.