0

I have a requirement where I have to create custom button that unchecks the checkbox value if the checkbox is already checked. Somehow I am able to check the checkbox value to false by click on custom button.but the biggest showstooper that I am facing in my requirement is we have 5 tabs & if I click on  any one of the tabs then I have to caputure the ID or the name of the tab that i clicked on it. I have written the following code;

​For Button:

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} 
sforce.connection.sessionId = '{!$Api.Session_ID}'; 
var Result = sforce.apex.execute("OutcomeController","checkboxFalse", {opportunityId: "{!Opportunity.Id}"}); 
alert('Result:'+Result); 
if(Result=='false'){ 
window.location.reload(); 
} 

Controller Class:

global with sharing class OutcomeController {
    public string myStage{get; set;}
    ......................



    public void StageNme()
    {
        system.debug('myStage:'+myStage);
    }



        webservice static boolean checkboxFalse(Id opportunityId) 
    {
    Opportunity currentOpportunity = OpportunityServices.getOpportunity(opportunityId);
      Outcome__c voi1= Outcome__c.getValues('Solution Implemented');   
     Outcome__c voi2= Outcome__c.getValues('Schedule Created');      
      system.debug('voi1 stage NAme:'+voi1.StageName__c);
       system.debug('voi2 stage NAme:'+voi2.StageName__c);


                //system.debug('vo name:'+vo);
                if (currentOpportunity.get(voi1.FieldName__c) == true && voi1.StageName__c=='Implement') {
                currentOpportunity.SolutionImplemented__c=false;
                update currentOpportunity;   
                }
                if(currentOpportunity.get(voi2.FieldName__c) == true && voi2.StageName__c=='Cause')
                {
                currentOpportunity.ScheduleCreated__c=false; 
                update currentOpportunity;  
                }
                else{
                    return true;
                }

                return false;

    }
}

VF Page:

<apex:page docType="html-5.0" standardController="Opportunity" extensions="OutcomeController" showHeader="false" sidebar="false" standardStylesheets="false" applyHtmlTag="false" applyBodyTag="false">
<html>
<head>
<script>
var j$ = jQuery.noConflict();

j$(function() {


    j$('.voCheckbox').click(function() {
        j$('[id$=":OutcomeIdInput"]').val(j$(this).data("outcome"));
        j$('[id$=":currentStageInput"]').val(j$(this).data("stage"));
        completeVOActionJSCheck();

    });




    // get tab container
    var container = document.getElementById("tabcontainer");
    var tabcon = document.getElementById("tabscontent");
    var navitem = document.getElementById("tabheader_{!SUBSTITUTE(currentStage,' ','')}");

    if (navitem != null) {

        var ide = navitem.id.split("_")[1];
        navitem.parentNode.setAttribute("data-current",ide);

        navitem.setAttribute("class","active");

    }
    //this adds click event to tabs
    var tabs = container.getElementsByTagName("li");
    console.log('tabdata8:'+tabs);
    for (var i = 0; i < tabs.length; i++) {
    tabs[i].onclick=display;
    console.log('tabdata9:'+tabs[0]);

    }
    // show active panel

    var curTab = document.getElementById("tabpage_{!SUBSTITUTE(currentStage,' ','')}");
    console.log('tabdata10:'+curTab);
    if (curTab != null) {
        curTab.style.display='block';
    }
});

