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
Krishna_Krishna_ 

How to hide a field through Apex code???

Hi to all,

I am using Lead object & the lead source field adds some Extra values like web,email,phone.
Now I added one custom field Lead No.

 

If I choose Lead source to Web,phone,email then lead no is increased by 1.


If I choose Lead source to Other than above three The Lead No Custom Field should be hodden.

How to hidden a Fields through APEX code???

 

 

Thanks,
Krishna.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
This can be achieved through the use of page layouts and record types. For example, a trigger that updates Lead No. by 1 (or not), could also set the Record Type to a layout that doesn't display lead number. While I'm all for using Visualforce as much as practical, there's times when some old-fashioned technology just works better.

All Answers

momorganmomorgan
If I understand correctly, this sounds like you want to update a page dynamically. Take a look in the Cookbook at the chapter called "Dynamically updating a Page" (p48) - does that set you on your way?
jkucerajkucera

http://wiki.developerforce.com/index.php/Visualforce_DynamicEditPage

 

Here's a link to the concept in case you have problems accessing the Cookbook (I had a problem earlier today). 

 

Key takeaway is to rerender the pageblock, not just the section or sectionitem as I haven't  found a way to make that work (despite 2hrs of trying).

 

sfdcfoxsfdcfox
This can be achieved through the use of page layouts and record types. For example, a trigger that updates Lead No. by 1 (or not), could also set the Record Type to a layout that doesn't display lead number. While I'm all for using Visualforce as much as practical, there's times when some old-fashioned technology just works better.
This was selected as the best answer
Krishna_Krishna_


thanks sfdcfox,


I got by using Page Layout & record types.


I am creating 2 record types that have different layouts.
One layout has that custom field another one not get.

I am using the Trigger are as follows,

 

trigger trg_Lead on Lead (before insert)
{
    for (Lead objLead : Trigger.new)
    {
        if(objLead.LeadSource != null)
        {
       
          // Check the Lead status is Phone,web or Mail & update the Lead No Custom Field.
        }
        else
        {
            RecordType[] rt = [select Id,Name from RecordType where Name =: 'Test Lead'];   //Test Lead is a RECORD TYPE.
            integer NsSize = rt.size();
            for(integer i = 0; i < NsSize ; i++)
            {
                objLead.RecordTypeId = rt[i].Id;
            }
        }
    }
}

 

 

Thanks,
Krishna.