3

I'm having a problem in using javasacript to display an error while mass updating a child record of an opporunity once I found the picklist ed_sp_ls__c='return' and the value ed_vpo_n__c=0 of at least one child record. Here is my code behind: // apex class

public String trouve {get;set;}
// constructeur de la classe
trouve ='IN Constructor';
public pageReference checkpo(){

        OppID = ApexPages.currentPage().getParameters().get('id');
        lstPO = [Select ed_sp_ls__c, ed_vpo_n__c From Poste_offre__c where Opportunite__c =: OppID];

        system.debug(logginglevel.error,'#######this.columnToSave '+this.columnToSave);
        if(this.columnToSave=='ed_sp_ls__c' ){
        system.debug(logginglevel.error,'#######Opportunite__c '+OppID);
        system.debug(logginglevel.error,'#######lstPO '+ lstPO);
        system.debug(logginglevel.error,'#######this.columnToSaveInIf '+this.columnToSave);
            for(Poste_offre__c po : lstPO){
                if(po.ed_sp_ls__c == 'retenu' &&  po.ed_vpo_n__c == 0)
                trouve ='true'; break;
                }
         system.debug(logginglevel.error,'#######trouve aprés init : '+trouve);
        }
        return refreshPage(false);
      }

// visualforce page:

<apex:actionFunction name="checkpo" action="{!checkpo}" status="spinningwheel" 
                             rerender="res,pageMessages"/>

<apex:outputPanel id="check" >
<script>
    var t  = '{!trouve}';
    checkpo();
   if(t=='true'){
    alert('Error, Status is 'return' and volume is 0');
    } 
</script>

</apex:outputPanel>

On debug log: trouve ='IN constructor' not 'true' wich doesnt let the message error to display

Any troubleshoot

  • 1
    When posting code, it's useful if you strip out anything irrelevant, such as debug statements and so on. – sfdcfox Dec 10 '14 at 16:50
2

Your javascript has a string with quotes that are not escaped. This is probably why no message is shown.

<script>
    var t  = '{!trouve}';
    checkpo();
   if(t=='true'){
    alert('Error, Status is \'return\' and volume is 0');
    } 
</script>

Besides that, checkpo is called asynchronously. The entire structure of what you're trying to do makes it highly improbable that it will work as you intend. You'll probably want to do something like this:

<apex:inputHidden value="{!trouvue}" id="result" />

<script>
function checkResult() {
    var x = document.getElementById("{!$Component.result}").value;
    if(x == "true") {
        alert("Status is \"return\" and volume is 0");
    }
 }
<apex:actionFunction name="checkpo" action="{!checkpo}" status="spinningwheel" 
                         rerender="result,res,pageMessages" oncomplete="checkResult()" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.