You need to sign in to do that
Don't have an account?
Drcete
How to get complex type values in SOQL query?
Hello,
I want to get the value of the fields in a complex type through a SOQL query.
How can I read this value?
Thanks for your help!
I want to get the value of the fields in a complex type through a SOQL query.
for(SearchLayout l : [ SELECT FieldsDisplayed from SearchLayout WHERE EntityDefinition.QualifiedApiName='Contact' AND LayoutType='Lookup']) { System.debug(l.FieldsDisplayed); }FieldsDisplay is a complex type containing the fields string property.
How can I read this value?
Thanks for your help!
To read the FieldsDisplay complex type, you need to serialize the SearchLayout object.
Inside the loop you can use JSON.parse(searchLayout), that will serialize the entire record. After that you can use the inner class to read the recrod. That serialization will return JSON something like that.. which will contains all the fields in the seach layout:
Hope this helps!
All Answers
To read the FieldsDisplay complex type, you need to serialize the SearchLayout object.
Inside the loop you can use JSON.parse(searchLayout), that will serialize the entire record. After that you can use the inner class to read the recrod. That serialization will return JSON something like that.. which will contains all the fields in the seach layout:
Hope this helps!
Thanks Gauravendra,
To complement your answer:
JSON2Apex (https://json2apex.herokuapp.com/) generates custom Apex classes for the specific JSON structure, I found it very useful.
Regards