Skip to Content

Solved: How do I fix invalid target parameter for function URLFOR in Apex, Visualforce, Salesforce?

Problem Symptom

URLFOR function returns a relative URL for an action, s-control, Visualforce (VF) page, or used to return a reference to a file contained in a static resource archive such as a .zip or .jar file.

I got the invalid target parameter error randomly and could not able to figured out what causing this error. The detailed error message return from URLFOR function is as below:

Invalid target parameter for function URLFOR

Invalid parameter for function URLFOR

Invalid parameter for function URLFOR Error is in expression ‘{!URLFOR($Action.DisplayCheck__c.New,$CurrentPage.Name)}’ in component in page visitaudit_vf

URLFOR: Invalid parameter for function

Invalid parameter for function URLFOR Error is in expression

Invalid parameter for function URLFOR Error is in expression

Follow the below solution steps to resolve invalid target parameter for function URLFOR issue.

Content Summary

Solution 1: Check the order of parameters
Solution 2: Hide the outputlink
Solution 3: Define static variable

Solution 1: Check the order of parameters

  • first param is $Page
  • second param is Id
  • third param is [‘param’=’eters’]
  • fourth param is Boolean

try this example:

value="Add Killer Checks"
action="{!URLFOR($Action.DisplayCheck__c.New, null, ['CF00N20000009H4jV'=$CurrentPage.Parameters.vname,'CF00N20000009H4jV_lkid'=$])}"

If the parameter where you pass your id is null, hide the outputLink completely when the id of the attachment is null to avoid this error.

<apex:outputLink value="{!URLFOR($Action.Attachment.Download, item.AttachmentID)}" target="_blank" rendered="{!NOT(ISBLANK(item) && NOT(ISBLANK(item.AttachmentID))}">{!item.AttachmentName}</apex:outputLink>

Solution 3: Define static variable

Define a static variable on a class, set that variable to true in your trigger and check against it. As long as you’re within the same transaction scope, that static variable will maintain its value.


Salesforce <Source> > URLFOR function finally explained!

Alex Lim is a certified IT Technical Support Architect with over 15 years of experience in designing, implementing, and troubleshooting complex IT systems and networks. He has worked for leading IT companies, such as Microsoft, IBM, and Cisco, providing technical support and solutions to clients across various industries and sectors. Alex has a bachelor’s degree in computer science from the National University of Singapore and a master’s degree in information security from the Massachusetts Institute of Technology. He is also the author of several best-selling books on IT technical support, such as The IT Technical Support Handbook and Troubleshooting IT Systems and Networks. Alex lives in Bandar, Johore, Malaysia with his wife and two chilrdren. You can reach him at [email protected] or follow him on Website | Twitter | Facebook

    Ads Blocker Image Powered by Code Help Pro

    Your Support Matters...

    We run an independent site that is committed to delivering valuable content, but it comes with its challenges. Many of our readers use ad blockers, causing our advertising revenue to decline. Unlike some websites, we have not implemented paywalls to restrict access. Your support can make a significant difference. If you find this website useful and choose to support us, it would greatly secure our future. We appreciate your help. If you are currently using an ad blocker, please consider disabling it for our site. Thank you for your understanding and support.