Activity Forums Salesforce® Discussions How to create OnClick button on visualforce page in Salesforce?

  • Piyush

    Member
    September 5, 2019 at 3:28 am

    Hi Deepak,

    You can take help from this below example of vf page to create an onclick event on vf page:-

    <apex:page standardController="Lead" extensions="D_B_LeadCntrlr">
    <apex:includeScript value="/soap/ajax/29.0/connection.js"/>
    <apex:includeScript value="/soap/ajax/29.0/apex.js"/>
    <script >
    
        var success = 'false';
        function myFunction(){
            var Retrieve_DB_Detail = '{!Retrieve_DB_Details}';
            if(Retrieve_DB_Detail == false || Retrieve_DB_Detail == 'false'){
                alert('You cannot perform DB Check with retrieve DB details as false');
            }else{
                var result = sforce.apex.execute("RetriveDBDetailsController","getDBDetails",{leadId:"{!leadId}"});
                alert(result);
                 window.location.reload();
            }
        }
    
        function showSuccess(){
            if(showSuccess == 'true'){
                alert(success);
               window.location.reload();
            }
        }
        </script>
    <apex:form >
    
        <apex:actionFunction name="callMethod" action="{!callMethod}" onComplete="showSuccess()"/>
    
            <apex:PageBlock >
                <div align="center" draggable="false" >
                    <apex:CommandButton value="D&B Check" onclick="myFunction()" />
                </div>
            </apex:PageBlock>
        </apex:form>    
    </apex:page>

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos