1

I get an error when i run the "Filtrer" method

common.apex.runtime.impl.ExecutionException: Invalid conversion from runtime type String to rubrique_analitique__c

here is my code

public class ListRubriqueAnaliticParPoste {

     public List<WrapperPosteRubriques> ListWrapper {get;set;}
     public String FiltrerParServ {get;set;}
     public String FiltrerPargrp {get;set;}
     public String FiltrerParmission {get;set;}
     public id idlignepaie {get;set;}
     public list<poste__c> ListesPostes {get;set;}


    public ListRubriqueAnaliticParPoste(){
        ListWrapper = new List<WrapperPosteRubriques>();
        ListesPostes = [select id,mission__c,name,matricule__c,SERV__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 limit 999];
              Set<ID> postesID = new SET<ID>();
        for(poste__c po: ListesPostes){
            postesID.add(po.id);
        }
        List<rubrique_analitique__c> listRubriques = [select id,contact__c,Poste__c,type__c,Heures__c from rubrique_analitique__c where poste__c IN:postesID]; 

        for(Poste__c po: ListesPostes){ 
           List<rubrique_analitique__c> ListesRubriquesParPost = new List<rubrique_analitique__c>();
            for(rubrique_analitique__c rb : listRubriques){
                if(rb.Poste__c == po.id){
                    ListesRubriquesParPost.add(rb);
                }
            }
            ListWrapper.add(new WrapperPosteRubriques(po,ListesRubriquesParPost));
            //posteRubriques.put(po,ListesRubriquesParPost);
        }
    }

    public List<SelectOption> getMissionItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('',''));
        List<poste__c> listespostesoptions = new List<poste__c>();      
       listespostesoptions = [select id,name,mission__c,matricule__c,SERV__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 limit 999];
        for(poste__c po:listespostesoptions){
            if(po.mission__c != '' && po.mission__c != null){
            options.add(new SelectOption(po.mission__c,po.mission__c));
            }
        }
        return options;
    }


    public pagereference Filter(){


        ListesPostes =chargerlstpc();
        Set<ID> postesID = new SET<ID>();
        for(poste__c po: ListesPostes){
            postesID.add(po.id);
        }
        List<rubrique_analitique__c> listRubriques = [select id,contact__c,Poste__c,type__c,Heures__c from rubrique_analitique__c where poste__c IN:postesID]; 

        for(Poste__c po: ListesPostes){ 
           List<rubrique_analitique__c> ListesRubriquesParPost = new List<rubrique_analitique__c>();
            for(rubrique_analitique__c rb : listRubriques){
                if(rb.Poste__c == po.id){
                    ListesRubriquesParPost.add(rb);
                }
            }
            ListWrapper.add(new WrapperPosteRubriques(po,ListesRubriquesParPost));
        }


        return null;
    }


    public list<poste__c> chargerlstpc(){ 

        list<poste__c> lpostes= new list<poste__c>();


            if(FiltrerParServ!=null && FiltrerParServ!=''  && FiltrerPargrp!=null && FiltrerPargrp!='' && FiltrerParmission !=null && FiltrerParmission != ''){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 and SERV__c =:FiltrerParServ and Groupe__c =:FiltrerPargrp  and mission__c =:FiltrerParmission limit 999];

            }else if( FiltrerParServ != null && FiltrerParServ !=''  && FiltrerPargrp != null && FiltrerPargrp !='' && (FiltrerParmission ==null || FiltrerParmission == '')){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 and SERV__c =:FiltrerParServ and Groupe__c =:FiltrerPargrp  limit 999];

            }else if(FiltrerParServ !=null && FiltrerParServ !='' && (FiltrerPargrp == null || FiltrerPargrp =='') && FiltrerParmission !=null && FiltrerParmission != ''){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 and SERV__c =:FiltrerParServ and mission__c =:FiltrerParmission limit 999];

            }else if(FiltrerParServ !=null && FiltrerParServ !='' && (FiltrerPargrp == null || FiltrerPargrp == '') && (FiltrerParmission ==null || FiltrerParmission == '')){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016  and SERV__c =:FiltrerParServ limit 999];

            }else if((FiltrerParServ ==null || FiltrerParServ =='') &&  FiltrerPargrp != null && FiltrerPargrp != '' && FiltrerParmission !=null && FiltrerParmission != ''){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 and Groupe__c =:FiltrerPargrp and mission__c =:FiltrerParmission limit 999];

            }else if((FiltrerParServ ==null || FiltrerParServ =='') &&  FiltrerPargrp != null && FiltrerPargrp != '' && (FiltrerParmission ==null || FiltrerParmission == '')){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 and Groupe__c =:FiltrerPargrp limit 999];

            }else if((FiltrerParServ ==null || FiltrerParServ =='') &&  (FiltrerPargrp == null || FiltrerPargrp == '') && FiltrerParmission !=null && FiltrerParmission != ''){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 and mission__c =:FiltrerParmission limit 999];

            }else if((FiltrerParServ == null || FiltrerParServ =='') &&  (FiltrerPargrp == null || FiltrerPargrp == '') && (FiltrerParmission ==null || FiltrerParmission == '')){
        lpostes = [select id,name,matricule__c,SERV__c,mission__c,Groupe__c,Annee_actuelleR__r.Name from Poste__c where calendar_year(CreatedDate) =: 2016 limit 999];

            }

        return lpostes;
    }



        public class WrapperPosteRubriques{
     //   Public Map<poste__c,List<Rubrique__c>> posteRubriques {get;set;}
        public List<rubrique_analitique__c> listRubriques {get;set;}
        public String test {get;set;}
        public Poste__c poste  {get;set;}
        public rubrique_analitique__c RubPrincipale {get;set;}
        public rubrique_analitique__c RubType1 {get;set;}
        public rubrique_analitique__c RubType2 {get;set;}
        public rubrique_analitique__c RubType3 {get;set;}
        public rubrique_analitique__c RubType4 {get;set;}
        public WrapperPosteRubriques(Poste__c poste,List<rubrique_analitique__c> listRubriques){

            this.poste = poste;
            this.listRubriques = listRubriques;
            for(rubrique_analitique__c  rb : listRubriques){
                if(rb.type__c == 'principale'){
                    test = 'B008 yes';
                    RubPrincipale = rb;
                }else if(rb.type__c == 'type1'){
                    RubType1 = rb;

                }else if(rb.type__c == 'type2'){
                    RubType2 = rb;

                }else if(rb.type__c == 'type3'){
                   RubType3 = rb;   
                }else if(rb.type__c == 'type4'){
                   RubType4 = rb;   
                }
            }            

        }
    }     

}

the error i get: enter image description here

2
  • Check your Visualforce too; for example binding an input field to value="{!RubType1}" (which is a rubrique_analitique__c ) rather than value="{!RubType1.Type__c}" (which is a String) might result in that error.
    – Keith C
    Apr 22, 2016 at 8:00
  • yes, @Keith C that 's it you are right , i am displaying the rubrique_analitique__c object as outputText rather than a specific field (ex hours) Apr 22, 2016 at 8:06

0

You must log in to answer this question.

Browse other questions tagged .