You need to sign in to do that
Don't have an account?
Flint Lockwood
Cannot Update Record Using StandardController Save Method
Hi,
I am trying to update an Account's name using the StandardController save method. For some reason the update is not happening. Here is my code:
public with sharing class UpdateAccountClass{ public ApexPages.StandardController s; public Account a {get; Set;} public UpdateAccountClass(ApexPages.StandardController stdCon){ s = stdCon; a = (Account)stdCon.getRecord(); a = [select id, Name from Account where Id =: a.Id]; } public PageReference SaveRecord(){ a.Name = 'Testing Testing'; PageReference p = null; try{ p = s.save(); }catch(Exception e){ system.debug(e.getMessage()); } return p; } }
Thank you in advance.
All Answers
Thanks,
Samba
Hi,
Please change your code as below:
public with sharing class UpdateAccountClass{
public ApexPages.StandardController s;
public Account a {get; Set;}
public UpdateAccountClass(ApexPages.StandardController stdCon){
s = stdCon;
a = (Account)s.getRecord();
}
public PageReference SaveRecord(){
PageReference p = null;
a.Name = 'Testing Testing';
p= s.save();
return p;
}
}
Please let me know if u have any problem on same and if this post helps u plz give KUDOS by click on star at left.
Thank you. This worked