1

I have a custom tab name 'Payments' and i need to provide a short cut access link to this tab from other pages. I know how to control the visibility based on object level settings, However, in this scenario I need to check if the tab is visible by that profile/user, then only show the output link.

Can anyone please point me into right direction.

Thank you.

1

create two layout one layout contain link and oher layout without link and share 1 layout with your profile

0

Parul,

One option is to use Permission sets to give access to the custom tab and add this permission set to the users profile [instead of using the object settings under the profile]

then in your controller, you can check if the users profile has this permission set assigned or not to find out if the tab is accessible to the user or not

here's a related post which has details on how to use permission sets to control tab visiblity

Can you show/hide a custom tab on a per user basis?

1
  • Thank you, but I don't want to use a permission set. The package is already deployed to all customers, so adding a new permission set will means updating it for all the existing profiles too. – parul Sep 15 '14 at 9:46
0

In Apex, you can check only Object/Field permissions and not tab visibility. To do that, we need to use Metadata API.

  1. Go to https://github.com/financialforcedev/apex-mdapi and click on "Deploy to Salesforce". This is the Apex wrapper for Salesforce Metadata API because Apex does not support Metadata API natively
  2. Add your Salesforce instance URL in remote site settings for the Metadata API to work
  3. Once deployed, you can use the below class to get tab visibility for any Profile. Invoke the method "ProfileTabSettings.getTabSettings();"

    public with sharing class ProfileTabSettings{
    public static MetadataService.MetadataPort createService()
    { 
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        return service;     
    }
    public static void getTabSettings(){
        MetadataService.MetadataPort service = createService();
        MetadataService.Profile admin = (MetadataService.Profile) service.readMetadata('Profile', new String[] { 'Admin' }).getRecords()[0];
        for(MetadataService.ProfileTabVisibility ptv : admin.tabVisibilities){
            system.debug('tab name = ' + ptv.tab + ' & ' + 'visibility = ' + ptv.visibility);
        }
    }
    

    }

  4. Sample debug logs showing tab visibility for both standard and custom tabs

USER_DEBUG|[16]|DEBUG|tab name = CObject1__c & visibility = DefaultOn 20:10:29.561 (2561238677)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561249923)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561263176)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561284914)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561294050)|USER_DEBUG|[16]|DEBUG|tab name = CObject2__c & visibility = DefaultOn 20:10:29.561 (2561300614)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561308910)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561320450)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561339471)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561347746)|USER_DEBUG|[16]|DEBUG|tab name = SSOContact__c & visibility = DefaultOn 20:10:29.561 (2561354395)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561362436)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561373417)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561392222)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561400516)|USER_DEBUG|[16]|DEBUG|tab name = SyncKA & visibility = DefaultOn 20:10:29.561 (2561406905)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561414831)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561425759)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561443722)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561451901)|USER_DEBUG|[16]|DEBUG|tab name = Test_web_tab & visibility = DefaultOn 20:10:29.561 (2561458116)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561466018)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561477020)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561494590)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561502603)|USER_DEBUG|[16]|DEBUG|tab name = redirect_tab & visibility = DefaultOn 20:10:29.561 (2561508755)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561516962)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561527993)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561545912)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561553946)|USER_DEBUG|[16]|DEBUG|tab name = standard-Account & visibility = DefaultOn 20:10:29.561 (2561560253)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561568218)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561580360)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561598330)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561606555)|USER_DEBUG|[16]|DEBUG|tab name = standard-AppLauncher & visibility = DefaultOn 20:10:29.561 (2561612953)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561621031)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561631931)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561649871)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561658460)|USER_DEBUG|[16]|DEBUG|tab name = standard-Campaign & visibility = DefaultOn 20:10:29.561 (2561664893)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561672589)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561683484)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561701822)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561709911)|USER_DEBUG|[16]|DEBUG|tab name = standard-Case & visibility = DefaultOn 20:10:29.561 (2561716253)|SYSTEM_METHOD_EXIT|[16]|System.debug(ANY) 20:10:29.561 (2561723972)|SYSTEM_METHOD_ENTRY|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561734972)|SYSTEM_METHOD_EXIT|[15]|system.ListIterator.hasNext() 20:10:29.561 (2561753048)|SYSTEM_METHOD_ENTRY|[16]|System.debug(ANY) 20:10:29.561 (2561760836)|USER_DEBUG|[16]|DEBUG|tab name = standard-Chatter & visibility = DefaultOn

3
  • ProfileTabVisibility supports visibility of tabs for standard objects.. are you sure it works for custom tabs as well ?? salesforce.com/us/developer/docs/api_meta/Content/… – Vamsi Krishna Gosu Sep 12 '14 at 23:07
  • @VamsiKrishna, You are right and also the documentation says that but I am able to see tab visibility for both standard and custom tabs (custom object tab, web tab, VF tab) of my org in debug logs (see sample debug logs above). Is it possible to add Permission Set to User's Profile like you mentioned? I have seen assigning it to individual Users but not Profile. – Sethuraman.AR Sep 13 '14 at 3:38
  • @parul, Any updates? – Sethuraman.AR Sep 19 '14 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.