0

Other questions on this topic are referencing high-level coding solutions that I'm not capable of at the moment. I am attempting to write a low level trigger that updates fields. This is extremely simple, but all the solutions I'm finding are above and beyond what I want to know. Ask_Ready_Date__c is a field on the Opportunity object. I'm working off trailheads, so I feel the syntax is fairly straightforward - what unknown rule am I violating here?

My main theory is that custom fields are not available to reference on standard object for some reason.

My error: Variable Ask_Ready_Date__c does not exist.

trigger FinancialPlanning on Opportunity (before update) {
    for (Opportunity x : Trigger.new) {
        // update this field with a date that is a year in the future
         x.Ask_Ready_Date__c = Ask_Ready_Date__c + 365;

    }

}
1
  • Pretty sure the += expression operator would work in this case. x.Ask_Ready_Date__c += 365;
    – zgc7009
    Commented Dec 5, 2017 at 21:38

1 Answer 1

2

The problem is that you're not referencing a standard object; it's trying to find a variable called Ask_Ready_Date__c, which does not exist. The fix is to simply add an object reference:

trigger FinancialPlanning on Opportunity (before update) {
    for (Opportunity x : Trigger.new) {
        // update this field with a date that is a year in the future
         x.Ask_Ready_Date__c = x.Ask_Ready_Date__c + 365;
    }
}
2
  • Thank you, I understand. I'm thinking this is x.Ask_Ready_Date__c is a variable that holds itself + 365.
    – raisl
    Commented Dec 5, 2017 at 20:03
  • @raisl Breaking this down, it's assigned from right to left: x.Ask_Ready_Date__c + 365 gets a date one year in the future, then x.Ask_Ready_Date__c = ... assigns the result back in to the variable.
    – sfdcfox
    Commented Dec 5, 2017 at 20:05

You must log in to answer this question.

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