
When you have more than one record type then you can put the record type information into a map. Below is the code to do that –
sObject Field Describe –
This will return a map of field tokens for an sObject type and then the field describe method can provide a number of useful information about that field. With this, you can make your code flexible to work for any object. Below is the code –
You can refer to the Salesforce Documentation for all the methods . Click Here
Global Describe –
This will return a map of sObject tokens for all sObjects. Below is the method –
Note – Fetch sObject Type from Record Id
The Schema.SObjectType can be retrieved from a Record Id. This is really helpful when you are working with Task or Event. The reason is WhatId field can refer to multiple types of objects. By fetching sObject type from WhatId field, dynamically you can decide your business logic.
Here is the code snippet –