You need to sign in to do that
Don't have an account?
sheila srivatsav
database.upsert issue
I have a custom button defined in the page layout of account
when I click this button, enter the account number then it should save back to object
Can any one please let me know?
Thanks
sheila
when I click this button, enter the account number then it should save back to object
public with sharing class InitiateApprovalController { public Account acc{get;set;} public string accid; public InitiateApprovalController(ApexPages.StandardController stdcontroller) { accid=ApexPages.CurrentPage().getParameters().get('id'); this.acc=(Account)stdcontroller.getRecord(); acc=[select ID,Name,AccountNumber from Account where ID =:acc.ID]; } public InitiateApprovalController() { acc=new Account(); } public PageReference customsave() { try{ system.debug('acc before update ='+acc); database.Upsert(acc); PageReference pr=new PageReference('/'+acc.Id); return pr; } catch( Exception e ){ ApexPages.addMessages(e); return Null; } } } <apex:page standardController="Account" extensions="InitiateApprovalController"> <apex:form > <apex:pageBlock mode="edit"> <apex:pageBlockSection title="Approvers" id="ApproversId"> <apex:inputField Id="name" html-placeholder="Account Name.." value="{!Account.Name}" /> <apex:inputField Id="accnumber" html-placeholder="Account Number.." value="{!Account.AccountNumber}" /> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom" html-align="right"> <apex:commandButton id="customsave1" value="save" action="{!customsave}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>I am surprised because I am using Database.Upsert but still it is not saving to object
Can any one please let me know?
Thanks
sheila
I trust you are doing very well.
The issue is that you are using value="{!Account.Name}" and value="{!Account.AccountNumber}" in inputField in Visualforce. Whereas, in extension controller, you are using public Account acc{get;set;} and upserting acc. But, there is no acc in visualforce.
Update your code:
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
I trust you are doing very well.
The issue is that you are using value="{!Account.Name}" and value="{!Account.AccountNumber}" in inputField in Visualforce. Whereas, in extension controller, you are using public Account acc{get;set;} and upserting acc. But, there is no acc in visualforce.
Update your code:
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
It was gr8 to see your post,
My mistake .
The changes you said are working.
thanks once again.
sheila