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
gringoesegringoese 

Changing field type based on it's value

Is there a way to change a field type based on it's value? I have a roll-up field that sums Opportunity Quantities but if no Opportunity Products have been entered and therefore the sum is 0 my client would like the field to temporarily be a number field where they can manually enter numbers.

jhurstjhurst

 Field Types cannot be dynamically changed.  There is no easy way to do this in general.  There are a couple of options:

 

1. You can create a formula that displays the value of the number field if the RSF is 0:

 

 IF(NumProductsRSF__c == 0,  CustomNumber__c, NumProductsRSF__c)

 

The issue here if the custom number field wil always be displayed.  You can take the option further by using Visualforce and Apex to conditionally expose the custom field or the RSF on the page layout, but that will be custom coding.

 

2. There actually is a standard field that does what you are describing.  The TotalOpportunityQuantity field will be editable when there are no products, but as soon as you add a single product the value will be overridden to the OppportunityLineItem quantities. 

 

Hope this helps.

 

Jay

gringoesegringoese

Thanks for filling me in on what my options would be. For now I convinced my client to have 2 separate fields so I won't have to change fields on the fly.