1

i get this error when i click on the Commandbutton Enregistrer, i debug the code and i realized that the error comes from the method Enregistrer what i do not know why ?

apex:

public class Comp_PilotageComptePM {
    public String CompteID {set;get;}
    public String RisqueAEnregistrer {set;get;}


    public Comp_PilotageComptePM(){

    }


    public  List<WrapperClass> ListWrapper;

    public List<WrapperClass> getListWrapper(){

        system.debug('CompteID = '+CompteID);
        List<WrapperClass> ListWrapper = new List<WrapperClass>();
        List<Risque__c> ListeRisques = [select Id,name,Critere__c,Date_Risque__c,Derniere_Alerte__c,Etat__c,Etat_Actions__c,idcritere__c,Idmapping__c,Libelle__c,
                                        Mapping__c,namepage__c, Priorite__c,Suivi_clientid__c,Suivi_client__c,Type__c,type_object__c from Risque__c where Suivi_client__c =:CompteID];
        system.debug('La taille des risques = '+ListeRisques.size());
        List<Action2__c> listeActions = [select Id,Acteur__c,name,Risque__c,Date_debut__c,Date_fin_prevue__c,Date_realisation__c,   Duree__c,Objectif__c,Pre_requis__c
                                         ,Priorite_risque__c,Resultat__c,Suivi_client__c,Type__c,Type_action__c,Type_risque__c from Action2__c where Risque__c IN (select Id from Risque__c where Suivi_client__c =:CompteID)];

        if(ListeRisques.size()>0){

            for(Risque__c rs: ListeRisques){
                List<Action2__c> al = new List<Action2__c>();
                for(Action2__c ac: listeActions){
                    if(ac.risque__c == rs.id){
                        Al.add(ac);
                    }
                }

               ListWrapper.add(new WrapperClass(rs,al)); 

            }
        }

        return ListWrapper;

    }

    public void setListWrapper(List<WrapperClass> ListWrapper){
            this.ListWrapper=ListWrapper;

    }


    public class WrapperClass{
        public List<Risque__c> risque {get;set;}
        public List<Action2__c> listActions {get;set;}

        public WrapperClass(Risque__c rs, List<Action2__c> lA){
            risque = new List<Risque__c>();
            risque.add(rs);
            listActions = lA;
        }
    }
    public pagereference Cloturer(){

        return null;
    }

    public pagereference Enregistrer(){
         system.debug('Le ID de l action 1 est = ');
        for(WrapperClass wr: ListWrapper){
            system.debug('Le ID de l action est = ');
            for(Risque__c rs: wr.risque){
                system.debug('Le ID de l action est = ');

                if(rs.id == RisqueAEnregistrer){
                    for(Action2__c ac:wr.listActions ){
                                            system.debug('Le ID de l action est = '+ac.id);

                    }
                    system.debug('Je suis la dans = '+rs.id);
                    system.debug('Name =  '+wr.listActions[0].Name);
                    system.debug('La taille de actions  = '+wr.listActions.size());
                    system.debug('Objectif 1=  '+wr.listActions[0].objectif__c);
                    system.debug('Date fin prevu=  '+wr.listActions[0].Date_fin_prevue__c);
                    update wr.listActions;
                }
            }
        }

        return null;
    }
}

visualforce (component) :

