1

I'm having an issue getting a button to execute javascript correctly on a Visualforce page. The button is supposed to execute an Apsona Merge Action, but instead, it just refreshes the page.

When I put the javascript into a Custom Button, it works fine. So I know the javascript itself is working, but there must be something wrong with the way I have it here:

<apex:includeScript value="https://service.apsona.com/sfdc/apsona_inline.min.js"/>
<script type="text/javascript">
    // script to make sure Apsona has session ID
    sforce.connection.sessionId = "{!$Api.Session_ID}";

    // hack that prevents Salesforce from always putting focus
    // on the first date field
    window.onload = function() { }
</script>

<button onclick="apsona.runAction ('buttonMerge', { 
'actionId': 'a2Of0000000RJ1BEAW', 
'recordId': '{!Campaign.Id}', 
'linkFieldId': 'Id', 
'element': this 
 });">VIP CRCF</button>

Any suggestions?

1 Answer 1

2

I blieve if you add return false; it will stop refreshing the page.. and to keep the code clear you can move the method into Javascript function and call it from the onclick Handler

<apex:includeScript value="https://service.apsona.com/sfdc/apsona_inline.min.js"/>
<script type="text/javascript">
    // script to make sure Apsona has session ID
    sforce.connection.sessionId = "{!$Api.Session_ID}";

    // hack that prevents Salesforce from always putting focus
    // on the first date field
    window.onload = function() { }

    function callApsona(){
        apsona.runAction ('buttonMerge', { 
                'actionId': 'a2Of0000000RJ1BEAW', 
                'recordId': '{!Campaign.Id}', 
                'linkFieldId': 'Id', 
                'element': this 
        });
    }
</script>

<button onclick="callApsona();return false;">VIP CRCF</button>
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.