public static void getFieldNames(String objName){

    Map <String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe()

    for(Schema.SObjectField sfield : fieldMap.Values())
        schema.describefieldresult dfield = sfield.getDescribe();
        system.debug(dfield.getname() + ': '+ dfield.getType());

I have the above code where it takes the object name as the argument and prints all the fields for that object along with their data types. But I am also looking for a way to know if any of those fields are formula fields.

Looks like the getType method returns result of the formula field but I need to know if that field is a formula field or not?


1 Answer 1


You need the isCalculated method on DescribeFieldResult:

public static Boolean isFormula(SObjectField field)
    return field.getDescribe().isCalculated();

Not the answer you're looking for? Browse other questions tagged .