You need to sign in to do that
Don't have an account?
Rajaa ABOUMAAD
DML currently not allowed when trying to update a record
hello, I'm trying to affect a value to a field depending on the value of two other, for example if the quantity of a product requested by a seller is greater than the quantity in the store, the value of our field must be the value of the quantity in the store, this is my code and thank you in advance
VF page:
apex class:
VF page:
<apex:page controller="ProduitDemandeClass" > <apex:form > <apex:pageBlock > <apex:commandButton value="Enregistrer" /> <apex:pageBlockSection > <apex:pageBlockTable value="{!produitsDemande}" var="pr"> <apex:column value="{!pr.Produit__c}"/> <apex:column value="{!pr.Quantit_demande__c}" /> <apex:column value="{!pr.Quantit_Accorde__c}"/> <apex:column headerValue="Action"> <apex:commandButton value="Modifier" onclick="window.location='/apex/ValeurAccorde?id={!pr.Produit__c}'; return false;" /> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
apex class:
public with sharing class ProduitDemandeClass { public String idcharg {get;set;} LIST<les_Produit_demander__c> produitsDemande {get;set;} public List<les_Produit_demander__c> getproduitsDemande() { if(produitsDemande == null){ produitsDemande = [select Id,Produit__c,Quantit_demande__c,Quantit_Accorde__c from les_Produit_demander__c where Demande_de_Chargement__c= :idcharg]; Integer i=0; for(les_Produit_demander__c pr :produitsDemande){ list<Stock_par_agence__c> p =[select QuantiteTotaleRestante__c from Stock_par_agence__c where Produit__c= :pr.Produit__c]; if(p != null && p.size() > 0){ if(p.get(0).QuantiteTotaleRestante__c > pr.Quantit_demande__c){ pr.Quantit_Accorde__c=pr.Quantit_demande__c; update pr; } else { pr.Quantit_Accorde__c=p.get(0).QuantiteTotaleRestante__c; update pr; } } } } return produitsDemande; } public ProduitDemandeClass(){ idcharg=ApexPages.currentPage().getParameters().get('id'); } }
http://th3silverlining.com/2009/11/23/dml-currently-not-allowed/
Hope this helps.
Thanks
shashi
All Answers
http://th3silverlining.com/2009/11/23/dml-currently-not-allowed/
Hope this helps.
Thanks
shashi