I have a use-case where I have to fetch all the meetings available. On selection of one meeting, I have to show the corresponding Attendees. Then I should give an option to display all unrelated attendees and map selected ones to the meeting. I have built my controller according.

But I am getting an error while mapping an attendee to the meeting. Attendee has a lookup field for Meeting. I have written comments accordingly. Please help

public class EventManagement{
    public string selected{get;set;}
    public List<Selectoption> options{get;set;}
    public string meets{get;set;}
    public List<Selectoption> opt{get;set;}
    public List<Meeting__c> meeting{get;set;}
    public boolean Test{get;set;}
    public boolean renderTable{get;set;}
    public boolean renderNew{get;set;}
    public boolean imp{get;set;}
    public List<AttendeesWrapper> attndWrap{get;set;}
    public List<AttendeesWrapper> attndWrap2{get;set;}
    public List<AttendeesWrapper> mapWrap{get;set;}
    public List<Attendee__c> attList{get;set;}
    public Meeting__c meetn {get;set;}
    public List<Attendee__c> attList1{get;set;}

    // Used to fetch list of meetings
    public EventManagement(){
        opt=new List<Selectoption>();
        meeting=new List<Meeting__c>();
        meeting=[select ID,Name from Meeting__c];

        opt.add(new Selectoption('','----SELECT----'));   
        for(Meeting__c mee : meeting){ 
            opt.add(new selectoption(mee.ID,mee.Name));

    // Used to fetch list of attendees related to a meeting  
    public void myAttendees(){
       for(Meeting__c mt : meeting){

        attList=new List<Attendee__c>();
        attList=[Select Id,Name,Attendee_Email__c,Country__c,Status__c from Attendee__c where  Meeting__c=:meets];

        // Creating a wrapper list for attendees   
        attndWrap = new List<AttendeesWrapper>();

        for(Attendee__c attnd : attList){
          attndWrap.add(new AttendeesWrapper(attnd));

        //used for showing the data at VF page
             renderTable = true;

    // Used to get attendeees not related to any meeting   
    public void importAttendee(){
        List<Attendee__c> attList1 = new List<Attendee__c>();

        attList1=[select id,name,Mobile__c,Country__c,Attendee_Email__c, Attendee__c.Meeting__c from Attendee__c where Meeting__c=null];

        attndWrap2 = new List<AttendeesWrapper>();
            for(Attendee__c wa : attList1){
              attndWrap2.add(new AttendeesWrapper(wa));

    //Used to map the selected attendee to the meeting      
    public void mapAttendee(){
        List<Attendee__c> atnds = new List<Attendee__c>();

        for(AttendeesWrapper atL : attndWrap2){

            if(atL.selected1 == true){
            //I am getting an de-referencing null object exception next line
                Attendee__c atn4 = atL.attn1;
        upsert atnds;

    /* Wrapper Class */
    //Used for adding a checkbox    
    public class AttendeesWrapper {
        public Attendee__c attn1 {get;set;}
        public boolean selected1{get;set;}

        public AttendeesWrapper(Attendee__c ab) {


VF page :

<apex:page controller="EventManagement" > 
 <apex:form >    
    <apex:pageBlock id="M1">
        <apex:pageBlockSection title="Name of Meetings" rendered="{!Test}">
        <apex:pageBlockSectionItem >
        <apex:selectList value="{!meets}" size="1" multiselect="false">
        <apex:outputLabel >Name of Meetings</apex:outputLabel>
        <apex:selectOptions value="{!opt}"></apex:selectOptions>
        <apex:actionSupport event="onchange" action="{!myAttendees}"/>

     <apex:outputPanel id="thePanel1" layout="none" rendered="{!renderTable}">
       <table align="centre" cellspacing="10px" cellpadding="20px" border="2px solid black" bgcolor="pink" id="t1" rendered="{!renderTable}" >
            <th>Attendee Name</th>

     <apex:repeat value="{!attndWrap}" var="mr"  >
             <td><apex:inputCheckbox value="{!mr.selected1}"/></td>   
             <td><apex:inputField value="{!mr.attn1.name}"></apex:inputField></td>
             <td><apex:inputField value="{!mr.attn1.Attendee_Email__c}"></apex:inputField></td>
             <td><apex:inputField value="{!mr.attn1.Country__c}"></apex:inputField></td>
              <td><apex:inputField value="{!mr.attn1.Status__c}"></apex:inputField></td>

     <apex:pageBlock rendered="{!renderTable}">
         <apex:commandButton value="Update" action="{!updateAttendee}"/>
         <apex:commandButton value="Add" action="{!newAttendee}"/>
         <apex:commandButton value="Upsert" action="{!upsertAttendee}"/>
         <apex:commandButton value="Delete" action="{!deleteAttendee}"/>
         <apex:commandButton value="Import" action="{!ImportAttendee}"/>

     <apex:outputPanel id="thePanel" layout="none" rendered="{!imp}">
       <table align="centre" cellspacing="10px" cellpadding="20px" border="2px solid black" bgcolor="pink" id="t3" rendered="{!imp}" >
            <th>Attendee Name</th>

     <apex:repeat value="{!attndWrap2}" var="mr1"  >
             <td><apex:inputCheckbox value="{!mr1.selected1}"/></td>   
             <td><apex:inputField value="{!mr1.attn1.name}"></apex:inputField></td>
             <td><apex:inputField value="{!mr1.attn1.Attendee_Email__c}"></apex:inputField></td>
             <td><apex:inputField value="{!mr1.attn1.Country__c}"></apex:inputField></td>
              <td><apex:inputField value="{!mr1.attn1.Mobile__c}"></apex:inputField></td>

     <apex:pageBlock rendered="{!imp}">
         <apex:commandButton value="Map" action="{!mapAttendee}"/>



Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!mapAttendee}' in component <apex:commandButton> in page event_management: Class.EventManagement.mapAttendee: line 82, column 1

  • 3
    Can you edit your question to include the exact text of the error? Feb 13 '17 at 18:29

Since you have created inputField to capture Attendee so you have to use Attendee__c.Id

Second thing, inputField works with SObject, it will not work with instance of wrapper class, so this line will not work with inputField

<td><apex:inputField value="{!mr.attn1.name}"></apex:inputField></td>

And there are lot of issues in the code the way you are structuring the logic and think about proper naming conversion.

Like in this line where Meeting__c should expect Ids where as you are passing List of Names as String:

 attList=[Select Id,Name,Attendee_Email__c,Country__c,Status__c from Attendee__c where  Meeting__c=:meets];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.