0

Good morning. Is there a way to pass a value from an OnClick Javascript Detail Page Button to a Controller other than the controller that the button is on?

This is my JavaScript:

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/26.0/apex.js")}

var engID=window.sfdcPage.entityId
var postType="statement of work";   

window.location="https://rsidemo1-dev-ed--c.na24.visual.force.com/apex/VfFilePost?scontrolCaching=1&id="+engID;

I want to assign postType to a variable in the controller of the VfFilePost Page. I am new to Salesforce and programming. Any help is appreciated.

0

You could pass it as an encoded URL parameter:

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/26.0/apex.js")}

var engID=window.sfdcPage.entityId
var postType="statement of work";   

window.location="https://rsidemo1-dev-ed--c.na24.visual.force.com/apex/VfFilePost?scontrolCaching=1&id="+engID+"&postType="+EncodingUtil.urlEncode(postType, 'UTF-8');

And then retrieve and decode it in your recipient controller:

String rawPostType = ApexPages.currentPage().getParameters().get('postType');
String postType = EncodingUtil.urlDecode(rawPostType, 'UTF-8');
| improve this answer | |
  • I'm getting an error. EncodingUtil is not defined. Do I have the correct requirescript notation? – Stephen Sep 25 '15 at 13:07
  • The second excerpt is for an Apex controller. Were you not talking about Apex controllers? What type of controller did you mean? – Rob Sep 25 '15 at 13:14
  • The Apex controller extension for the VfFilePost Page. – Stephen Sep 25 '15 at 13:19
  • You should be able to run the second excerpt within the controller extension. EncodingUtil is a standard Apex library. – Rob Sep 25 '15 at 13:21
  • Were you able to get it working in the end? – Rob Sep 25 '15 at 13:55
0
VF Page - Action function<br><apex:actionFunction name="sendpostType" action="{!sendpostType}" rerender="pb">
<apex:param name="x" value="" assignTo="{!postTypeValue}" />

javascript code:

      sendpostType(postType);

controller code:

public class TestController{
public string postTypeValue{get;set;}

public TestController(){
postTypeValue = '';
}
public void sendpostType(){
system.debug('postTypeValue' + postTypeValue);
}
}

| improve this answer | |

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.