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
Reference

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:

<apex:commandButton
value="Add Killer Checks"
action="{!URLFOR($Action.DisplayCheck__c.New, null, ['CF00N20000009H4jV'=$CurrentPage.Parameters.vname,'CF00N20000009H4jV_lkid'=$CurrentPage.Parameters.id])}"
style="float:center"
/>

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.

Reference

Salesforce <Source> > URLFOR function finally explained!

Tags

Tags

    Ads Blocker Image Powered by Code Help Pro

    Ads Blocker Detected!!!

    This site depends on revenue from ad impressions to survive. If you find this site valuable, please consider disabling your ad blocker.