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
Pawan RaiPawan Rai 

Field Update using refresh Button

Hello Everyone, I created some formula field and i try to merge all the field using IF condition, but it Showing error because its to large. So i try to update the field using Apex trigger.

This is my trigger:


trigger TimeZone on Contact (before insert, before update) {

 for (Contact cc :
  if(cc.SP_Place_TimeZone__c =='GMT+05:30')
     cc.Customer_Place_Time__c = cc.Customer_Place_Time1_del__c;
    if(cc.SP_Place_TimeZone__c =='GMT+00:00')
       cc.Customer_Place_Time__c = cc.Customer_Place_Time_00_00_del__c;
    if(cc.SP_Place_TimeZone__c =='GMT+01:00')
       cc.Customer_Place_Time__c = cc.Customer_Place_Time_01_00_del__c;
   if(cc.SP_Place_TimeZone__c =='GMT+03:00')
       cc.Customer_Place_Time__c = cc.Customer_Place_Time_03_00_del__c;
Actually i created 10 formula field like that only :

IF( SP_Place_TimeZone__c ="GMT+00:00" && ISPICKVAL(Customer_place_Time_Zone__c, 'GMT+01:00'), NOW()+(0.041667) ,

IF(ISPICKVAL(Customer_place_Time_Zone__c, 'GMT+02:00'), NOW()+(0.833333),

IF(ISPICKVAL(Customer_place_Time_Zone__c, 'GMT+03:00'), NOW()+(0.125),

IF(ISPICKVAL(Customer_place_Time_Zone__c, 'GMT+04:00'), NOW()+(0.166667),

IF(ISPICKVAL(Customer_place_Time_Zone__c, 'GMT+05:00'), NOW()+(0.208333),

IF(ISPICKVAL(Customer_place_Time_Zone__c, 'GMT+06:00'), NOW()+(0.25),

The main problem is Customer dont want to edit record, he want to just refresh record and update the field.

Can any one help me on this...Please. Please..

Thanks in advance :manhappy:

When using a trigger to change data like this, the only way to get that new data is to update every record.


It looks like you may be able to make your Formula field work, if you are a bit clever with your time calculation.  Instead of using a CASE or a bunch of IF statements, try using some text parsing and a calculation.  Since your timezones are formatted consistently, with GMT+XX:YY, you can calculate how much to add to to NOW() by getting the offset in hours and minutes from the text.  If I understand correctly, you're trying to show the time in the timezone of Customer_place_Time_Zone__c, given the local timezone of SP_Place_TimeZone__c.  In that case, this formula should work:


- (VALUE(MID(SP_Place_TimeZone__c,5,2))+VALUE(RIGHT(SP_Place_TimeZone__c,2))/60)/24
+ (VALUE(MID(Customer_place_Time_Zone__c,5,2))+VALUE(RIGHT(Customer_place_Time_Zone__c,2))/60)/24

I might be off by one on the index for MID(), the documentation doesn't say if it's zero-based or one-based.  In addition, I don't think you'll need any of your other formula fields, so that should save you some headache as well.


I think you might want to change - to +, and vice versa... not sure, as I didn't actually try this out.