Standard user cannot add / edit user settings record in salesforce

I created a custom settings object with two fields. I also created an Apex controller and a Visual Force page to update / change user settings. As a system administrator, I can edit user settings using this form. But when I log in as a standard user, the form fields are not displayed. I can’t add custom settings even through Setup-> Develop-> CustomSettings and click on the control when I am registered as a standard user. I have allowed access for both my controller and Visual Force.

Below is my controller code,

public class XYZSettingsController { public XYZSettings__c mySettings {get; set;} public XYZSettings__c myOrgSettings{get; set;} public XYZSettingsController() { mySettings = XYZSettings__c.getValues(System.Userinfo.getUserId()); myOrgSettings = XYZSettings__c.getInstance(); if(mySettings == null) { mySettings = new XYZSettings__c(SetupOwnerId=System.Userinfo.getUserId()); } } public String getOrgUrl() { return myOrgSettings.XYZ_Url__c; } public String getOrgEmail() { return myOrgSettings.XYZ_Email__c; } public String getUrl() { return mySettings.XYZ_Url__c; } public String getEmail() { return mySettings.XYZ_Email__c; } public PageReference save() { if(mySettings.id == null){ upsert mySettings; } else{ update mySettings; } return null; } } 

And below is my Visual Force page,

 <apex:page Controller="XYZSettingsController" title="Edit XYZ access settings"> <apex:form > <apex:pagemessage severity="info" strength="1"> Your default XYZ platform url is: {!OrgUrl} and Email is: {!OrgEmail} <br></br> You can override it in the settings below </apex:pagemessage> <apex:pageBlock title="Edit XYZ settings" mode="edit"> <apex:commandButton action="{!save}" value="Save"/> <apex:pageBlockSection columns="2"> <apex:inputField value="{!mySettings.XYZ_Url__c}"/> <apex:inputField value="{!mySettings.XYZ_Email__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> 

Any clues?

+4
source share
2 answers

Users with a Standard User profile cannot record Custom Settings objects. To do this, you need to give users the Configure Application permission, and this, in turn, requires View Setup Configuration permission, which is probably undesirable.

It is best to use a custom object instead to save custom settings.

In another note: your recipients for email fields and URLs are redundant, you can just use {!mySettings.XYZ_Url__c} , etc., as you did, with input fields, and for better formatting and character escaping you you may want to use <apex:outputField value="{!mySettings.XYZ_Url__c}"/> .

+1
source

Source: https://habr.com/ru/post/1382878/


All Articles