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.

2 Answers 2

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');
9
  • I'm getting an error. EncodingUtil is not defined. Do I have the correct requirescript notation? Commented Sep 25, 2015 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? Commented Sep 25, 2015 at 13:14
  • The Apex controller extension for the VfFilePost Page. Commented Sep 25, 2015 at 13:19
  • You should be able to run the second excerpt within the controller extension. EncodingUtil is a standard Apex library. Commented Sep 25, 2015 at 13:21
  • Were you able to get it working in the end? Commented Sep 25, 2015 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);
}
}

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.