• Mick Man
  • NEWBIE
  • 35 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 16
    Replies
I am new to Salesforce, I try to create a test class, I think I succeeded, but my coach was not yet satisfied, but I do not know now what this test class, the problem is that c I only have two days today and tomorrow to do it, if not, I'm not allowed to support my report
this is my class
public class NouveauProduitExtensions 
    {
         public List<cMatiere> matiereList {get; set;}
         public List<JointMatProd__c> JointList {get; set;}
         public List<MatierePremiere__c> selectedMatieres{get;set;}
         public Integer value {get;set;} 

         public NouveauProduitExtensions(ApexPages.StandardController controller) 
             {
                 
             }
    
        public PageReference cancel() 
            {
                return Page.Nouveau_produit;
            }
        public JointMatProd__c Jointure {get; set;} 

        public Produit__c prod { get; set; }

        public NouveauProduitExtensions() 
            {
                prod = new Produit__c();
        
                Jointure = new JointMatProd__c();
            }
    
        public PageReference showAddMatierePage() 
            {
                return Page.Produit_Add_Matiere;
            }
    
        public PageReference Save() 
            {
                insert prod;
                List<JointMatProd__c> JointSave = new  List<JointMatProd__c>();
                 for (JointMatProd__c jl : JointList)
                     {
                         JointSave.add(new jointMatProd__c(Produit__c = prod.id, MatierePremiere__c = jl.MatierePremiere__c, Quantite__c = jl.Quantite__c));
                     }
                insert JointSave;
                PageReference acctPage = new ApexPages.StandardController(prod).view();

                acctPage.setRedirect(true);

                return acctPage;
            }

        public List<cMatiere> getMatieres() 

            {
                if(matiereList == null) 
                    {
                        matiereList = new List<cMatiere>();
                        for(MatierePremiere__c c : [select Id, Name, Unite__c from MatierePremiere__c])
    
                           {

                               matiereList.add(new cMatiere(c));
                           }
                  }
                  return matiereList;
             }  
    
        public PageReference processSelected()

            {
                selectedMatieres = new List<MatierePremiere__c>();
                JointList = new List<JointMatProd__c>(); 
                for (cMatiere cMat : getMatieres()) 
                    {
                        if(cMat.selected == true) 
                            {
                                selectedMatieres.add(cMat.mat);
                            }
                    }
                value = selectedMatieres.size();
                System.debug('printing listcontc'+selectedMatieres.size());
                for (MatierePremiere__c mat : selectedMatieres)
                    {
                        JointList.add(new jointMatProd__c(Produit__c = prod.id, MatierePremiere__c = mat.id, Quantite__c=0));
                    }

                return page.Nouveau_produit;

             }

             public class cMatiere

                {
                    public MatierePremiere__c mat {get; set;}
                    public Boolean selected {get; set;}

                    public cMatiere(MatierePremiere__c c) 
                        {
                            mat = c;
                            selected = false;
                        }
                }


}

and here's the test
@isTest(SeeAllData=true)
public class TestDataAccessClass {

    static testmethod void ProdTestMethod() {
        Produit__c prod = [SELECT Id, Name FROM Produit__c WHERE Name='Oli-c' LIMIT 1];
        System.assert(prod != null);
        
        Produit__c testProd = prod.clone();
        testProd.Name = 'test prod';
        insert testProd;
        
        Produit__c testProd2 = [SELECT Id, Name FROM Produit__c WHERE Name='test prod' LIMIT 1];
        System.assert(testProd2 != null);
    }
 
 static void JointTestMethod() {
    JointMatProd__c joint = [SELECT  Id, Name, MatierePremiere__c, Produit__c, Quantite__c FROM JointMatProd__c WHERE Name='17' LIMIT 1];
    System.assert(joint != null);
    
    JointMatProd__c testJoint = joint.clone();
    //testJoint.Name = '';
    testJoint.MatierePremiere__c = 'Couvercle alu test';
    testJoint.Quantite__c = 12;
    
    JointMatProd__c testJoint2 = [SELECT Id, Name, MatierePremiere__c, Quantite__c FROM JointMatProd__c WHERE MatierePremiere__c='Couvercle alu test' LIMIT 1];
   }
  
}

