Schema-Parent,Child,Formula

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for (Schema.ChildRelationship cr: R.getChildRelationships()) {
system.debug('====child object==='+cr.getChildSObject());
}

for(Schema.SobjectField strFld: Contact.SobjectType.getDescribe().fields.getMap().Values()){
if(strFld.getDescribe().getType() == Schema.DisplayType.REFERENCE){
system.debug('==parent object='+strFld.getDescribe().getReferenceTo());
}
}

String strFormula = '';
String strTable = '<table><th>Field Name</th><th>Formula</th>';
//replace with appropriate object name
Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.Car_Service__c.fields.getMap();
for(Schema.SObjectField field : fieldMap.values()){
    Schema.DescribeFieldResult dfr = field.getDescribe();
    //isCalculated() is used to identify custom formula fields
    //getCalculatedFormula() != null is used to exclude rollup summary fields as they are treated as formulas
    if(dfr.isCalculated() && dfr.getCalculatedFormula() != null){
        strFormula += '<tr><td>' + dfr.getName() + '</td>' + '<td>' + dfr.getCalculatedFormula() + '</td></tr>';
        system.debug('Formula Field::' + dfr.getName() + ' Formula::' + dfr.getCalculatedFormula());
    }
}

Comments

Popular posts from this blog

Lightning Grid Custom Datatable

Comparing Two Values Using Aura If

Dynamic Standard Datatable Using Fieldset