You need to sign in to do that
Don't have an account?
Mick Man
problem with SOQL
Please! can someone help me to solve my little problem because I can not do the same,
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"
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"
Uncomment line number 16 and update like below
Best Regards,
Mithun.
All Answers
OrdreTravail = [SELECT Id, Date__c, Produit__c, Nombre__c FROMOrdre_Travail__c];
Please mark this question as solved if your issue is fixed
As per your code, i think you no need to add line number 16, since you are using standard controller and getting the same record in constructor. just comment line number 16 and check the functionality.
comment line no 16
//OrdreTravail = [SELECT Id, Date__c, Produit__c, Nombre__c FROM Ordre_Travail__c];
Best Regards,
Mithun
Visualforce Error
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Ordre_Travail__c.Produit__c
Class.OdtDetailController2.<init>: line 17, column 1
Uncomment line number 16 and update like below
Best Regards,
Mithun.
Visualforce Error
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Ordre_Travail__c.Name
You need to add necessary fields in your query, just add name field in your query.
Here is updated query.
OrdreTravail = [SELECT Id, name,Date__c, Produit__c, Nombre__c FROM Ordre_Travail__c Where id =: OrdreTravail.Id];
Best Regards,
Mithun.
Best Regards,
Mithun.