Can someone help me please
I want to know where is the problem for this trigger
trigger updateParentQuantity on EntreeSortie__c (after insert, after update) 
    {
        Set<Id> MatPremIds= new Set<Id>();

        for (EntreeSortie__c ES: Trigger.new) 
            {
                MatPremIds.add(ES.MatierePremiere__c);
            }

        MatPremIds.remove(null);

        if (!MatPremIds.isEmpty()) 
            {
                Map<Id, Decimal> totalMap = new Map<Id, Decimal>();
                for (Id id: MatPremIds) 
                    {
                        totalMap.put(id, 0);
                    }
        
                for (AggregateResult ar : [select SUM(Quantite__c) tot, MatierePremiere__c, Type__c from EntreeSortie__c where MatierePremiere__c = :MatPremIds])
                    {   
                        Id MatPremId = ar.get('MatierePremiere__c');
                        if (ar.get('Type__c') == 'Entrée') 
                            {
                                totalMap.put(MatPremId, totalMap.get(MatPremId) + ar.get('tot'));
                            } 
                         else if (ar.get('Type__c') == 'Sortie') 
                            {
                                totalMap.put(MatPremId, totalMap.get(MatPremId) - ar.get('tot'));
                            }
                    }   

                List<MatierePremiere__c> MatToUpdate = new List<MatierePremiere__c>();

                for (Id id: totalMap.keySet()) 
                    {
                        MatToUpdate.add(new MatierePremiere__c(Id = id,Nombre_au_Stock__c = totalMap.get(id)));
                    }

                update MatToUpdate;
        }
    }

User-added image
thank you in advance for your help
who can help me to create a trigger for the custom object Entree/Sortier that the custom object MatierPremiere be updated each time that there is an input or an output
that is to say, if one selects entrée (input), the number of stores of raw material object is updated (+) and if one selects sortie (output), the number of stock of raw material object is updated (- )

User-added image
is what we can create a trigger for thé standard Visualforce page
Please! can someone help me to solve my little problem because I can not do the same,
public class OdtDetailController2 
    {

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

                        } 
                    // }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
                        if(Joint.Quantite__c==Null)
                        Joint.Quantite__c=0; 
                        Jonintwrapper.add(new wrapperclass(Joint,Double.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;
                           }
                  }
    }

here's my problem

"Visualforce ErrorAide sur cette page
System.QueryException: List has more than 1 row for assignment to SObject 
Class.OdtDetailController2.<init>: line 16, column 1"
 
there to further problems, can someone help me, this is my code
public class OdtDetailController2 
    {

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

                        } 
                    // }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
                        if(Joint.Quantite__c==Null)
                        Joint.Quantite__c=0; 
                        Jonintwrapper.add(new wrapperclass(Joint,Double.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;
                           }
                  }
    }
Here the error
Erreur : OdtDetailController2 Erreur de compilation : Invalid bind expression type of Schema.SObjectField for column of type Id à la ligne 17 colonne 136
 
j'aimerai créer une page visualforce comme l'image ci-dessous, mais je n'arrive même pas, que dois je faire ?
<apex:page standardController="Ordre_Travail__c" extensions="OdtDetailController2">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!Odtwrapper}" var="odt">
            <apex:column value="{!odt.ODT.name}"/>
            <apex:column value="{!odt.ODT.Date__c}"/>
            <apex:column value="{!odt.ODT.Produit__c}"/>
            <apex:column value="{!odt.ODT.Nombre__c}"/>
        </apex:pageBlockTable>
            <apex:pageblocktable value="{!Jonintwrapper}" var="joint">
                  <apex:column value="{!joint.JOINT.MatierePremiere__c}" />
                  <apex:column value="{!joint.JOINT.Quantite__c}" />
          </apex:pageblocktable>
    </apex:pageBlock>
</apex:page>
and here is my class
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);
                           }
                  }
    }

and I'd like this 
User-added image
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);
                           }
                  }
    }

 
how can calculate the product of two fields in two different custom objecthel
how the class if I want to calculate the amount of MP by product,
that is to say, I want to calculate the result Quantity x number of product
<apex:page standardController="Ordre_Travail__c" extensions="OdtDetailController2">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!Odtwrapper}" var="odt">
            <apex:column value="{!odt.ODT.name}"/>
            <apex:column value="{!odt.ODT.Date__c}"/>
            <apex:column value="{!odt.ODT.Produit__c}"/>
            <apex:column value="{!odt.ODT.Nombre__c}"/>
        </apex:pageBlockTable>
            <apex:pageblocktable value="{!Jonintwrapper}" var="joint">
                  <apex:column value="{!joint.JOINT.MatierePremiere__c}" />
                  <apex:column value="{!joint.JOINT.Quantite__c}" />
          </apex:pageblocktable>
    </apex:pageBlock>
</apex:page>
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);
                           }
                  }    
    }


 
how can display two custom object in a Visualforce page
such as
<apex:page standardController="Ordre_Travail__c" extensions="OdtDetailController">
    <apex:pageBlock >
        <apex:pageBlockSection title="Detail d'un ordre de travail" collapsible="false">
                    <apex:outputText value="{!Ordre_Travail__c.Name}"/>
                    <apex:outputField value="{!Ordre_Travail__c.Date__c}"/>
                    <apex:outputField value="{!Ordre_Travail__c.Produit__c}"/>
                    <apex:outputField value="{!Ordre_Travail__c.Nombre__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable value="{!Joint}" var="g">
                    <apex:column value="{!g.MatierePremiere__r.name}"/>
                    <apex:column value="{!g.Quantite__c}"/>
            </apex:pageBlockTable>
    </apex:pageBlock>

 
