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
Sourav PSourav P 

Query in Method declaration

Hi, I am new to Apex, Can anyone plz clarify me on below,

User-added imageWhile checking the above method from the SObjectType Class, as i can see the Example mentioned is not same as the Signature. So Is that an instance created for calling the method ? , If its an instance there is no "New" keyword. So, what is that actually?
Best Answer chosen by Sourav P
Danish HodaDanish Hoda
Hi Sarav,
You can refer it this way:
These methods are static methods of the Schema class.

And the static methods are initialised in this manner : ClassName.MethodName();
The return type has been equated for processing other operations --
ReturnType result = ClassName.MethodName();

All Answers

Danish HodaDanish Hoda
Hi Sarav,
You can refer it this way:
These methods are static methods of the Schema class.

And the static methods are initialised in this manner : ClassName.MethodName();
The return type has been equated for processing other operations --
ReturnType result = ClassName.MethodName();
This was selected as the best answer
Sourav PSourav P
Hi Danish , Thanks
Is the above initilization synta is for the static method only ? What if it is an instance method, like below case. what would be the syntax then ?

User-added image
Sourav PSourav P
Also, when the rule is the return type of getGlobalDescribe(), is Map, why in below case , the Map is not assigned ?
Schema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ;

 
Danish HodaDanish Hoda
Hi Sourav,
Instance methods are the non-static methods, which is called by an instantiated object of a class.

For example, we can see one of the methods of DescribeSObjectResult class as below:

Schema.DescribeSObjectResult d = Account.sObjectType.getDescribe(); Map<String, Schema.FieldSet> FsMap = d.fieldSets.getMap();

The above syntax can also be written as below, which you can better infer:
1. Schema.DescribeSObjectResult d = new Schema.DescribeSObjectResult(); 
2. d = Account.sObjectType.getDescribe(); 

Please put you attention here -
the expression in #1 is the same as OuterClass.InnerClass classObjInstance = new  OuterClass.InnerClass();
the expression in #2 is the same as classObjInstance.MethodName();
 
Danish HodaDanish Hoda
Now Coming to your second query:

Map comes with a pair of keys and values, like Map<Key, Value>
to get the value related to a key, you have to use the Map's get method --> mapObject.get(key);

As you can see from my first answer in this trail:
ReturnType result = ClassName.MethodName();

Here, the return type is Map<String, Schema.sObjectType>, thus, we would get the value of a definite objectName from this result object which is Map type as below:
Schema.SObjectType s = Schema.getGlobalDescribe().get(objectName) ;
<Type value of Map in result variable> <instanceVariable> = <ClassName.MethodName()>.<getMethodOfMap>