You need to sign in to do that
Don't have an account?
chandan kumar 99
i have a create custom controller to show list of account and also visual force page click button to New Account then show popup window and fill value then save value
my code is :-
public class AccountDetailCtr{
public Account account{get; set;}
public List<Account> getlstAcc(){
List<Account> accounts = new List<Account>();
accounts=[Select id,name,AnnualRevenue,rating,Industry,Phone,ShippingAddress,AccountNumber from account ];
if(accounts!=null && accounts.size()>0)
return accounts ;
else
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'No account record found'));
return accounts ;
}
public PageReference save() {
update account;
pagereference p = page.SecondPageSLDS;
p.setRedirect(true);
p.getParameters().put('id', account.Id);
return p;
}
}
when save button press then following error show
Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page secondpageslds: Class.AccountDetailCtr.save: line 16, column 1
An unexpected error has occurred. Your development organization has been notified.
public class AccountDetailCtr{
public Account account{get; set;}
public List<Account> getlstAcc(){
List<Account> accounts = new List<Account>();
accounts=[Select id,name,AnnualRevenue,rating,Industry,Phone,ShippingAddress,AccountNumber from account ];
if(accounts!=null && accounts.size()>0)
return accounts ;
else
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info,'No account record found'));
return accounts ;
}
public PageReference save() {
update account;
pagereference p = page.SecondPageSLDS;
p.setRedirect(true);
p.getParameters().put('id', account.Id);
return p;
}
}
when save button press then following error show
Attempt to de-reference a null object
Error is in expression '{!save}' in component <apex:commandButton> in page secondpageslds: Class.AccountDetailCtr.save: line 16, column 1
An unexpected error has occurred. Your development organization has been notified.
The error is coming because you are assigning null values at the time of updating account record.Here ccount is having all fields balnk.
If you want update account we need Id of the record.
update account;
Please let me know why you have written below lines :
pagereference p = page.SecondPageSLDS;
p.setRedirect(true);
p.getParameters().put('id', account.Id);
return p;
}
Hope It helps you.
Thanks
vara prasad