You need to sign in to do that
Don't have an account?
John Neilan
Trigger Not Firing
Hello,
I created the trigger below to fire when a custom object is created to create a clone of the Opportunity related to the custom object. I added a system.debug line on line 19, and it shows that the variable "amh2.Opportunity__r.Managed_Account_Transfer__c" is set to FALSE. However, this checkbox field on the Opportunity is set to TRUE. Does anyone know how to fix this? Thanks.
I created the trigger below to fire when a custom object is created to create a clone of the Opportunity related to the custom object. I added a system.debug line on line 19, and it shows that the variable "amh2.Opportunity__r.Managed_Account_Transfer__c" is set to FALSE. However, this checkbox field on the Opportunity is set to TRUE. Does anyone know how to fix this? Thanks.
public class ClassAccountManagerHandoffNotes { public void autoCreateRenewal1(Account_Manager_Handoff__c[] newAMH){ Map<String,String> oppMap = new Map<String,String>(); Set<Id> parentOpp = new Set<Id>(); FOR (Account_Manager_Handoff__c amh1 : newAMH) { parentOpp.add(amh1.Opportunity__c); Map<Id,Opportunity> oppMap2 = new Map<Id,Opportunity> ([SELECT Id FROM Opportunity WHERE Id IN :parentOpp]); FOR(Account_Manager_Handoff__c amh2 : newAMH){ system.debug('********AMH'+amh2.Assigned_Account_Manager__c+' '+amh2.Opportunity__r.Managed_Transfer__c); IF(oppMap2.containskey(amh2.Opportunity__c) && amh2.Assigned_Account_Manager__c != NULL && amh2.Opportunity__r.Managed_Transfer__c == TRUE){ Opportunity renewalOpp = amh2.Opportunity__r.clone(false); Opportunity clonedObj = renewalOpp.clone(false,true); clonedObj.Name = amh2.Opportunity__r.Acct_Name__c + ' - Renewal (' +amh2.Opportunity__r.Renewal_Date_Year__c + ')'; clonedObj.OwnerId = amh2.Assigned_Account_Manager__r.Id; clonedObj.StageName = 'Active Discussions'; clonedObj.CloseDate = amh2.Opportunity__r.Renewal_Date_Next__c; clonedObj.Amount = amh2.Opportunity__r.Amount; clonedObj.Effective_Date__c = amh2.Opportunity__r.Renewal_Date_Next__c; clonedObj.Renewal__c = 'Yes'; clonedObj.Renewed_Opportunity__c = amh2.Opportunity__r.Id; clonedObj.Probability = 5; insert clonedObj; } } } } }
Here you have missed querying Opportunity__c & Assigned_Account_Manager__c from Account_Manager_Handoff__c
Add these 2 fields as well in your SOQL at Line 19
All Answers
You may refer:
https://developer.salesforce.com/forums/ForumsMain?id=906F000000090YSIAY
execution of AfterInsert caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account_Manager_Handoff__c.Assigned_Account_Manager__c: Class.ClassAccountManagerHandoffNotes.autoCreateRenewal1: line 26, column 1
What did I do wrong? Thanks,
Here you have missed querying Opportunity__c & Assigned_Account_Manager__c from Account_Manager_Handoff__c
Add these 2 fields as well in your SOQL at Line 19
Below code will help you
That code works as well to get rid of any errors, however, the trigger is still not cloning the Opportunity. Any idea why that may be happening?