function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sid_devsid_dev 

recordSetVar with Lookup field

Hi,

 

I am trying to fetch the selected records using list button in a page which also has a lookup field to add the account owner. How can I fetch the selected records into a List<accounts> and also the value from input field that I can update.I am getting the error 'Attempt to de-reference a null object'.

 

Currently I am fetching the vaue from the querystring from the onclick(javascript) of the list button which I don't want to do. I would appreciate if you could help me.

 

<apex:page standardController="Account" recordSetVar="accounts" extensions="UpdateOwner" tabstyle="Account" >
    <apex:form >
      <apex:pageBlock title="Update Owner">
          <apex:pageBlockSection >
              <apex:inputField value="{!Account.ownerId}" id="Owner" />   

              <apex:param value="{!$CurrentPage.parameters.array}"/>
          </apex:pageBlockSection>
          <center><apex:CommandButton action="{!save}" value="Update"/></center>        
      </apex:pageBlock>         
  </apex:form>

 </apex:page>

 

//custom controller
public class BulkUpdateOwner
{
    private Account owner ;
    private List<string> accId;
    public ApexPages.standardSetController controller {get; set;}
   
       
    //get the standard controller and the parameters
    public BulkUpdateOwner(ApexPages.StandardSetController controller)
    {                               
        try
        {
            this.controller = controller;
            //List<Account> myOppList = (List<Account>)controller.getSelected();
            this.accId = System.currentPageReference().getParameters().get('array').split(',');              
        }      
        catch(System.Exception e)
        {
            system.debug(e);
        }       
    }
  
    public Account getAccount()
    {  
          this.owner = (Account)controller.getRecord();
          return owner;   
    }        
   
    public void setAccount(Account owner) 
    {       
        this.owner=owner;   
    }   
    
    public PageReference save()
    {                          
        List<Account> a =[Select a.Id, a.OwnerId FROM Account a WHERE a.id in :this.accId];   
        for(Account acc :a)
        {       
            acc.OwnerId = this.Owner.OwnerId;
        }           
        update a;       
        return ApexPages.currentPage();
    }
}

 

 

Thanks,

Sid_Dev