Saturday, February 14, 2015

Filled Under: , , ,

Using Hierarchical Custom Setting to your Advantage



Salesforce gives you many a construct to make your life easier and present your users a very customized and relevant UI to work on.
To begin my Salesforce post, I will start with such a one - Hierarchical Custom Settings.
The Salesforce Hierarchical custom settings gives you a way to use the Salesforce profile and user variations to make your UI more relevant and useful to a particular user or type of user.
To demonstrate the power of Hierarchical custom settings, let us take up a very simple and basic example.
I have a custom object called Survey in my org. The object records are visible to all users in the org, however, I want only a specific type of user - Recruiters to be able to delete any irrelevant survey.
Even as a recruiter deletes a survey, I have a set of additional logic running behind the screen to do so.
I override my standard Survey detail page with a Visualforce page to begin with, as I want some additional UI customizarions.
To begin with, I remove the standard delete button from my Survey page layout.

I just add the below to my Visualforce page, to display the basic fields on the Survey Detail Page

<apex:page standardController="Survey__c">
  <apex:detail relatedList="false" />
</apex:page>

Now, as any type of user I will only see the 'Edit' and 'Submit for Approval' buttons on the Survey detail page

Now, we go ahead and create a new Hierarchical Custom Setting to be used to make my Visualforce page display a Delete button only for a Recruiter.

We create a new Checkbox field in the Custom settings

With 'Manage' we set the 'canDeleteSurveyRecords' value to true/checked only for a Recruiter

Now, a very important aspect of Hierarchical Settings.Your next thought may come to the point, that your org or any org may have several Profiles and hundreds of users to work with.
Do we set the fields of a custom settings for all the profiles and users ?!
The Answer is NO.
We use the Default Organization Level Value of a Hierarchical custom setting.


In our case we want it to be false for any one else so we leave the check box unchecked.

Now we change our visualforce page, I have added an additonal text just to print the value of the settings for convenience
<apex:page standardController="Survey__c">
  <apex:detail relatedList="false" />
  <apex:form >
  <apex:pageBlock>
  <apex:pageBlockSection >
      <apex:outputText label="Value on Hierarchy Setting" value="{!$Setup.UserAccessSettings__c.canDeleteSurveyRecords__c}"/>
      <apex:commandButton value="Delete" rendered="{!$Setup.UserAccessSettings__c.canDeleteSurveyRecords__c}"/>
  </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>
This does nothing, just makes the commnadbutton 'Delete' rendered based on the value of the Hierarchical custom setting - canDeleteSurveyRecords field.
Now, we login as System admin the page will look like
However, as a Recruiter, I see

So, with intelligent use of Hierarchical Custom settings, you can customize your visualforce pages, with no additional lines of logic in your page.
Similarly, you can branch out your Apex code and and its flow based on a User or a User profile using the very effective Hierarchical Custom settings.

Hope this helps you to design more intelligent and manageable pages and classes.

In my next post, I will be talking about how to make your email templates display your desired information.

8 comments:


  1. Thanks for sharing valuable information and it is useful for onlineitguru provides the best salesforce Online Training Bangalore

    ReplyDelete
  2. I have read your blog its very attractive and impressive. I like your blog. salesforce Online course

    ReplyDelete
  3. Tech Gadgets reviews and latest Tech and Gadgets news updates, trends, explore the facts, research, and analysis covering the digital world.
    You will see Some Tech reviews below,

    lg bluetooth headset : You will also wish to keep design and assorted features in mind. The most essential part of the design here is the buttonsof lg bluetooth headset .

    Fastest Car in the World : is a lot more than the usual number. Nevertheless, non-enthusiasts and fans alike can’t resist the impulse to brag or estimate according to specifications. Fastest Car in the World click here to know more.

    samsung galaxy gear : Samsung will undoubtedly put a great deal of time and even more cash into courting developers It is looking for partners and will allow developers to try out
    different sensors and software. It is preparing two variants as they launched last year. samsung galaxy gear is very use full click to know more.

    samsung fridge : Samsung plans to supply family-oriented applications like health care programs and digital picture frames along with games It should stick with what they know and they
    do not know how to produce a quality refrigerator that is worth what we paid. samsung fridge is very usefull and nice product. clickcamera best for travel: Nikon D850: Camera It may be costly, but if you’re trying to find the very best camera you can purchase at this time, then Nikon’s gorgeous DX50 DSLR will
    probably mark each box. The packaging is in a vibrant 45.4-megapixel full-frame detector, the picture quality is simply wonderful. However, this is just half the story. Because of a complex 153-point AF system along with a brst rate of 9 frames per minute. camera best specification. click here to know more.

    visit https://techgadgets.expert/ this site to know more.

    ReplyDelete
  4. Big Truck Tow: Heavy Duty towing service san jose

    We're rated the most reliable heavy duty towing san jose service & roadside assistance in San Jose!
    Call us now! We're ready to help you NOW!

    Since 1999, tow truck san jose has provided quality services to clients by providing them
    with the professional care they deserve. We are a professional and affordable Commercial
    Towing Company. BIG TRUCK TOW provides a variety of services, look below for the list of
    services we offer. Get in touch today to learn more about our heavy duty towing


    Click here to Find tow truck near me

    ReplyDelete
  5. crowdsourcehttp://www.incruiter.com recruitment agency.

    We ’incruiter’ provide a uniquerecruitment agencies platform to various committed professionals
    placement consultancyacross the globe to use their skills and expertise to join as a recruiter and
    interviewer to empower the industry with talented human resources.Searching for the right candidate is never easy.
    job consultancy We use crowdsource recruitment to find right talent pool at much faster pace.
    Our candidate search follows application of a rigorous methodology, and a comprehensive screening to find an individual
    whorecruitment consultants is not only skilled but is also the right culture fit for your organization.
    Our interviewers are best in the industry,staffing agencies being experts from various verticals to judge right
    candidate for the job. They interview candidates taking into account primarily defined job specification of our clients and targeting
    them for needs of the organization.Thinking about payment?placement agencies Don’t worry, you pay when you hire.
    Whether you are a startup or an established enterprise, join our 10x faster recruitment process that reduces your hiring process by 50% and give you
    manpower consultancyefficient results.

    check our website:http://www.incruiter.com.

    ReplyDelete
  6. The article is much informative which i was searching for .Nice intro good explanation thanks for sharing.
    Enrgtech Limited

    ReplyDelete
  7. Casinos Near Harrah's Casino, Atlantic City - MapYRO
    Casinos near Harrah's Casino, Atlantic City. MapYRO users have the option to download this 공주 출장마사지 app from 대구광역 출장안마 the 오산 출장안마 Google 천안 출장샵 Play Store and 밀양 출장샵 play the game for free.

    ReplyDelete