// on click of one of tabs
function display() {

    var current = this.parentNode.getAttribute("data-current");
    console.log('current tab name'+current);
    if (current != null) {
        //remove class of activetabheader and hide old contents
        document.getElementById("tabheader_" + current).removeAttribute("class");
        document.getElementById("tabpage_" + current).style.display="none";
    }
    ide = this.id.split("_")[1];

    //add class of activetabheader to new active tab and show contents
    this.setAttribute("class","active");
    document.getElementById("tabpage_" + ident).style.display="block";
    this.parentNode.setAttribute("data-current",ide);
}

 /*function dosomejavascript() 
 { 
 var myParam = 'abc'; 
 //call my action function - myParam variable should be set to 'somevariable' in my controller 
 StageNme(myParam); 
 console.log('myParam Name:'+myParam);
 }


</script>

</head>

<body>



<apex:variable value="{!Opportunity.AccountId}" var="oppAccId" />

<apex:form id="mainForm">

    <apex:actionFunction action="{!completeVOActionCheck}" name="completeVOActionJSCheck" />
<apex:actionFunction action="{!StageNme}" name="StageNme"  rerender="">
<apex:param name="v" value="" assignTo="{!myStage}" />
</apex:actionFunction>


<apex:inputHidden value="{!selectedVerifiableOutcomeId}" id="selectedOutcomeIdInput" />


          </script>
</apex:outputPanel>

<apex:outputPanel id="allTabs" layout="block">


                    <apex:outputPanel layout="block" rendered="{!outcome.Type__c == 'CHECKBOX'}">
                        <p>
                            <label class="outcome-name">{!outcome.Name}:</label>
                            <apex:outputPanel layout="none" rendered="{!currentOpportunity[outcome.FieldName__c] == true}">
                                <i class=" green"></i>
                            </apex:outputPanel>
                            <apex:outputPanel layout="none" rendered="{!currentOpportunity[outcome.FieldName__c] == false}">

                                <apex:outputPanel rendered="{!isEditAllowed}" layout="none">
                                    <input type="checkbox" class="voCheckbox" data-outcome="{!outcome.Id}" data-stage="{!stage}" style="vertical-align: middle" />
                                </apex:outputPanel>
                                <apex:outputPanel rendered="{!!isEditAllowed}" layout="none">
                                    <input type="checkbox" style="vertical-align: middle" disabled="true" />
                                </apex:outputPanel>

                            </apex:outputPanel>
                        </p>
                    </apex:outputPanel>

                </apex:repeat>

            </div>

            <div class="rightCol">
                <apex:outputText escape="false" value="{!$Label[verifiableOutcomesUI[stage].HelpLabel__c]}" rendered="{!oppTender=false}" />
                <apex:outputText escape="false" value="{!$Label[verifiableOutcomesUI[stage].HelpLabelTender__c]}" rendered="{!oppTender=true}" />
            </div>

            </div>
        </apex:repeat>
        </div>
    </div>
</apex:outputPanel>   
</apex:form>

</body>
</html>
</apex:page>

if u have referred the VF code,there is a function called as 'Display Page' inwhich there is a variable called as 'Ident' that gives me the exact value of the tabs that i clicked and I must pass the Variable 'Ident' value to the controller class which i am trying to pass by using following syntax

<apex:actionFunction action="{!StageNme}" name="StageNme"  rerender="">
<apex:param name="v" value="Ident" assignTo="{!myStage}" />
</apex:actionFunction>

whatever the Stage Value I get in the Ident variable I have to pass the value and assign to the Variable 'myStage' of the controller but I am not able to pass it out not sure why?? Can somebody please help me how can i pass the variable value to the controller class so that I can use it in my If() of Weservice method? because right now the problem that I am facing while unchecking the checkbox is I am not able uncheck the exact checkbox of the current tab,it randomly executes the condition and randomly uncheck the checkbox and this is true because I am not able to pass the value of click event in my controller class. I am not aware about JS and Jquery totally. Your Help is really appreciate for me to fix this issue.

  • add some id to rerender attribute of action function. due to this, it is not passing value to controller variable. – Ankuli Aug 19 '16 at 10:58
0

First, since you are using VF your do not need

{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/25.0/apex.js")} 
sforce.connection.sessionId = '{!$Api.Session_ID}'; 
var Result = sforce.apex.execute("OutcomeController","checkboxFalse", {opportunityId: "{!Opportunity.Id}"}); 
alert('Result:'+Result); 
if(Result=='false'){ 
window.location.reload(); 
} 

At the end of DisplayPage function

  1. add console.log(ident); just to confirm you have no errors and are making it to the point in the JS code with a value for ident. This is not required but helpful in debugging
  2. Add this line at the end of that JS method

    StageNme(ident);
    

You do not need an ID of any type in the rerender IIRC but if the above does not work just put anything in the rerender parameter and see if that resolves it

Other than that it is debugging your page, required fields, controller, proper use of xyz.

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.