**Create a new before insert trigger to do below action:​

Read ‘Event Name’ field and split the text based on ‘(‘ character. Read the last value of array then remove ‘)’ from it.**​

I have tried this so far. I am not sure where it is correct or not.

trigger myTrigger on Timecard__c (before insert) 
   for (Timecard__c timeCard : Trigger.new) 
      string one = timeCard.Event_Name__C;
      String[] bits = one.split("(");
      String lastOne = bits[bits.length-1];

Can you please help me how to Read the last value of array then remove ‘)’ from it.​

1 Answer 1


Just use substringBetween:

String one = timeCard.Event_Name__c.substringBetween('(',')');
  • Then how can we get last value of array?
    – Pooh
    Aug 27, 2020 at 6:03
  • @Pooh No split, no array, just use the method designed for the purpose you're looking for.
    – sfdcfox
    Aug 27, 2020 at 6:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .