Activity › Forums › Salesforce® Discussions › How to hide or show Salesforce object through the apex code?
Tagged: Account, Record Type, Salesforce Apex, Salesforce Apex Code, Salesforce Custom Object, Salesforce Trigger
-
How to hide or show Salesforce object through the apex code?
Posted by Mohit on July 14, 2016 at 4:16 PMHi All,
How to hide or show Salesforce object like account, contacts, cases or any custom object through the apex code?
Give your suggestion.
Avnish Yadav replied 7 years, 7 months ago 5 Members · 5 Replies -
5 Replies
-
Hi,
I don’t think so this is possible through apex code. But there is one workaround we can change the current user profile through apex code.
- [adinserter block='9']
-
we can change the current user profile through apex code.
-
You can change the profile of the user to hide the meta data.
Hope this helps.
-
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.
-
Here is the code,
You can create 2 record types that have different layouts.
One layout has that custom field another one not get.You can 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.
Log In to reply.