You need to sign in to do that
Don't have an account?
Mayank Deshpande 22
Not able to save the record in visualforce page , kindly suggest whats wrong on code
Apex Code = ublic with sharing class Saveaccountdetail {
Public Account Account {get;set;}
Public Account Accts {get;set;}
Public Saveaccountdetail (){
Id id= ApexPages.currentPage().getParameters().get('id');
Accts = (id == null)? new Account() : [SELECT Name, Phone, Industry FROM Account WHERE Id = :id];
}
Public PageReference Save()
{try
{
insert (Accts);
}
catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
return (redirectSuccess);
}
}
Visual Force Page
<apex:page controller="Saveaccountdetail" tabStyle="Account" > <apex:form > <apex:pageBlock title="New Account"> <apex:pageBlockSection > <apex:inputField value="{!Account.name}" /> <apex:inputField value="{!Account.Industry}" /> <apex:inputField value="{!Account.Phone}" /> </apex:pageBlockSection> <apex:commandButton value="Save" action="{!Save}"/> </apex:pageBlock> </apex:form> </apex:page>
Public Account Account {get;set;}
Public Account Accts {get;set;}
Public Saveaccountdetail (){
Id id= ApexPages.currentPage().getParameters().get('id');
Accts = (id == null)? new Account() : [SELECT Name, Phone, Industry FROM Account WHERE Id = :id];
}
Public PageReference Save()
{try
{
insert (Accts);
}
catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
return (redirectSuccess);
}
}
Visual Force Page
<apex:page controller="Saveaccountdetail" tabStyle="Account" > <apex:form > <apex:pageBlock title="New Account"> <apex:pageBlockSection > <apex:inputField value="{!Account.name}" /> <apex:inputField value="{!Account.Industry}" /> <apex:inputField value="{!Account.Phone}" /> </apex:pageBlockSection> <apex:commandButton value="Save" action="{!Save}"/> </apex:pageBlock> </apex:form> </apex:page>
controller : * use Accts in PageReference redirectSuccess
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
http://sfdcmonkey.com (http://sfdcmonkey.com )
All Answers
controller : * use Accts in PageReference redirectSuccess
i hope it helps you.
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
http://sfdcmonkey.com (http://sfdcmonkey.com )
Please check code :
Hope this helps you.
Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
You have taken "Accts" as getter setter variable in class but used standard "Account" as a variable on the page that's why you are not able to save your record. So please modify your code as follows:
Class:
public with sharing class Saveaccountdetail {
Public Account Account {get;set;}
Public Account Accts {get;set;}
Public Saveaccountdetail (){
Id id= ApexPages.currentPage().getParameters().get('id');
Accts = (id == null)? new Account() : [SELECT Name, Phone, Industry FROM Account WHERE Id = :id];
}
Public PageReference Save() {
try {
insert (Accts);
}
catch(System.DMLException e) {
ApexPages.addMessages(e);
return null;
}
PageReference redirectSuccess = new PageReference('/' + Accts.Id);
return (redirectSuccess);
}
}
Page:
<apex:page controller="Saveaccountdetail" tabStyle="Account" >
<apex:form >
<apex:pageBlock title="New Account">
<apex:pageBlockSection >
<apex:inputField value="{!Accts.name}" />
<apex:inputField value="{!Accts.Industry}" />
<apex:inputField value="{!Accts.Phone}" />
</apex:pageBlockSection>
<apex:commandButton value="Save" action="{!Save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Please mark the answer as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.
now code is working fine