I would like to add a record in a custom object products and the same time a record in a custom object jointure__c, 
Here is my controller
public class NouveauProduitExtensions {

    public NouveauProduitExtensions(ApexPages.StandardController controller) {
    }
    
    public PageReference cancel() {
        return Page.Nouveau_produit;
    }
    public JointMatProd__c Jointure {get; set;} 

    public Produit__c prod { get; set; }

    public NouveauProduitExtensions() {
        prod = new Produit__c();
        
        Jointure = new JointMatProd__c();
    }
    
    public PageReference showAddMatierePage() {
        return Page.Produit_Add_Matiere;
    }
    
    public PageReference Save() {
        insert prod;
        insert JointList;
        PageReference acctPage = new ApexPages.StandardController(prod).view();

        acctPage.setRedirect(true);

        return acctPage;
    }

     public List<cMatiere> matiereList {get; set;}
     public List<JointMatProd__c> JointList {get; set;}
     public List<MatierePremiere__c> selectedMatieres{get;set;}
     public Integer value {get;set;} 

     public List<cMatiere> getMatieres() 

     {
      if(matiereList == null) {
       matiereList = new List<cMatiere>();
       for(MatierePremiere__c c : [select Id, Name, Unite__c from MatierePremiere__c])
    
       {

       matiereList.add(new cMatiere(c));
       }
      }
      return matiereList;
     }  
    
public PageReference processSelected()

 {
  
   
    selectedMatieres = new List<MatierePremiere__c>();
    JointList = new List<JointMatProd__c>();
    
    for (cMatiere cMat : getMatieres()) {
        if(cMat.selected == true) {
            selectedMatieres.add(cMat.mat);
        }
    }
   value = selectedMatieres.size();
   System.debug('printing listcontc'+selectedMatieres.size());
    
    for (MatierePremiere__c mat : selectedMatieres)
     {
        JointList.add(new jointMatProd__c(Produit__c = prod.id, MatierePremiere__c = mat.id, Quantite__c=0));
    }

   return page.Nouveau_produit;

 }

public class cMatiere

{
 public MatierePremiere__c mat {get; set;}
 public Boolean selected {get; set;}

 public cMatiere(MatierePremiere__c c) {
            mat = c;
            selected = false;
        }
  }


}

but if I completed my registration with the button save, an error is produced as
"System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields have not been filled: [Produit]: [Produit]"
can someone help me
 
I am new with salesforce, I have an Apex class and I would like to create a test for this class but I have no idea, can someone help me please
public class NouveauProduitExtensions {

    public NouveauProduitExtensions(ApexPages.StandardController controller) {
    }
    
    public PageReference cancel() {
        return Page.Nouveau_produit;
    }
    public JointMatProd__c Jointure {get; set;} 

    public Produit__c prod { get; set; }

    public NouveauProduitExtensions() {
        prod = new Produit__c();
        Jointure = new JointMatProd__c();
    }
    
    public PageReference showAddMatierePage() {
        return Page.Produit_Add_Matiere;
    }
    
    public PageReference Save() {
        insert prod;
        insert Jointure;
        PageReference acctPage = new ApexPages.StandardController(prod).view();

        acctPage.setRedirect(true);

        return acctPage;
    }

     public List<cMatiere> matiereList {get; set;}
     public List<JointMatProd__c> JointList {get; set;}
     public List<MatierePremiere__c> selectedMatieres{get;set;}
     public Integer value {get;set;} 

     public List<cMatiere> getMatieres() 

     {
      if(matiereList == null) {
       matiereList = new List<cMatiere>();
       for(MatierePremiere__c c : [select Id, Name, Unite__c from MatierePremiere__c])
    
       {

       matiereList.add(new cMatiere(c));
       }
      }
      return matiereList;
     }  
    
public PageReference processSelected()

 {
  
   
    selectedMatieres = new List<MatierePremiere__c>();
    JointList = new List<JointMatProd__c>();
    
    for (cMatiere cMat : getMatieres()) {
        if(cMat.selected == true) {
            selectedMatieres.add(cMat.mat);
        }
    }
   value = selectedMatieres.size();
   System.debug('printing listcontc'+selectedMatieres.size());
    
    for (MatierePremiere__c mat : selectedMatieres)
     {
        JointList.add(new jointMatProd__c(Produit__c = prod.id, MatierePremiere__c = mat.id, Quantite__c=0));
    }

   return page.Nouveau_produit;

 }

public class cMatiere

{
 public MatierePremiere__c mat {get; set;}
 public Boolean selected {get; set;}

