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
nagasnagas 

S-Control to VisualForce Page

hi ,

 

I have an S-Control in our Organization which needs to be replaced by VisualForce Page. Can anybody help me how to build a visualforce page for this S-Control logic. I am posting the S-Control logic below.

 

 

<script type="text/javascript"> 
if({!ISNULL( User.Partner_PIF__c )})
{
alert("You do not have Access to PIF. Please Contact System Administrator for further assistance");
}
else{
top.location.href ="/{!User.Partner_PIF__c}"; 
}
</script>

 

 

bob_buzzardbob_buzzard

While you can do this in VF, it would be simpler to create a custom button with execute javascript behaviour, then you just need a slightly tweaked version of you JS as the content:

 

 

if({!ISNULL( $User.Partner_PIF__c )})
{
alert("You do not have Access to PIF. Please Contact System Administrator for further assistance");
}
else{
top.location.href ="/{!$User.Partner_PIF__c}"; 
}

 

Note that you don't need to wrap it in <script> tags either.

 

 

 

nagasnagas

yes for button we can use this code. But my requirement is i need to create a visualforce tab and assigne that VF page to the tab. So when the user clicks on that Tab this functionality should be happened.

bob_buzzardbob_buzzard

The way you'd do this is a VF page with a page-level action, declared like so:

 

 

<apex:page controller="mycontroller" action="{!checkUser}">
   You do not have Access to PIF. Please Contact System Administrator for further assistance
</apex:page>

 

Then your controller would have the checkuser method defined as:

 

 

public class mycontroller
{
   public PageReference checkUser()
   {
      PageReference result=null;
      User u=[select id, Partner_PIF__c from User where id =:UserInfo.getUserId()][0];
      if (null!=u.Partner_PIF__c)
      {
         result=new PageReference('/' + u.Partner_PIF__c);
      }

      return result;
}

 

Thus if the user doesn't have a Partner_PIF__c defined, they will stay on the page and get the error message.