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
JoshTonksJoshTonks 

Can i use a apex Map in place of formula

I've been asked to look into this and investigate possible replacement methods to elimate the issue we are having this was all set up prior to my starting at the company.

The below formula is used in determining the GP a sales rep generates for the company and for themself. We havn't enough space in a formula field to do all of it as it essentially needs to contain any value of months. We have to keep changing them round on a daily basis. This is just a sample of the whole formula. I was wondering if i could do any with map in apex to overcome the the problem. We have a workflow update that only runs when the opp is set to "Closed Won".
 
CASE(1,
  IF(ISPICKVAL(Term__c, "3 months"),1,0) , 3,
  IF(ISPICKVAL(Term__c, "4 months"),1,0) , 4,
  IF(ISPICKVAL(Term__c, "12 months"),1,0) , 12,
  IF(ISPICKVAL(Term__c, "24 months"),1,0) , 24,
  IF(ISPICKVAL(Term__c, "36 months"),1,0) , 36,
  IF(ISPICKVAL(Term__c, "48 months"),1,0) , 48,
I am open to any suggestion on how to tackle this if this can be done without the use of extra fields this would be ideal as we don't have any available fields on the object.
GauravGargGauravGarg
Hi Tonks,
We can use Custom setting / custom metadata types to resolve this issue. 

Basically we create custom metadata type with all the possible values. 
Fields:
  1. Name  (2 months)
  2. Value: (2)

We will query this Metadata based on Term__c selected and put this value in any field you require and call your workflow based on it. 

We can discuss more options, you can connect with me (e) gauravgarg.nmims@gmail.com, (skype) gaurav62990

Thanks,

Gaurav