 public cMatiere(MatierePremiere__c c) {
            mat = c;
            selected = false;
        }
  }


}


 
I want to know where is the problem for this trigger
trigger updateParentQuantity on EntreeSortie__c (after insert, after update) 
    {
        Set<Id> MatPremIds= new Set<Id>();

        for (EntreeSortie__c ES: Trigger.new) 
            {
                MatPremIds.add(ES.MatierePremiere__c);
            }

        MatPremIds.remove(null);

        if (!MatPremIds.isEmpty()) 
            {
                Map<Id, Decimal> totalMap = new Map<Id, Decimal>();
                for (Id id: MatPremIds) 
                    {
                        totalMap.put(id, 0);
                    }
        
                for (AggregateResult ar : [select SUM(Quantite__c) tot, MatierePremiere__c, Type__c from EntreeSortie__c where MatierePremiere__c = :MatPremIds])
                    {   
                        Id MatPremId = ar.get('MatierePremiere__c');
                        if (ar.get('Type__c') == 'Entrée') 
                            {
                                totalMap.put(MatPremId, totalMap.get(MatPremId) + ar.get('tot'));
                            } 
                         else if (ar.get('Type__c') == 'Sortie') 
                            {
                                totalMap.put(MatPremId, totalMap.get(MatPremId) - ar.get('tot'));
                            }
                    }   

                List<MatierePremiere__c> MatToUpdate = new List<MatierePremiere__c>();

                for (Id id: totalMap.keySet()) 
                    {
                        MatToUpdate.add(new MatierePremiere__c(Id = id,Nombre_au_Stock__c = totalMap.get(id)));
                    }

                update MatToUpdate;
        }
    }

User-added image
thank you in advance for your help
I want to know where is the problem for this trigger
trigger updateParentQuantity on EntreeSortie__c (after insert, after update) 
    {
        Set<Id> MatPremIds= new Set<Id>();

        for (EntreeSortie__c ES: Trigger.new) 
            {
                MatPremIds.add(ES.MatierePremiere__c);
            }

        MatPremIds.remove(null);

        if (!MatPremIds.isEmpty()) 
            {
                Map<Id, Decimal> totalMap = new Map<Id, Decimal>();
                for (Id id: MatPremIds) 
                    {
                        totalMap.put(id, 0);
                    }
        
                for (AggregateResult ar : [select SUM(Quantite__c) tot, MatierePremiere__c, Type__c from EntreeSortie__c where MatierePremiere__c = :MatPremIds])
                    {   
                        Id MatPremId = ar.get('MatierePremiere__c');
                        if (ar.get('Type__c') == 'Entrée') 
                            {
                                totalMap.put(MatPremId, totalMap.get(MatPremId) + ar.get('tot'));
                            } 
                         else if (ar.get('Type__c') == 'Sortie') 
                            {
                                totalMap.put(MatPremId, totalMap.get(MatPremId) - ar.get('tot'));
                            }
                    }   

                List<MatierePremiere__c> MatToUpdate = new List<MatierePremiere__c>();

                for (Id id: totalMap.keySet()) 
                    {
                        MatToUpdate.add(new MatierePremiere__c(Id = id,Nombre_au_Stock__c = totalMap.get(id)));
                    }

                update MatToUpdate;
        }
    }

User-added image
thank you in advance for your help
who can help me to create a trigger for the custom object Entree/Sortier that the custom object MatierPremiere be updated each time that there is an input or an output
that is to say, if one selects entrée (input), the number of stores of raw material object is updated (+) and if one selects sortie (output), the number of stock of raw material object is updated (- )

User-added image
Please! can someone help me to solve my little problem because I can not do the same,
public class OdtDetailController2 
    {

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

                        } 
                    // }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
                        if(Joint.Quantite__c==Null)
                        Joint.Quantite__c=0; 
                        Jonintwrapper.add(new wrapperclass(Joint,Double.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;
                           }
                  }
    }

here's my problem

"Visualforce ErrorAide sur cette page
System.QueryException: List has more than 1 row for assignment to SObject 
Class.OdtDetailController2.<init>: line 16, column 1"
 
there to further problems, can someone help me, this is my code
public class OdtDetailController2 
    {

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

                        } 
                    // }
                     
                 Jonintwrapper = new list<wrapperclass>();
                 for(JointMatProd__c Joint: Jointure)
                     {
                        if(Joint.Quantite__c==Null)
                        Joint.Quantite__c=0; 
                        Jonintwrapper.add(new wrapperclass(Joint,Double.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;
                           }
                  }
    }
Here the error
Erreur : OdtDetailController2 Erreur de compilation : Invalid bind expression type of Schema.SObjectField for column of type Id à la ligne 17 colonne 136
 
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);
                           }
                  }
    }

 
how can calculate the product of two fields in two different custom objecthel