0

I've a custom button in the detail view of the object (type is onClick Javascript). I have a visualforce Page where I'm trying to replicate the same functionality done through the Onclick JS button in the page.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var result = 'www.google.com';
window.top.location.href = result;

I was wondering if the button code can be brought in to execute the code. Metadata API was the approach I chose. I queried the button details through Metadata and I got the simple JS working. However, when I have buttons that use connection.js & apex.js, BOOM! They don't work.

I replaced the merge fields those used in the JS script to be replaced with the actual value using a Util class. How do I get the {!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} scripts to work in the page as well?

Thanks in Advance!

2 Answers 2

0

If you are calling from a VF page then the code remains same but ensure that you have added scripts to the top of VF page as below:

<apex:includeScript value="/soap/ajax/30.0/connection.js"/>
<apex:includeScript value="/soap/ajax/30.0/apex.js"/>
6
  • Amit, I've tried that already. The Session ID is missing and hence I get an error. I don't want to do it manually in JS as well. Commented Aug 11, 2015 at 8:39
  • are you passing sessionID somehow ? Commented Aug 11, 2015 at 9:00
  • Yes, setting it in JS. var __sfdcSessionId = '{!GETSESSIONID()}'; Commented Aug 11, 2015 at 9:06
  • It may not work. Its always important to generate session ID in context of VF page or batch apex by possibly using a login call. Just read through the last part of my blog post : cloudyaffair.wordpress.com/2015/07/22/… Commented Aug 11, 2015 at 9:13
  • Did it help ? Were you able to work this out ? Commented Aug 11, 2015 at 11:19
0

After including the scripts manually, I faced the same issue mentioned here.

Setting __sfdcSessionId did not help since the session Id was not set.

var __sfdcSessionId = '{!GETSESSIONID()}';

I had to set the sforce session Id manually.

sforce.connection.sessionId = "{!$Api.Session_ID}";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .