6

Is there any mechanism in apex for determining if a standard field's value on an sObject is automatically calculated by the platform? (Essentially a roll-up summary field.)

A custom roll up summary field will return true when calling the Schema.DescribeFieldResult .isCalculated() method but the platform's standard summarized fields return false.

Campaign.HierarchyAmountWonOpportunities is one of these automatically calculated fields for instance.

Schema.DescribeFieldResult dfr = Campaign.HierarchyAmountWonOpportunities.getDescribe();
system.debug(dfr);

The describe results for this field look like the list below, giving no indication that the platform automatically calculates this field's value.

getByteLength=0;
getCalculatedFormula=null;
getController=null;
getDefaultValue=null;
getDefaultValueFormula=null;
getDigits=0;
getFilteredLookupInfo=null;
getInlineHelpText=null;
getLabel=Total Value Won Opportunities in Hierarchy;
getLength=0;
getLocalName=HierarchyAmountWonOpportunities;
getMask=null;
getMaskType=null;
getName=HierarchyAmountWonOpportunities;
getPrecision=18;
getReferenceTargetField=null;
getRelationshipName=null;
getRelationshipOrder=null;
getScale=0;
getSoapType=DOUBLE;
getSobjectField=HierarchyAmountWonOpportunities;
getType=CURRENCY;
isAccessible=true;
isAutoNumber=false;
isCalculated=false;
isCascadeDelete=false;
isCaseSensitive=false;
isCreateable=false;
isCustom=false;
isDefaultedOnCreate=false;
isDependentPicklist=false;
isDeprecatedAndHidden=false;
isDisplayLocationInDecimal=false;
isEncrypted=false;
isExternalId=false;
isFilterable=true;
isGroupable=false;
isHighScaleNumber=false;
isHtmlFormatted=false;
isIdLookup=false;
isNameField=false;
isNamePointing=false;
isNillable=true;
isPermissionable=true;
isQueryByDistance=false;
isRestrictedDelete=false;
isSortable=true;
isUnique=false;
isUpdateable=false;
isWriteRequiresMasterRead=false;
1

If you call the REST API SObject Describe for Campaign I think you'll get a bit more info on your fields, including a Boolean value for "calculated". Making use of that and the calculatedFormula field should allow you to determine it is a system calculated value and not a formula field. Might check the updateable value too, Rollup Summary should be updateable: false.

  • Does calling the REST API produce a different result than the isCalculated=false; and getCalculatedFormula=null from the DescribeFieldResult? I would expect them to be identical. – Mark Pond Jan 27 '16 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.