1

I'm trying to pass user parameters (integers) to a button, which runs a method. At the moment, my method and button work as intended, except with hard coded data.

Below is an image of what I'm trying to do. Is there anyway to create a text field like this that will send data to my function? I'm quite new to Salesforce, and would appreciate any feedback.

(for more reference as to what I'm trying to do, my button will copy/create new assignments for however many months into the future as the user selects)

enter image description here

EDIT

The below is what my javascript code now looks like:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var timestoexecute = prompt("Please enter how many months to copy this assignment over", "1");

var result = sforce.apex.execute("AssignmentPropagation","copyAssignments",{assignmentName:"{!Assignment__c.Name}", times:timestoexecute});
alert(result);
window.location.reload();

By adding a prompt, and sending that variable to the Apex class, I now get the desired results. Thanks Daniel.

1

1 Answer 1

4

You can't place additional controls next to the custom buttons. At least without using some form of JavaScipt DOM injection, which could create bigger problems.

There are a few options I can think of:

  1. Create an intermediate Visualforce page that collects the parameter data
  2. Use an "Execute JavaScript" button to prompt for the extra parameter before performing the action.
  3. Inline a Visualforce page into the page layout that has all the controls you need.

Aptorian's implementation of option 2:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
var timestoexecute = prompt("Please enter how many months to copy this assignment over", "1");

var result = sforce.apex.execute("AssignmentPropagation","copyAssignments",{assignmentName:"{!Assignment__c.Name}", times:timestoexecute});
alert(result);
window.location.reload();

By adding a prompt, and sending that variable to the Apex class, I now get the desired results.

3
  • Ok, thanks Daniel. As you can tell I'm very new to salesforce. I'll look into those options, thanks.
    – Aptorian
    Jun 15, 2016 at 22:01
  • 1
    Thanks Daniel, #2 worked for me. I'll update my main post for anyone else who may have this question.
    – Aptorian
    Jun 15, 2016 at 22:21
  • @Aptorian Happy to help. I've merged your solution into the answer. You might not have sufficent upvotes yet, but in the future you can also suggest edits to existing answers with useful details like this. Keeps the Q and A parts more distinct for future visitors. Jun 15, 2016 at 23:58

You must log in to answer this question.

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