I need to create a url with Concat function, but also I need to add to this link additional parameters set in the email properties. Therefore, I placed the URL not in the AMPscript block, but in the a tag.

This is my try:

%%[ VAR @url, @subscriber_key, @jobid SET @subscriber_key = _SubscriberKey SET @jobid = JobID ]%%


Unluckily, it doesn't work: sending a preview and clicking on the resulting link, I receive the horrible error message "bad request - invalid url".

Where am I wrong? Thank you, G.


The simple solution is to build it all in the ampscript block and then push the value of the final variable into the href. This lets you manipulate all inside the ampscript and reduces the 'inline' coding, especially if you need to place this url in multiple places.

See below for sample of what I mean.

        VAR @url, @subscriber_key, @jobid, @finalurl

        SET @subscriber_key = _SubscriberKey
        SET @jobid = JobID 
        SET @url="https://www.pixartprinting.it/unsubscribe/"
        SET @finalurl=CONCAT(@URL,"?tk=",@subscriber_key,"&jid=",@jobid)

        <a href="%%=v(@finalurl)=%%">Unsubscribe9</a>

Looks like you are missing a few things.
1 - links using AMPscript tend to work best when wrapped with RedirectTo()
2 - double quotes in the function will cause it to break if you are not also including an escape
3 - there's no Concat() in the snippet provided

Try the following:

    VAR @url, @subscriber_key, @jobid 
    SET @subscriber_key = _SubscriberKey 
    SET @jobid = JobID 

<a href="%%=RedirectTo(Concat('https://www.pixartprinting.it/unsubscribe/?tk=',@subscriber_key,'&jid=',@jobid))=%%" target="_blank">Unsubscribe_9</a>
  • Thank you @edu8rdo. One more doubt. setting additional email properties on email leve, they will be added also to the link wrapped in RedirectTo()? – Giulia De Monte Jun 25 '15 at 15:05
  • Yep - as long as those parameters are part of the URL, the yes - the parameters should live w/in the RedirectTo() function. – Eduardo Arias Jun 26 '15 at 18:49
  • The RedirectTo() just saved my day when trying to create dynamic invitations for Trustpilot. Thank you! – Felix Sanchez Sep 21 '17 at 9:11

Check this example code to compose a complete SF URL in Apex Code:

String sbaseURL = System.URL.getSalesforceBaseUrl().toExternalForm();

sfullURL = sbaseURL + '/apex/' + [VISUALFORCE_PAGE_NAME] + '&' + [PARAMETER_NAME] >+ '=' + [PARAMETER_VALUE];

Regards. David Lirio

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.