You need to sign in to do that
Don't have an account?
Thakkar Parth
Error: Compile Error: Field expression not allowed for generic SObject
I'm getting an error and not able to find solution . I'm trying to use best practice of trigger using trigger handler . Following is what I did uptil now . Anyone please help me to structure or help me with modification .Thanks in advance.
===Trigger===
=== Trigger Handler class ===
== OpportunityTriggerHancler Class==
I'm getting error in this class .
===Trigger===
trigger OpportunityTrigger on Opportunity (after update) { new OpportunityTriggerHandler().run(); }
=== Trigger Handler class ===
public virtual class TriggerHandler { public TriggerHandler() { } // main method that will be called during execution public void run() { // dispatch to the correct handler method if(Trigger.isAfter && Trigger.isUpdate) { this.afterUpdate(); } } // context-specific methods for override protected virtual void afterUpdate(){} protected virtual void afterDelete(){} // exception class public class TriggerHandlerException extends Exception {} }
== OpportunityTriggerHancler Class==
I'm getting error in this class .
public class OpportunityTriggerHandler extends TriggerHandler { List<Task> tasks = new List<Task>(); List<Opportunity> Opps = Trigger.new; Map <Id, String> oppsOwner = new Map <Id, String> (); public OpportunityTriggerHandler() {} protected override void afterUpdate() { for (Opportunity opp : trigger.new) { // Check if the StageName has been changed if (opp.StageName != trigger.oldMap.get(opp.Id).StageName) { // get the owner ID's that have been affected oppsOwner.put(opp.ownerId, null); } } // Map the owner ID to it's email address for (User owner : [SELECT Id, Email FROM User WHERE Id = :oppsOwner.keySet()]) { oppsOwner.put(owner.Id, owner.Email); } } }
All Answers
List<Opportunity> Opps = (List<Opportunity>) Trigger.new;
I did type casting and still no luck .
The opportunity in trigger.oldmap is also returning as an SObject and needs casting correctly.
and still using
Would request you to use my complete code and then do your modifications.