RSS feed for blog Linkin Skype Mail Me Twitter

Stickfight

Salesforce read mode hide-when hack

It seems the need for hacks has not gone away with the move to cloud, but you do have to be more careful, as I have already found out Salesforce can break your custom code at will.

So that being true one of the things that SalesForce does not seem to have that every other framework does is a simple an powerful “hide when”, IMHO this feature should be present in every line button and object on every page and most platforms do,

It is the most requested feature for customisation that I have come across, and this is the hack that I use for read mode documents or forms (which strangely is where the request is most often made) (and yes it is a hack)

We are going to just stuff some JavaScript into a apex page, you can see an example of it below

<apex:page standardController="Case" showHeader="false" sidebar="false">

<script>

myVar = checkforbutton();

function checkforbutton()
{
    if (typeof(parent.document.getElementsByName("searchArticles")[0]) != "undefined" )
    {
               if ( parent.document.title.indexOf("Customer Community") != -1) {        
                   parent.document.getElementsByName("searchArticles")[0].style.display = "none"; 
               }
    }
    else
    {
            window.setTimeout("checkforbutton();",100);
    }
} 


</script>

   
</apex:page>


Lets break it down

  1. We have to use “parent.document” to get JavaScript objects as when we use this page SalesForce will embed it inside a Iframe

  2. We have to do a wait loop that keeps looking for the object till it finds it (then stops), because SalesForce adds button objects in after the page loads so they wont be there when it first opens

    if (typeof(parent.document.getElementsByName("searchArticles")[0]) != "undefined" )
    {
            //do stuff
    }
    else
    {
            window.setTimeout("checkforbutton();",100);
    }


  1. When the button is confirmed to be there then we are going to check the page for a condition(s) and if it’s true/false we are going to hide the button/element on the basis of it, in the above example, if we are on the “Customer Community” version of a page, we don’t want to allow the users to search for articles, so we hide the “searchArticles” button, it’s not a security issue, we just don’t want to confuse the user experience by allowing this feature.

So we put this code into a Page

SF Page

This insert that page into the layout Object layout we want it to effect.

SF Page

that would normally give a big white space where the inserted form lives, so we make the page a 1% by 1px block


SFHIDEWHENHACK03.png

And that’s it, just save the layout, the button/”what ever” will hide when the page loads, a hack but a simple reliable hack

Now as always “hide when” is not security, remember to make sure that you don’t leave functions exposed and think this kind of thing covers you.

Leave Your Comments

blog comments powered by Disqus

Related Entries

Free beer and disreputable company

A Year in Review 2016

Ical Invites with Gmail tip

IBM Champion for 2017

The Perfect IBM Champion

SAML and Invalid Arguments

Sametime 9.0.1 and IP6

Salesforce Pardot: Multi Completion Rules

Razer Deathadder Chrome Sensitivity on Linux

MWLug 2016 Round-Up

To Find The Perfect Office

A Little Thing Done Right

SalesForce for Domino Dogs 3: Web Query Save Agents

Presenting at MWLUG

SalesForce for Domino Dogs 2: Scheduled Agents

SalesForce for Domino Dogs 1: Profile Documents

Editable salesforce templates

New Platform Type New Client Type

Engage 2016

LDCVia Webinar

Current Android Software 2015

Classic Domino and multi country dates with Bootstrap

C3 charts on Saleforce Winter16

Updating Statamic on AWS

Icon UK 2015

Quiet Isnt it

Engage 2015

Conditional Checking in AngularJs using Restangular

IBM ConnectED2015 All work and no play

Learning A Lesson About Security from other People

2014 A Year In Review

IBM Connections Dev Update to V5

W.T.F. they made me an IBM Champion and a C-API tip

Bloody Android Kit-Kat and SD Cards

LDC Via Cross Post: Why oh why oh why (Part One)

Applet security: a blast from the past

UK ICON 2014

jQuery UK 2014 Day 2

jQuery UK 2014 Day 1

London Node.js User Group April 2014

Listen while you work

SQuirrel SQL For IBM Connections

Living Document: Connections Db Schema Versions

Connections Db Schema Tip2: Finding the UserID

Working from anywhere

Connections Db Tip1: getting the Connections db Schema version

CSC Event No.1

Engage 2014

IBM Connections Dev Links

Collaboration Stack Community Agenda and Stuff

Connections aide memoire 02: Backing Up Websphere Config

Inserting HTML into word documents

Connections aide memoire 01: Changing XML config

IBM Connect 2014 Slide Decks

IBM Connect 2014 Round up

Finding Me at IBM Connect 2014

Collaboration Stack Event

Commuting tip for Developers

My IBM Connect 2014 Sessions

IBM Connect 2014 session

Best USB Cable

The Perfect Consultant

First Tuesday Club November 2013

Latest Blogs