Visualforce页面显示指定用户的特定记录

时间:2014-08-28 08:21:32

标签: salesforce visualforce

我在visualforce页面上有一个代码,它显示指定用户的特定记录。此代码是IF-ELSE方案,假设只有两个指定的用户。但是,我想为不同的记录指定10个不同的用户。有人可以帮帮我吗?

现有代码

/************** Visualforce page *****************/
<apex:page controller="myClass" action="{!redirect}" >

</apex:page>


 /************* Controller ***********************/
public with sharing class myClass{
public string uId;

public myClass(){
    uId = UserInfo.getUserId(); 
}

public pageReference redirect(){
    PageReference pageRef = new PageReference('URL1');
    pageRef.setRedirect(true);
    if(uId == 'firstOption'){
        pageRef.setRedirect(true);
        return pageRef;
    }else{
        pageRef = new PageReference('URL2');
        pageRef.setRedirect(true);
        return pageRef;
    }
}

}

1 个答案:

答案 0 :(得分:0)

如果您要让多个用户访问该页面,则可以创建Hierarchy Custom Setting来存储每个用户的URL。这样,您就可以使用可配置的方式维护列表,而无需更新/重新部署代码。

首先创建自定义设置,对于此示例,我们将其称为&#34;用户重定向&#34;(User_Redirect__c),并使其成为层次结构类型。给它一个名为&#34;重定向URL&#34;(Redirect_Url__c)的自定义文本字段。

完成后,单击“管理”按钮,然后可以为“用户”(和/或“个人档案”)添加单个记录。确保创建一个默认的组织范围的记录也是一个全部记录。

现在,在您的控制器中,您只需要参考自定义设置。

//the system will automatically grab the record for the user if one exists, 
//else a for their profile if a record exists, else the org-default
String url = User_Redirect__c.getInstance().Redirect_Url__c;
PageReference pageRef = new PageReference(url);
//this is implied if redirecting to a different url. you only ever need to set 
//this if you are refreshing the current page and want to reset the state
//pageRef.setRedirect(true);
return pageRef;
相关问题