You need to sign in to do that
Don't have an account?
John Neilan
Trigger Question
Hi Everyone,
This is probably a pretty easy answer, but I'm just drawig a blank. The code snippet below is designed to clone an Opportunity. The RecClone class is set up to pull in all createable fields for the clone, since the clone function that Apex offers only pulls those fields that you specifically name. The clone works fine, but I want to overwrite some of the clone fields with other values. How do I pull the values from Line 3 and replace them with the values from lines 4 - 10?
This is probably a pretty easy answer, but I'm just drawig a blank. The code snippet below is designed to clone an Opportunity. The RecClone class is set up to pull in all createable fields for the clone, since the clone function that Apex offers only pulls those fields that you specifically name. The clone works fine, but I want to overwrite some of the clone fields with other values. How do I pull the values from Line 3 and replace them with the values from lines 4 - 10?
String soql = RecClone.getCreatableFieldsSOQL('Opportunity','Id =: OppId'); Opportunity opp = (Opportunity)Database.query(soql); Opportunity opp2 = opp.clone(false, true); opp2.CloseDate = opp.Renewal_Date_Next__c; opp2.OwnerId = amh.Assigned_Account_Manager__c; opp2.Term__c = 12; opp2.Renewal__c = 'Yes'; opp2.Effective_Date__c = opp.Renewal_Date_Next__c; opp2.Renewed_Opportunity__c = opp.Id; Opp2.StageName = 'Call Scheduled'; insert opp2;
You might have to get this field from Trigger.newmap (Opportunity opp2 = Trigger.newmap.get(opp.id))
All Answers
it seems to me that code should be working fine...
execution of AfterUpdate caused by: System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Opportunity.Renewal_Date_Next__c: Class.ClassAccountManagerHandoffNotes.addNotes: line 4, column 1
ClassAccountManagerHandoffNotes
go to line 4, and add Renewel_Date_Next__c to the select statement against Opportunity.
ClassAccountManagerHandoffNotes" apex class.
You might have to get this field from Trigger.newmap (Opportunity opp2 = Trigger.newmap.get(opp.id))