function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sindoorasindoora 

Java function on visualforce page

We build a vf page for an custom object called competitor.  The vf page consists of java script for executing pop up box according to our senario.
The java part of the code is as below: function chngPrimComp(cmp,val){       
        var c;
        var flag=0;
        if(cmp.checked==false && flag!=0){           
            alert('{!$Label.msgCantUnchk}');
            cmp.checked=true;
            flag++;
        }
        if(cmp.checked==true && flag==0){             
            ctrlCompetitor.checkFirstPrimaryComp('{!$CurrentPage.parameters.retURL}',function(result, event){
                if(event.status){           
                    if(result=='false'){                   
                    c=confirm('{!$Label.msgPrmryCompCnfrm}');
                        if(c==true){
                        flag++;                              
                            ctrlCompetitor.checkPrimaryComp('{!$CurrentPage.parameters.retURL}',function(result, event){
                                if(event.status){}
                                if(event.exception){}
                            });
                        }
                        else if(c==false){
                        cmp.checked=false;
                        }
                    }
                }  
            });
Senario: Opportunity had competitor has a related list. ---> This competitor had few records. if we edit the record from opportunity page,the logic work fine and it displays popup.
In this case the logic captures the opportunity id {!$CurrentPage.parameters.retURL}' =>
ctrlCompetitor.checkFirstPrimaryComp('/006c0000009gG4Q',function(result, event){

Problem:if i edit the competitor records from competitor page then the code didn't fire pop up.

In this case the logic captures opprotunity id along with addtional info .something like this heckFirstPrimaryComp('/a0G?rlid=00ND0000005Df4w&id=006c0000009gG4Q',function(result, event){

 Bug:In the above case how to truncate the additional values and how to display popup on the competitor if user edits from competitor page.
Ashish_SFDCAshish_SFDC
Hi Sindoora, 


This code must be in a Controller Method and that must be called / triggered via javascript on click etc, or a DML event like Save or Submit. 

If you still have issues, enable debug logs and see the logs for the steps of execution. 


Regards,
Ashish