function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
VKrishVKrish 

Validation Error: Field Community_Registrant__c may not be used in this type of formula

Hello,

 

I am trying to create a default value for a text field using formula.

I am using a custom field in the formula to have the text value accordingly.

The custom field I am using is a look up field. This is what I tried..

 

IF(NOT ISBLANK(Community_Registrant__c) , "Has Web Access", "" )

 

Error says Field may not be used in this type of formula!

I even tried using standard field in place of custom field. I still get the same error.

 

I have used formula to specify default value of custom fields before.

What am I doing wrong in this case?

Any help is appriciated

 

Thanks in advance

Vidhya

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

You can't use a field value from the current record in a default value formula, as the record is null and has no data when the page is rendered, and so it would never have any value loaded. You probably want a Formula Field instead, as it is rendered on each successful data access request (on-the-fly), and would show the correct value. Default Field Value formulas are useful for things like: A number of days from some known value (usually today), a default string to show, some default number for a known calculation, etc. Their utility is largely limited by the fact that you can only use variables known during initialization, such as user information, organization information, and other items that can be calculated with no dependency on the state of the record.

 

Edit: Someone beat me to it, so feel free to disregard.

All Answers

SeAlVaSeAlVa

You cannnot use fields in default-value formulas.

 

Reason: Default-value is caluclated when the "new page" is loaded.

if you use a field on it, you might change the value of the field you are using, and that will

a) force Salesforce to recalculate the default value.

b) don't touch the default value prompted (what would be bad too).

 

You will be able to achieve this functionality with Visualforce (either with rerender or javascript)

 

Regards.

VKrishVKrish

Thanks!

I am using a trigger to update the custom field value that I am using in this formula. I can also update this text field in same trigger.

I was trying this default value through formula field just to avoid coding as much as possible.

sfdcfoxsfdcfox

You can't use a field value from the current record in a default value formula, as the record is null and has no data when the page is rendered, and so it would never have any value loaded. You probably want a Formula Field instead, as it is rendered on each successful data access request (on-the-fly), and would show the correct value. Default Field Value formulas are useful for things like: A number of days from some known value (usually today), a default string to show, some default number for a known calculation, etc. Their utility is largely limited by the fact that you can only use variables known during initialization, such as user information, organization information, and other items that can be calculated with no dependency on the state of the record.

 

Edit: Someone beat me to it, so feel free to disregard.

This was selected as the best answer