You need to sign in to do that
Don't have an account?
Sourav P
Query in Method declaration
Hi, I am new to Apex, Can anyone plz clarify me on below,
While 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?
While 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?
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
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();
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 ?
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();
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>