Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I have created custom settings object with two fields. I have also created an Apex controller, and a Visual Force Page to update/edit the custom settings. As a system administrator, I can edit the custom settings using that form. But when I log in as a standard user the form fields are not showing up. I can't add custom setting even through Setup->Develop->CustomSettings and clicking on manage, when I am logged in as a standard user. I have made both my controller and Visual force page permissions to be accessible by anyone.

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?

1 Answer

0 votes
by (32.1k points)
edited by

Users with the 'Standard User' profile can't write to Custom Settings objects. For this, you'd need to grant users the 'Customize Application' permission and this, in turn, will require the View Setup Configuration permission which is undesirable.

You could customize object instead of storing the user's settings.

Enroll in our Salesforce training to become an Expert in Salesforce!

Browse Categories

...