function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lauren HonyotskiLauren Honyotski 

Visualforce page with particular record type

I have a record type on the lead object that requires the email field to be hidden. Salesforce does not allow the email field to be hidden on the page layout of the lead object. I cannot use field level permissions to hide this field either, as the email field is used for other integrations. I just need the email to be hidden from users for this record type. I have a visualforce page that has everything I need. How can I have this page displayed when the lead is this particular record type?
Hargobind_SinghHargobind_Singh
Switching to default page layout conditionally could be hard, you might end up creating a VF page for all record-types. 
@login.ax974@login.ax974
Lauren - try to override your view button with a different visualforce page whose controller can help redirect based on record types to either the visualforce page you created or to the standard layout. An example is given below:


<apex:page standardController="Lead" extensions="LeadOverrideViewController" action="{!navigateToNewRecordTypePage}"> <apex:detail subject="{!lead.Id}" relatedlist="true" rendered="{!NOT(isNewBusinessRecordType)}"/> </apex:page>

public without sharing class LeadOverrideViewController
 {
       public boolean isNewBusinessRecordType {get; set;}
       public Lead lead {get; set;}
       
       /* 
        * Constructor
        */
           
       public LeadOverrideViewController(ApexPages.StandardController controller) 
        {
          isNewBusinessRecordType = false;
          this.lead = (Lead)controller.getRecord();
          List<Lead> lstLE = [Select Id, RecordType.Name from Lead where Id =: lead.Id];
          if(lstLE[0].RecordType.Name == 'New_Business')
           {
             isNewBusinessRecordType  = true;
           }
        }
        
        public PageReference navigateToNewRecordTypePage()
        {
          PageReference pg;
          if(isNewBusinessRecordType)
           {
            pg = Page.myPage; // Replace it with your visualforce page
           }
           else
           {
            pg = new PageReference('/'+lead.Id);
            pg.getParameters().put('nooverride', '1');
           }
          return pg.setRedirect(true);
        }
 }

Let me know if this works.