<apex:attribute name="IDdeCompte" description="Le ID de compte pour afficher les risques et les actions."
                  type="String" required="required" assignTo="{!CompteID}"/>
                      <apex:form >
    <apex:pageblock title="Les risques de les actions" id="test">

       <apex:repeat value="{!ListWrapper}" var="item">
           <div class="row">
               <div class="panel panel-default" id="aa{!item.risque[0].id}">
                   <div class="panel-heading " style="background: #ff0000; color: #fff;">
                       <h4 class="panel-title">{!item.risque[0].name}</h4>
                       </div>

                       <div class="panel-body">
                            <apex:pageBlock title="Le risque">  
                            <apex:pageBlockTable value="{!item.risque}" var="itemRisque" title="Le risque">
                              <apex:column >
                               <apex:facet name="header">Nom de risaque</apex:facet>
                                <apex:outputtext Value="{!itemRisque.name}" />
                                    </apex:column>
                            <apex:column >
                               <apex:facet name="header">Date de risque</apex:facet>

                                      <apex:outputText value="{0,date,dd'/'MM'/'yyyy}">
                             <apex:param Value="{!itemRisque.Date_Risque__c}" /> 
                            </apex:outputText>

                                    </apex:column>
                                <apex:column >
                                <apex:facet name="header">Dérnière alerte</apex:facet>
                                <apex:outputtext Value="{!itemRisque.Derniere_Alerte__c}" />
                                    </apex:column>
                                <apex:column >
                                <apex:facet name="header">Etat</apex:facet>
                                <apex:outputtext Value="{!itemRisque.Etat__c}" />
                                    </apex:column>
                                 <apex:column >
                                <apex:facet name="header">Type</apex:facet>
                                <apex:outputtext Value="{!itemRisque.Type__c}" />
                                    </apex:column>

                                <apex:column >
                                <apex:facet name="header">Cloturer</apex:facet>
                                <apex:Commandbutton Value="Cloturer" action="{!cloturer}" />
                                    </apex:column>




                          </apex:PageBlockTable>
                            </apex:pageBlock>
                            <apex:pageBlock title="Les actions">
                          <apex:pageBlockTable value="{!item.listActions}" var="itemAction" title="Les actions">
                          <apex:column >
                           <apex:facet name="header">Nom</apex:facet>
                            <apex:outputtext Value="{!itemAction.name}" />
                                </apex:column>

                              <apex:column >
                           <apex:facet name="header">Acteur</apex:facet>
                            <apex:OutputField Value="{!itemAction.Acteur__c}" />
                                </apex:column>

                        <apex:column >
                           <apex:facet name="header">Date début</apex:facet>
                            <apex:inputField Value="{!itemAction.Date_debut__c}" />
                                </apex:column>
                            <apex:column >
                           <apex:facet name="header">Date fin prévu</apex:facet>
                            <apex:inputField Value="{!itemAction.Date_fin_prevue__c}" />
                                </apex:column>
                            <apex:column >
                           <apex:facet name="header">Objectif</apex:facet>
                            <apex:inputField Value="{!itemAction.Objectif__c}" />
                                </apex:column>
                             <apex:column >
                           <apex:facet name="header">Resultat</apex:facet>
                            <apex:inputField Value="{!itemAction.Resultat__c}" />
                                </apex:column>

                             <apex:column >
                           <apex:facet name="header">Date de réalisation</apex:facet>
                            <apex:inputField Value="{!itemAction.Date_realisation__c}" />
                                </apex:column>




                          </apex:PageBlockTable>
                            </apex:pageBlock>           
                    </div>

              <div class="panel-footer"><apex:commandbutton value="Enregistrer" action="{!Enregistrer}" rerender="test">
               <apex:param name="Risque" value="{!item.Risque[0].id}" assignTo="{!RisqueAEnregistrer}"/>
                </apex:commandbutton>
                </div>

                            </div>

           </div>
       </apex:repeat>

EDIT: when i click on the button :

enter image description here

I get the following error :

enter image description here

no line specified on the log

enter image description here

  • Your error message should give you a line number. That is where you should be looking. – mkorman Jun 20 '16 at 11:04
  • Please give the screenshot of your error, so that it easy to identify that by which code you get an error. Or follow the steps, suggested by @mkorman – Anurag Bhardwaj Jun 20 '16 at 11:06
  • I edit the post – Merabti iBRAHIM Jun 20 '16 at 11:17
  • It is because of variable ListWrapper in for loop. – Anurag Bhardwaj Jun 20 '16 at 11:27
1

I think the problem is in below line

for(WrapperClass wr: ListWrapper)

If the ListWrapper is null, you might get this exception. If it has values or it's not empty(new List(); is fine atleast) then this error won't fire.

How it gets null value?

Since you have defined a separate getter for ListWrapper, Visualforce will find it correctly and will iterate through the list. But when you refer it from Apex, it refers to the variable where in the current scope.

In your getter, you have declared a new variable called ListWrapper as below

List<WrapperClass> ListWrapper = new List<WrapperClass>();

so when you polulating ListWrapper inside the getter, it'll not reflect in the class level ListWrapper variable. Change the above mentioned line so that it's not going to duplicate but initialize the same variable.

ListWrapper = new List<WrapperClass>();

Also make sure you have hit the setter (setListWrapper) before firing the commandButton action. If not, again the ListWrapper remains null and you'll get the same exception.

  • You areeeeee awesome, it works like a charm . – Merabti iBRAHIM Jun 20 '16 at 11:35
0

It is because of the first for loop in method Enregistrer(). ListWrapper is null and you perform loop operation on null list. I think your method setListWrapper() is not called before this method.

First you will verify that list is not null and size of list is greater than 0, then this error not generate.

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.