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
Ankit KhuranaAnkit Khurana 

how to do this..

 

"There is a text box on case page layout. User can enter text into it. Whenever user type <today> in the text, while saving the case, today should be replaced by today’s date" 

 

 

I tried this trigger but it works only when new case is created..but donot when case is edited.

trigger dateconvert on Case (after insert)
{
 
  for(Case case1:System.Trigger.new)
  {
  Case ca=[select Enter_text__c from Case where CaseNumber =:case1.CaseNumber  ];
  date myDate = date.today();
  String abc = myDate .format();
  String NewEntry=ca.Enter_text__c.replaceAll('today',abc);
    ca.Enter_text__c=NewEntry;
  update ca;
  }
    
 
}

HariDineshHariDinesh

Hi,

 

Here you forgot to include update Event for trigger, then how it will work for update operation.

 

Write Update trigger event for the trigger. then it will work for update operation also.

 

 

trigger dateconvert on Case (after insert,before update)
{
 if(trigger.isafter)
 {
  for(Case case1:System.Trigger.new)
  {
  Case ca=[select Enter_text__c from Case where CaseNumber =:case1.CaseNumber  ];
  date myDate = date.today();
  String abc = myDate .format();
  String NewEntry=ca.Enter_text__c.replaceAll('today',abc);
    ca.Enter_text__c=NewEntry;
  update ca;
  }
  }
  
  if(trigger.isbefore )
  {
   if(trigger.isupdate)
   {
     for(case as1 : trigger.new)
      {
       
         as1.Enter_text__c = string.valueof(date.today());
      
        }
    }
  }
    
 
}

 

Ankit KhuranaAnkit Khurana

Hi Haridinesh,

 

The above only converts the whole line to todays date.....not like iif line is 'today is Monday"---->>>>"10/9/2012 is Monday"

HariDineshHariDinesh

Hi,

 

Yes, by observing the code I told that.

But as per your description in first post 

"Whenever user type <today> in the text, while saving the case, today should be replaced by today’s date" 

 

There is no such condition like that is what am saying.

 

OK, if you don't what that condition leave it.

 

Does your question is answered by my post or not, or you looking for something other? 

Ankit KhuranaAnkit Khurana

Haridinesh..

 

my code is working for new case .Can you help me so that it also work of existing record.

here is exact screnerio...

"There is a text box on case page layout. User can enter text into it. Whenever user type <today> in the text, while saving the case, today should be replaced by today’s date."

HariDineshHariDinesh

Hi,

 

The above code in my post will do that thing.

it will work for Existing record.

 

But one thing we need to add is check like whether enterted text is <today> or not.

 

Add below code to the above posted code.

 

for(case as1 : trigger.new)
{
   if(as1.Enter_text__c == '%<today>%')
         as1.Enter_text__c = string.valueof(date.today());

}

 

so Find complete code

 

trigger dateconvert on Case (after insert,before update)
{
 if(trigger.isafter)
 {
  for(Case case1:System.Trigger.new)
  {
  Case ca=[select Enter_text__c from Case where CaseNumber =:case1.CaseNumber  ];
  date myDate = date.today();
  String abc = myDate .format();
  String NewEntry=ca.Enter_text__c.replaceAll('today',abc);
    ca.Enter_text__c=NewEntry;
  update ca;
  }
  }
  
  if(trigger.isbefore )
  {
   if(trigger.isupdate)
   {
     for(case as1 : trigger.new)
      {
        if(as1.Enter_text__c == '%<today>%')
            as1.Enter_text__c = string.valueof(date.today());
      
        }
    }
  }
    
 
}

 

 


}