You need to sign in to do that
Don't have an account?
Parteek Goyal 3
I want to add change owner button on account list view page
HI All
I want to add change owner button on account list view page but shows this error.
Null reference exception
I want to add change owner button on account list view page but shows this error.
Null reference exception
public class AccountController1 { public Account accounts{get;set;} private ApexPages.StandardSetController standardController; public AccountController1(ApexPages.StandardController controller) { } public AccountController1(ApexPages.StandardSetController standardController) { this.standardController = standardController; List<Account> selectedAccounts = (List<Account>) standardController.getSelected(); for(Account selectedAccount : selectedAccounts) { //if(selectedAccount.ownerid== null) selectedAccount.ownerid = selectedAccount.ownerid; //else if(selectedAccount.ownerid == 'Low') System.debug('selectownerid>>>'+selectedAccount.ownerid); // System.debug('selectownerid>>>'+selectedAccount.ownerid); // selectedAccount.ownerid = 'Medium'; /// else if(selectedAccount.ownerid == 'Medium') // selectedAccount.ownerid = 'High'; } } public PageReference updateAccount() { //update accounts; return standardController.save(); // Call StandardSetController 'save' method to update (optional, you can use your own DML) //return null; } } vd page <apex:page standardController="Account" extensions="AccountController1"> <apex:form > <apex:pageblock > <apex:pageblockbuttons > <apex:commandButton action="{!updateAccount}" value="Save"/> </apex:pageblockbuttons> <apex:pageblockSection > <apex:inputField value="{!accounts.OwnerId}"/> </apex:pageblockSection> </apex:pageblock> </apex:form> </apex:page>please help me
Use the following code.
Mark It as solution if this solves your problem
it gives a error
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.OwnerId
Class.AccountController1.<init>: line 18, column 1
We are using SObject so this error is not supposed to occur.
Can you paste your SOQL if you are using them in your actual code
I have run the code in my developer org and it is working fine.
Apex Class Visualforce Page
Try it in developer org and see if you have any issue.
If you are using same code in some other org and you are getting some error then we need to look into your profile.
Please try below controller.
Let us know if it helps.
show error in this
standardController.addFields();
please check this code again
Sorry My bad, Please try below code. Missed to pass list as parameter.
Let us know if it works.