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
Hitesh ChillappagariHitesh Chillappagari 

Schema.SObjectType.Event.getRecordTypeInfosByName().get(Label.RecordTypeName).getRecordTypeId();

Hi Everyone!

Am new to slaesforce and Am trying to learn apex. 

Can anyone breakdown the following..

 

Schema.SObjectType.Event.getRecordTypeInfosByName().get(Label.RecordTypeName).getRecordTypeId();
 

Schema  --> is a class 
SObjectType--> Am guessing it is an inner class
Event--> I understand this can be any object api name but how does that translate to apex? how are we able to call an object name on class? is it because that the object name is a variable inside the inner class?
getRecordTypeInfosByName() --> I guess it is a method inside the inner class
get(Label.RecordTypeName) --> another method but how are we able to call method from a method? method1().method2()??
getRecordTypeId(); --> another method???

Am pretty new to oops(apex) and would like to know how they are internally structure for the way the calls are happeining in the above statement?
can any one explain please.

Thanks in advance!

ShirishaShirisha (Salesforce Developers) 
Hi Hitesh,

Greetings!

Yes,those are all the classes and methods from which we are trying to get the Record Type Name.


Schema.SObjectType.Event.getRecordTypeInfosByName().get(Label.RecordTypeName).getRecordTypeId();

Here,we are trying to get the recordType Name of the Event Object.

If you would like to get the recordType name on Account Object then you can replace EVENT Object With ACCOUNT.

Also,we can call as many as methods as per our requirements as we do not have any limits on it.

Reference:https://developer.salesforce.com/forums/?id=906F0000000937iIAA

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Warm Regards,
Shirisha Pathuri 
Troy CenterTroy Center

Shirisha Pathuri -- Thank you. 
I found this helpful for this reason. "get(Label.RecordTypeName)". I was trying to get the Record Type Name. It seems odd to me why this is, but whatever, it's working. 

Record Type Label: Master (CPQ)  << Works
Record Type Name: Master_CPQ << Does not work. 

Thank you. Troy ~ Seattle. 

Ajay Budarapu 3Ajay Budarapu 3
'Schema.SObjectType.Event.getRecordTypeInfosByName().get(Label.RecordTypeName).getRecordTypeId();'

In above statement you are trying to get the Id of the RecordType(in above statement it'll get the record type name from the custum label 'RecordTypeName). In simple words It'll return the Id of that record type name.

This is how you write you're statement in real time.
global static id id_of_Recordtype = Schema.SObjectType.Event.getRecordTypeInfosByName().get(Label.RecordTypeName).getRecordTypeId();

Explanation:
Class.Class.ObjectAPIName.Method(it's method from DescribeSObjectResult Class).get method(pass the Record type name, in above you're getting from custom label. You can directly write the record type name).Method(it's amethod from RecordTypeInfo Class, to get the id)

Close your query. I hope it'll clear your doubts.