You need to sign in to do that
Don't have an account?

Custom Button to start Flow with JavaScript
Hi,
I originally created a custom button on the Contact page layout that allowed me to start a flow. The code that worked fine is as follows:
/flow/Enable_SLink_Access &varContactId={!Contact.Id} &retURL=/{!Contact.Id}
This worked great. However I now need to add some JavaScript to this button to analyse the current users profile to allow or deny running the flow.
The new code now looks like this:
//Required by Salesforce.com to run OnClick JavaScript {!RequireScript("/soap/ajax/10.0/connection.js")} if ( '{!User.Profile}' != 'System Administrator' ) { alert('You are not authorised to edit SLink Settings for this Contact'); } else { window.open('/flow/Enable_SLink_Access&varContactId={!Contact.Id}&retURL=/{!Contact.Id}'); }
However now it takes me to an invalid URL where the message on screen says 'URL No Longer Exists'.
The URL has become: https://cs2.salesforce.com/flow/Enable_SLink_Access&varContactId=003R000000Z7dEv&retURL=/003R000000Z7dEv
Can anyone help me with the code I should dress up the flow bit of the code with please?
Thanks very much,
Marco
Hi Marco,
I'd recommend capturing the base url somewhere in the controller like this:
Then use this baseUrl along with the builtIn javascript functions:
encodeURIComponent(str)
andencodeURI(str).
In your case:
Hope this helps!
- Anup
I need this same functionality. Where do you put the baseUrl? Which controller? I'm just using a button, do buttons have controllers attached to them? I know very little about JavaScript
/flow/EnableSLink_Access&varContactIdd={!Contact.Id}&retURL=/{!Contact.Id}
should have been:
/flow/EnableSLink_Access?varContactIdd={!Contact.Id}&retURL=/{!Contact.Id}
(note the first & was changed to a ?)
The first argument must open with a ?.