+ Start a Discussion
Mick ManMick Man 

Apex + visualforce

I want to calculate the Nombre__c * Quantite__c, what should I do? please help me
public class OdtDetailController2 
    {

       
         public list<wrapperclass> Jonintwrapper{get;set;}
         public list<wrapperclass> Odtwrapper{get;set;}
         
         public OdtDetailController2(ApexPages.StandardController controller) 
             {
                 list<Ordre_Travail__c> OrdreTravail = [SELECT id, name, Date__c, Produit__c, Nombre__c FROM Ordre_Travail__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                 list<JointMatProd__c> Jointure = [SELECT id, MatierePremiere__c, Quantite__c FROM JointMatProd__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
             
                 Odtwrapper = new list<wrapperclass>();
                 for(Ordre_Travail__c Odt: OrdreTravail)
                     {
                        Odtwrapper.add(new wrapperclass(Odt));
                     }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
                        Jonintwrapper.add(new wrapperclass(Joint));
                     }
              }
    
              public class wrapperclass
                  {
                       public Ordre_Travail__c ODT{get;set;}
                       public JointMatProd__c JOINT{get;set;}
                       
                       public wrapperclass(Ordre_Travail__c OrdreTravail) 
                           {
                                this.ODT = (OrdreTravail);
                           }
                           
                       public wrapperclass(JointMatProd__c Joint) 
                           {
                                this.JOINT = (Joint);
                           }
                  }
    }

 
Best Answer chosen by Mick Man
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Micky Andriamiarantsoa:

Try this code:
 
public class OdtDetailController2 
    {

       
         public list<wrapperclass> Jonintwrapper{get;set;}
         public list<wrapperclass> Odtwrapper{get;set;}
        Pubic Double TotalNombre=0.0;
        Public Double TotalQuantite=0.0;
       Public Double Total;
       
         
         public OdtDetailController2(ApexPages.StandardController controller) 
             {
                 list<Ordre_Travail__c> OrdreTravail = [SELECT id, name, Date__c, Produit__c, Nombre__c FROM Ordre_Travail__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                 list<JointMatProd__c> Jointure = [SELECT id, MatierePremiere__c, Quantite__c FROM JointMatProd__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                
                 Odtwrapper = new list<wrapperclass>();
                 for(Ordre_Travail__c Odt: OrdreTravail)
                     {
                        Odtwrapper.add(new wrapperclass(Odt));
                         if(odt.Nombre__c!=Null){
                             TotalNombre+=odt.Nombre__c;

                        } 
                     }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
						if(Joint.Quantite__c==Null) // Checking! In case of null make it to 0 zero value so code wont break, and assuming Quantite__c is a numeric value
						Joint.Quantite__c=0; 
                        Jonintwrapper.add(new wrapperclass(Joint,Decimal.ValueOf(Joint.Quantite__c*TotalNombre)));
                        
                     }
                       

              }
    
              public class wrapperclass
                  {
                       public Ordre_Travail__c ODT{get;set;}
                       public JointMatProd__c JOINT{get;set;}
					   Public Decimal Total{get;set;}
                       
                       public wrapperclass(Ordre_Travail__c OrdreTravail) 
                           {
                                this.ODT = (OrdreTravail);
                           }
                           
                       public wrapperclass(JointMatProd__c Joint,Decimal Total) 
                           {
                                this.JOINT = (Joint);
								this.Total=Total;
                           }
                  }
    }


Created an other parameter called Total and an other constructore which takes Joint instance and Total value to assign it back to its variables. 
Hope it helps.

Thanks,
Balaji

All Answers

Suneel#8Suneel#8
On what criteria you want to do multiplication Nombre__c * Quantite__c? Where do you store the result from the multiplication?How Ordre_Travail__c and JointMatProd__c are related to?Please explain in detail,so that we can help
Mick ManMick Man
thank you for your answer Suneel#8! Each product needs Type single or multiple raw material and every matter has its first amount ie quantity per product, the number is the number of product so I want the amount of one or raw materials for the total product
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Micky Andriamiarantsoa:


  Were you looking for this?

(sum of all Nombre__c * sum of all Quantite__c) ??

If so, below code will help:
 
public class OdtDetailController2 
    {

       
         public list<wrapperclass> Jonintwrapper{get;set;}
         public list<wrapperclass> Odtwrapper{get;set;}
        Pubic Double TotalNombre=0.0;
        Public Double TotalQuantite=0.0;
       Public Double Total;
       
         
         public OdtDetailController2(ApexPages.StandardController controller) 
             {
                 list<Ordre_Travail__c> OrdreTravail = [SELECT id, name, Date__c, Produit__c, Nombre__c FROM Ordre_Travail__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                 list<JointMatProd__c> Jointure = [SELECT id, MatierePremiere__c, Quantite__c FROM JointMatProd__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                
                 Odtwrapper = new list<wrapperclass>();
                 for(Ordre_Travail__c Odt: OrdreTravail)
                     {
                        Odtwrapper.add(new wrapperclass(Odt));
                         if(odt.Nombre__c!=Null){
                             TotalNombre+=odt.Nombre__c;

                        } 
                     }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
                        Jonintwrapper.add(new wrapperclass(Joint));
                        if(Joint.Nombre__c!=Null){
                             TotalQuantite+=Joint.Quantite__c;

                        } 

                     }
                        Total=TotalQuantite*TotalNombre;

              }
    
              public class wrapperclass
                  {
                       public Ordre_Travail__c ODT{get;set;}
                       public JointMatProd__c JOINT{get;set;}
                       
                       public wrapperclass(Ordre_Travail__c OrdreTravail) 
                           {
                                this.ODT = (OrdreTravail);
                           }
                           
                       public wrapperclass(JointMatProd__c Joint) 
                           {
                                this.JOINT = (Joint);
                           }
                  }
    }




Note: The requirement is unclear, so just did the best i can, if it doesnt fit your requirement, please give the entire reuqirement and the object specficiations as asked by @ Suneel#8 so that the issue can be resolved quicker.

Thanks,
balaji  

  
Mick ManMick Man
thank you Balaji Chowdary Garapati, for more precisely, I would like to create another wrapper class for the field Nombre__c and Quantite__c field, and display the product of two fields in a pageblock table, thank you for your understanding because I'm beginner with apex
I sent you a picture for more detail
User-added image
Balaji Chowdary GarapatiBalaji Chowdary Garapati
@Micky Andriamiarantsoa:

Try this code:
 
public class OdtDetailController2 
    {

       
         public list<wrapperclass> Jonintwrapper{get;set;}
         public list<wrapperclass> Odtwrapper{get;set;}
        Pubic Double TotalNombre=0.0;
        Public Double TotalQuantite=0.0;
       Public Double Total;
       
         
         public OdtDetailController2(ApexPages.StandardController controller) 
             {
                 list<Ordre_Travail__c> OrdreTravail = [SELECT id, name, Date__c, Produit__c, Nombre__c FROM Ordre_Travail__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                 list<JointMatProd__c> Jointure = [SELECT id, MatierePremiere__c, Quantite__c FROM JointMatProd__c  WHERE produit__c = 'a0Ic000000DCvwEEAT'];
                
                 Odtwrapper = new list<wrapperclass>();
                 for(Ordre_Travail__c Odt: OrdreTravail)
                     {
                        Odtwrapper.add(new wrapperclass(Odt));
                         if(odt.Nombre__c!=Null){
                             TotalNombre+=odt.Nombre__c;

                        } 
                     }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
						if(Joint.Quantite__c==Null) // Checking! In case of null make it to 0 zero value so code wont break, and assuming Quantite__c is a numeric value
						Joint.Quantite__c=0; 
                        Jonintwrapper.add(new wrapperclass(Joint,Decimal.ValueOf(Joint.Quantite__c*TotalNombre)));
                        
                     }
                       

              }
    
              public class wrapperclass
                  {
                       public Ordre_Travail__c ODT{get;set;}
                       public JointMatProd__c JOINT{get;set;}
					   Public Decimal Total{get;set;}
                       
                       public wrapperclass(Ordre_Travail__c OrdreTravail) 
                           {
                                this.ODT = (OrdreTravail);
                           }
                           
                       public wrapperclass(JointMatProd__c Joint,Decimal Total) 
                           {
                                this.JOINT = (Joint);
								this.Total=Total;
                           }
                  }
    }


Created an other parameter called Total and an other constructore which takes Joint instance and Total value to assign it back to its variables. 
Hope it helps.

Thanks,
Balaji

This was selected as the best answer
Mick ManMick Man
A big thank you to you all, and especially for you Balaji Chowdary Garapati finally my problem is solved, thanks to you, thank you again
Balaji Chowdary GarapatiBalaji Chowdary Garapati
Can you please mark it solved and select the best answer :)

Thanks,
Balaji
Mick ManMick Man
and if I would like to create a test class for this class, what should I do