Created
July 5, 2023 17:08
-
-
Save Sunil02kumar/a157b777ec32da88e25ee05c5ace271f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SK_ToolingAPIFieldsUtility { | |
@AuraEnabled | |
public static DM_FieldWrapper findAllFields(string selOrgNCName,string objAPIName,string NamespacePrefix){ | |
DM_FieldWrapper returnValue= new DM_FieldWrapper(); | |
string URIForFields='/services/data/v54.0/tooling/query/?q=Select+id,Datatype,ReferenceTo,ExtraTypeInfo,IsCalculated,IsCompound,IsIndexed,ValueTypeId,RelationshipName,NamespacePrefix,Label,IsNameField,QualifiedApiName,developerName+from+FieldDefinition+'; | |
URIForFields=URIForFields + 'where+EntityDefinition.QualifiedApiName=\''+objAPIName+'\'+AND+IsCalculated=false+'; | |
URIForFields=URIForFields + '+AND+DataType!=\'Auto+Number\''; | |
string endpointURL='callout:'+selOrgNCName+URIForFields; | |
if(string.isNotBlank(NamespacePrefix)){ | |
endpointURL=endpointURL+'+AND+NamespacePrefix=\''+NamespacePrefix+'\''; | |
} | |
system.debug('***endpointURL:'+endpointURL); | |
HttpRequest req = new HttpRequest(); | |
req.setEndpoint(endpointURL); | |
req.setMethod('GET'); | |
Http http = new Http(); | |
HTTPResponse res = http.send(req); | |
DM_FieldWrapper JSONDetails= DM_FieldWrapper.parse(res.getBody()); | |
System.debug('****field count-:'+JSONDetails.records.size()); | |
for(cls_records fdata : JSONDetails.records){ | |
system.debug('****fdata.QualifiedApiName:'+fdata); | |
} | |
returnValue= JSONDetails; | |
return returnValue; | |
} | |
public class DM_FieldWrapper{ | |
public Integer size; | |
public Integer totalSize; | |
public boolean done; | |
public String entityTypeName; | |
public cls_records[] records; | |
} | |
public class cls_records { | |
public String Id; | |
public String DataType; | |
public boolean IsCalculated; | |
public boolean IsCompound; | |
public boolean IsIndexed; | |
public string RelationshipName; | |
public string NamespacePrefix; | |
public String Label; | |
public boolean IsNameField; | |
public String QualifiedApiName; | |
public String DeveloperName; | |
public ReferenceTo ReferenceTo; | |
public cls_EntityDefinition EntityDefinition; | |
} | |
public class ReferenceTo { | |
public List<String> referenceTo; | |
} | |
public class cls_EntityDefinition { | |
public String QualifiedApiName; | |
public string MasterLabel; | |
} | |
public static DM_FieldWrapper parse(String json){ | |
return (DM_FieldWrapper) System.JSON.deserialize(json, DM_FieldWrapper.class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment