<apex:page controller="MyController" tabStyle="Account" showChat="false">
<apex:form >
<apex:pageBlock title="Congratulations {!$User.FirstName}">
You belong to Account Name: <apex:inputField value="{!account.name}"/>
<apex:commandButton action="{!save}" value="save"/></apex:pageblock>
</apex:form>
</apex:page>
/* Apex class*/
public class MyController {
private final Account account;
public MyController() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
update account;
return null;
}
}
Unable to insert account name.any solution to get rid from below error:
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:page> in page fresh14
can anyone suggest the best solution. The main problem is at 'insert' option of public PageReference save() code
can anyone suugest with insert code
or
combination of insert and update code.
public Account account {get;set;}
public MyController() {
string accId = ApexPages.currentPage().getParameters().get('id');
if(accId != null)
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :accId ];
else account = new Account ();
}
public PageReference save() {
upsert account;
return null;
}