I am new to Apex coding and trying to build a simple trigger that connects online activity to a checkbox on opportunities. We have a custom object (Online_Activity__c) where records are created automatically by an external system. We'd like a certain online activity to cause a checkbox on the opportunity to go from false to true. However, we only want the checkbox on a certain opportunity to be checked. My code is below-
trigger purlOpp on Online_Activity__c (after insert) {
for (Online_Activity__c updatePurlOpp : Trigger.new) {
if (updatePurlOpp.Description__c.startswith ('2015 PURL Page Visit')) {
updatePurlOpp.What__r.Opportunity.PurlLink = true;
}
}
}
My question is where can I add the criteria to only update the opportunity checkbox on opportunities where Year__c = 2015 (picklist value) and Value_Prop__c = "External Product Renewal" (string). The what__r is the account object api name on Online Activity.
what__r
relationship. You'll need to do SOQL to fetch before you can update – cropredy Jan 27 '15 at 0:44Apex Class
. – Adrian Larson♦ Jan 27 '15 at 0:46