You need to sign in to do that
Don't have an account?
Ben Wild 8
Error: Id not specified in an update call
I have a custom object called Opportunity_Forecast__c that sits as a child object below Opportunity. I created a custom visualforce page for editing and creating new Opportunity_Forecast__c records. The reason for this was the navigation butotns on the standard edit page took me back to the wrong page. Editing is working as expected. I am however having issues with creating new forecasts, I get the error Error:
Id not specified in an update call when saving. My code is as below;
VF Page:
Any ideas?
Id not specified in an update call when saving. My code is as below;
VF Page:
<apex:page standardController="Opportunity_Forecast__c" extensions="createController"> <apex:form > <apex:pageBlock title="Forecast" mode="Edit"> <apex:pageBlockButtons > <apex:commandButton action="{!saveAndReturn}" value="Save"/> <apex:commandButton action="{!cancelAndReturn}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageMessages /> <apex:pageBlockSection title="Forecast Detail" columns="1"> <apex:inputField value="{!Opportunity_Forecast__c.Value__c}"/> <apex:inputField value="{!Opportunity_Forecast__c.Forecast_Category__c}"/> <apex:inputField value="{!Opportunity_Forecast__c.Forecast_Period__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>Controller Extension:
public with sharing class createController { Opportunity_Forecast__c oppf {get;set;} private ApexPages.StandardController stdController; public createController(ApexPages.StandardController stdController) { this.stdController = stdController; Opportunity_Forecast__c oppf = (Opportunity_Forecast__c) stdController.getRecord(); Map<String, String> m = ApexPages.currentPage().getParameters(); oppf.Opportunity__c = (Id) m.get('oppId'); } public PageReference cancelAndReturn() { PageReference cancel = stdController.cancel(); cancel.setRedirect(true); return cancel; } public PageReference saveAndReturn() { try{ insert oppf; PageReference save = stdController.cancel(); stdController.save(); save.setRedirect(true); return save; } catch(DMLException ex){ ApexPages.addMessages(ex); return null; } } }
Any ideas?
Hi Ben,
Please let me know In try block, you are updating or inserting new record .
If you are updating record then use :
try{
insert oppf; // for inserting
update oppf // for updating the record you need record id.
And One more thing please put some debug logs for below code and check expected values or coming or not.
Map<String, String> m = ApexPages.currentPage().getParameters();
system.debug('mmmmm'+m);
oppf.Opportunity__c = (Id) m.get('oppId');
system.debug('oppf.Opportunity__c : '+oppf.Opportunity__c);
Hope it helps you.
Thanks
Varaprasad
How are you launching your Visualforce page to create these new Opp Forecasts? I see you are grabbing a URL parameter "OppId" - from somewhere; how is that coming about? -- I don't nesessarily think it is connected to the error message, but it would be useful to know.
You are definitly making an Insert call at line 22... so all I can think is that inserting oppf is causing a chained event (such as a Trigger or Process Builder flow) that is then failing to complete an update of it's own - and the error message is bubbling all the way back up to your try/catch.
Are there any other automations on insert of Opportunity_Forecast you can examine? If OppId was coming in blank (which I might suspect) that could be causing an attempted trigger updating/upserting the associated Opportunity to fail with that message.
I do have other automations running, these Opportunity_Forecast__c objects are also created automatically when the opportunity reaches a certain percentage. The edit/create screen I am working on is for whena user wants to manually override what the system has created (I have a manual override checkbox).
this should bypass page level validation and fire your method