You need to sign in to do that
Don't have an account?
John Neilan
VF Controller Error
Hello,
I have a controller below on a VF page off the Opportunity object. All I am trying to do is pre-populate a custom field (RENEW_Date_Updated__c) with today's date. When I try to save my VF page, I get the error below. Does anyone know how I can fix this? Thanks.
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Error is in expression '{!save}' in component <apex:commandButton> in page renewprogupdate: Class.RenewalOppProg.save: line 18, column 1
Class.RenewalOppProg.save: line 18, column 1
I have a controller below on a VF page off the Opportunity object. All I am trying to do is pre-populate a custom field (RENEW_Date_Updated__c) with today's date. When I try to save my VF page, I get the error below. Does anyone know how I can fix this? Thanks.
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Error is in expression '{!save}' in component <apex:commandButton> in page renewprogupdate: Class.RenewalOppProg.save: line 18, column 1
Class.RenewalOppProg.save: line 18, column 1
public class RenewalOppProg{ public List<Opportunity> opps {get; set;} private final Opportunity oppty; public RenewalOppProg(ApexPages.StandardController myController) { opps = new List<Opportunity>(); oppty = (Opportunity)myController.getrecord(); } public Opportunity opp2 = new Opportunity(); public void OppProg(){ opp2.RENEW_Date_Updated__c = Date.Today(); opps.add(opp2); } public PageReference save() { update opps; { PageReference RetPage = new PageReference('/apex/RenewProgView?id=' + opps[0].id); RetPage.setRedirect(true); return RetPage; } } }
All Answers
Hope that helps.
public class OppRenewController {
public Opportunity opp {get; set;}
public OppRenewController(ApexPages.StandardController myController) {
this.opp = myController.getRecord();
//if you are instead passing in an opp ID, lookup the opp
//you can even check if opp is null and then look for the ID on the params as well
//may want to wrap in try/catch in case nothing is found/passed in, etc.
String oppId = ApexPages.CurrentPage().getParameters().get('oppid');
this.opp = [SELECT ID, RENEW_Date_Updated__c FROM Opportunity WHERE ID = :oppId];
}
public pageReference save() {
//do custom save stuff
this.opp.RENEW_Date_Updated__c = Date.Today();
update this.opp;
}
}
Naturally you'll want to wrap the necessary try/catch around the opportunity ID part to ensure you have an ID, etc. but this should get you the gist...
There may be errros in this code as this is off the top of my head and I don't have access to my editor at the moment :)