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
YWAMRTOadminYWAMRTOadmin 

Custom links based on user.

I want my contact View page link to be determined by the user.


So User 1 would go to /apex1

User 2 would go to /apex2

etc...

 

Is this possible?

Best Answer chosen by Admin (Salesforce Developers) 
YWAMRTOadminYWAMRTOadmin
This is the controller code.
 
public class pageredir
{
   String recordId;
       public pageredir(ApexPages.StandardController controller)  
           {recordId = controller.getId();}
 

   public Pagereference pageredirect()
       {
           if (Userinfo.getUserName() == 'helpdesk@ywamrto.org.sandbox')
           {
               Pagereference p = Page.viewpage1;
               p.getParameters().put('id', recordId);
               return p;
               
           } 
           
            else
           {
               Pagereference p = Page.viewpage2;  
               p.getParameters().put('id', recordId);
               return p;
           }  
       }      
}
Message Edited by YWAMRTOadmin on 07-27-2009 04:47 PM

All Answers

Edwin VijayEdwin Vijay

Yes it is possible...

 

Override your View button with a VF page say "PageRedirView"

 

In "PageRedirView", in the <apex:page> tag call a action method... have nothing else in this VF pafe

 

In the action method.. check the current user ($Userinfo() ) will get you the details... And redirect as you like

 

Hope this helps.....

YWAMRTOadminYWAMRTOadmin

Thanks, but I'm not sure what action I'm supposed to invoke. This attribute is foreign to me.

 

I'm pretty much stuck at:

<apex:page action="">

</apex:page>

 

 

 



Edwin VijayEdwin Vijay

I've posted an article on this here http://salesforceexperts.blogspot.com/2009/07/overriding-standard-buttons-with.html

 

 

Hope this helps you

YWAMRTOadminYWAMRTOadmin

Okay, so I've made the class in Eclipse (3.4.2 IDE v16). And when I try to deploy it to the server, I get this error.

# Deploy Results:

   File Name:    classes/pageredir.cls

   Full Name:  pageredir

   Action:  NO ACTION

   Result:  FAILED

   Problem: An error occurred on your page.

 

I copied the code you had on your blog exactly save for the username. Am I doing something wrong? 

 

"An error occurred on your page.    pageredir.cls pageredir/src/classes     line 0  Force.com save problem"

 

It works great in the Sandbox environment, but it won't save to my production org. 

 

Message Edited by YWAMRTOadmin on 07-23-2009 11:37 PM
Edwin VijayEdwin Vijay

Hi.. Iv not worked much on the Eclipse environment...

 

But the usual practice is.. you will have to package your code and move it to production.. you cannot create a class directly in production.. I guess that might be the reason your class does'nt save in production..

 

Remember your apex class should have 75% test coverage in order to move to production..

 

Hope this helps

YWAMRTOadminYWAMRTOadmin

There was an error on my part about which page it was to used.

 

Now it works in production, but when the view link is overridden, it doesn't keep the ID of the contact. Any idea?

YWAMRTOadminYWAMRTOadmin
This is the controller code.
 
public class pageredir
{
   String recordId;
       public pageredir(ApexPages.StandardController controller)  
           {recordId = controller.getId();}
 

   public Pagereference pageredirect()
       {
           if (Userinfo.getUserName() == 'helpdesk@ywamrto.org.sandbox')
           {
               Pagereference p = Page.viewpage1;
               p.getParameters().put('id', recordId);
               return p;
               
           } 
           
            else
           {
               Pagereference p = Page.viewpage2;  
               p.getParameters().put('id', recordId);
               return p;
           }  
       }      
}
Message Edited by YWAMRTOadmin on 07-27-2009 04:47 PM
This was selected as the best answer