+ Start a Discussion
Numaan A.MNumaan A.M 

Is there a way to get index fields of an Object in Apex?

Hi All,

I want all the index fields of an particular object in apex. I have searched throught the Schema describe but couldn't find a way to identify the field as index. Please let me know if somebody have any idea on this.

Regards,
Numaan
Best Answer chosen by Numaan A.M
NagendraNagendra (Salesforce Developers) 
Hi Numaan,

It's not in the describe call, but you can query the FieldDefinition via the Tooling API and it has an IsIndexed field.
List<FieldDefinition> indexedAccountFields = [
    SELECT QualifiedApiName FROM FieldDefinition WHERE IsIndexed = true
    AND EntityDefinition.QualifiedApiName = 'Account'
];
Hope this helps.

Thanks,
Nagendra
 

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Numaan,

It's not in the describe call, but you can query the FieldDefinition via the Tooling API and it has an IsIndexed field.
List<FieldDefinition> indexedAccountFields = [
    SELECT QualifiedApiName FROM FieldDefinition WHERE IsIndexed = true
    AND EntityDefinition.QualifiedApiName = 'Account'
];
Hope this helps.

Thanks,
Nagendra
 
This was selected as the best answer
Numaan A.MNumaan A.M
Thank you Nagendra. I totaly forgot about Tooling API.