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
vivekjainvivekjain 

Apex trigger for replacing a formula

I am trying to write an trigger for a fomula calculation as it is hitting the character limits.

 

Formula is:

Value(CASE( LEN( text( Area_Range__c ) ), 5, Left(text(Area_Range__c ), 1), 6, Left(text(Area_Range__c ), 1), 7, Left(text(Area_Range__c ), 2), 8, Left(text(Area_Range__c ), 2), 9, Left(text(Area_Range__c ), 3), 10, Left(text(Area_Range__c ), 3), 11, Left(text(Area_Range__c ), 4), 12, Left(text(Area_Range__c ), 4), 13, Left(text(Area_Range__c ), 5), 14, "0", 15, "50000", 16, "750","0"))

 now the trigger is something like this

trigger PropertyValue on Property__c (before insert, before update) {

    Property__c thisProp;
    {
    for(Property__c prop: Trigger.New)
    
  {
  	list<Property__c> propNew=[select id, test_1__c, Budget_Range__c from Property__c];
  	 {
  	 	    if(propNew.Budget__c=='ABC')
    	
    {
				prop.test_1__c = CASE( LEN( text( prop.Budget_Range__c ) ), 5, Left(text(prop.Budget_Range__c ), 1), 6, Left(text(prop.Budget_Range__c ), 1), 7, Left(text(prop.Budget_Range__c ), 2), 8, Left(text(prop.Budget_Range__c ), 2), 9, Left(text(prop.Budget_Range__c ), 3), 10, Left(text(prop.Budget_Range__c ), 3), 11, Left(text(prop.Budget_Range__c ), 4), 12, Left(text(prop.Budget_Range__c ), 4), 13, Left(text(prop.Budget_Range__c ), 5));
			    
			}

}
}
    }
}

 It is giving error 

Save error: Method does not exist or incorrect signature: text(String) PropertyValue.trigger /src/triggers line 13 Force.com save problem

Nilesh ManeNilesh Mane

what you want to do by using text(string) method ?

vivekjainvivekjain

my aim is to assign value to a field based on certain formula calculations when the custom object record is inserted.

for formula i can am using CASE. which is suppose to be numeric value.

these is nothing specific about text(string)