0

VF page:

<apex:page standardController="Position__c" extensions="PositionsForJobApplications" recordSetVar="lineitems" lightningStylesheets="true">
    <apex:form >
        <apex:pageBlock title = "POSITIONS">
            <apex:outputLabel>Status</apex:outputLabel>
            <apex:inputField value="{! PosStatus.Status__c }">
                <apex:actionSupport event="onchange" rerender="positionsList" action="{! filterPositions }"/>
            </apex:inputField>
            
            <apex:outputPanel id="positionsList">
                <apex:pageBlockTable value="{! Positions }" var="pos">
                    <apex:column headerValue="Positions name">
                        <apex:outputLink value="/{!URLFOR(pos.id)}">{!pos.name}</apex:outputLink>
                    </apex:column>  
                    <apex:column headerValue="Status">
                        <apex:inputField value="{! pos.Status__c }"/>                    
                    </apex:column> 
                    <apex:column headerValue="Open Date" value="{! pos.Open_date__c }"/>
                    <apex:column headerValue="Close Date" value="{! pos.Closed_date__c }"/>
                    <apex:column headerValue="Max Pay" value="{! pos.Max_pay__c }"/>
                    <apex:column headerValue="Min Pay" value="{! pos.Min_pay__c }"/>
                </apex:pageBlockTable>  
            </apex:outputPanel>
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:

public class PositionsForJobApplications {
    
    public Position__c Pos;
    public List<Position__c> Positions {get; set;}
    public Position__c PosStatus {get; set;}

    public PositionsForJobApplications() {
        PosStatus = new Position__c();
    }
    
    public PositionsForJobApplications(ApexPages.StandardSetController controller) {
        Positions = [SELECT Id, Name, Status__c, Open_date__c, Closed_date__c, Min_pay__c, Max_pay__c FROM Position__c];
    }
    
    public List<Position__c> getPositions() {
        Positions = [SELECT Id, Name, Status__c, Open_date__c, Closed_date__c, Min_pay__c, Max_pay__c FROM Position__c];
        return Positions;
    }
    
    public void filterPositions() {
        Positions = [SELECT Id, Name, Status__c, Open_date__c, Closed_date__c, Min_pay__c, Max_pay__c FROM Position__c
                    WHERE Status__c =: PosStatus.Status__c];
    }
    
    public PageReference save() {
        update Positions;
        return null;
    }
   
}

I have next error:

Attempt to de-reference a null object

enter image description here

1
  • 1
    Hi and welcome to SFSE. Please edit the question to replace the screenshots with the code text instead. The question editor has help that explains the markdown you need.
    – Phil W
    Aug 14, 2022 at 10:50

1 Answer 1

1

When you use this pattern in the page:

<apex:page standardController= ... extensions=... recordSetVar=...

the constructor that is invoked is always this one:

public ControllerClassName(ApexPages.StandardSetController ssc) {

which in your code does not initialise PosStatus, hence the exception.

Adding this:

PosStatus = new Position__c();

to that constructor will fix that problem.

1
  • Yes, it is work! Thank you! Aug 14, 2022 at 13:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .