0

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(){
        Test=true;
        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){
            if(mt.name==meets)
                meetn=mt;           
       }

        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
         if(attndWrap.size()>0){
             renderTable = true;
        }    
    } 


    // Used to get attendeees not related to any meeting   
    public void importAttendee(){
        imp=true;
        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;
                    atn4.Meeting__c=meetn.id;
                    atnds.add(atn4);
            }
        }
        upsert atnds;
        myAttendees();
        renderNew=true;
    }


    /* 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) {
            this.attn1=ab;
            this.selected1=false;
        }

    }   
}

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:selectList>
        </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>

     <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}" >
        <tr>
            <th>Select</th>
            <th>Attendee Name</th>
            <th>E-mail</th>
            <th>Country</th>
            <th>Status</th>
        </tr>

     <apex:repeat value="{!attndWrap}" var="mr"  >
         <tr>
             <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>
         </tr>
     </apex:repeat> 
     </table>
     </apex:outputPanel>

     <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:pageBlock> 


     <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}" >
        <tr>
            <th>Select</th>
            <th>Attendee Name</th>
            <th>E-mail</th>
            <th>Country</th>
            <th>Status</th>
        </tr>

     <apex:repeat value="{!attndWrap2}" var="mr1"  >
         <tr>
             <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>
         </tr>
     </apex:repeat> 
     </table>
     </apex:outputPanel>


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

 </apex:form>
</apex:page>

Error

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

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

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.