function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MiralomaMiraloma 

Conditional Redirect

I have a custom link that requires a condition. The content source is set to URL and I want to display a Visual Force page when the condition fails. I have the following syntax.

/{!if(isBlank(Svc_GC__c)
,"apex/NoSvcGCFound"
,Svc_GC__c)
}

 

The problem is the / in "apex/NoSvcGCFound" gets decoded to %2F and I get a page not foundn error. I've tried to htmlencode, urlencode, ', ", \, //, etc. Nothing worked.

 

Suggestions are appreciated!

MiralomaMiraloma

Update:

 

I ended up changing it to onClick Javascript (instead of URL) and doing the following:

 

var gc="{!CR__c.Svc_GC__c}";

if (!gc) window.open("/apex/NoServiceGoverningContract");
else  window.location.href="/"+gc;

 

Am still interested in knowing how to do the same in URL if at all possible. Thanks!

Avidev9Avidev9

Well there seems to be a problem in your code. Apex generally doesnt encode URL automatically.

 

I tried replicating your scenario by doing some thing like this : 

<script>
      window.location.href = "{!IF(MYCondition,'apex/Test','apex/Test2')}";
</script>

 

The above code worked as expected

MiralomaMiraloma
Is there a way to do it without invoking the script context? I was
aiming/hoping that it could be done with just the {} escapes.

Thanks!