You need to sign in to do that
Don't have an account?
Shazib Mahmood
Cross object reference not working in my trigger
Hi guys,
I am trying to write a very simple trigger but running into some issues. On case I created a lookup field to Opportunity.
trigger UpdateCaseAndOppOwnerManager on Case (before update)
{
for (Case caseselected : Trigger.new)
{
caseselected.Opportunity_Owner_Email__c = caseselected.Opportunity__r.Owner.Email; // Issue # 1. Brings back a null value every time.
caseselected.Case_Owner_Manager_Email__c = caseselected.Owner.Manager.Email; // Issue # 2. Owner.Manager reference is not valid
}
}
Issue # 3. I want these fields to be populated actively like a formula field and not just upon insert/update i.e save. What should I look into, to achieve that ?
Thank you for all the help !
Cheers,
Shaz
I am trying to write a very simple trigger but running into some issues. On case I created a lookup field to Opportunity.
trigger UpdateCaseAndOppOwnerManager on Case (before update)
{
for (Case caseselected : Trigger.new)
{
caseselected.Opportunity_Owner_Email__c = caseselected.Opportunity__r.Owner.Email; // Issue # 1. Brings back a null value every time.
caseselected.Case_Owner_Manager_Email__c = caseselected.Owner.Manager.Email; // Issue # 2. Owner.Manager reference is not valid
}
}
Issue # 3. I want these fields to be populated actively like a formula field and not just upon insert/update i.e save. What should I look into, to achieve that ?
Thank you for all the help !
Cheers,
Shaz
Option # 1 : Best option to populated actively, you need to create both fields as formula fields .
Opportunity_Owner_Email__c = Opportunity__r.Owner.Email
Case_Owner_Manager_Email__c = Case_Owner_Manager_Email__c
Option # 2
Create Workflow with field Update on Opportunity(2 workflow) & case( 2 workflow).
Option # 3
Create two trigger on both object.
If this answers your question then hit Like and mark it as solution!
I cannot use formulae because of object reference limits. I believe I can work around issue # 2 using the link you provided. I am still not sure how to go ahead with debugging issue # 1. Logs show me null value being returned for it.
Hello Shaz
Issue # 1 : Its bring null because of it is difficult to get direct relationship contaxt without querying, so we need to query.
Issue # 2 : There are two owner Queue & User etc so reference is not valid
Issue # 3 : Case trigger check below
Use this code :
If this answers your question mark Best Answer it as solution and then hit Like!