I am trying to copy a Rich Text Field (32k)
into multiple Rich Text Field (2k)
. I get this error:
System.StringException: Ending position out of bounds:2000.
Code
trigger UpdateCaseResponse on Case (before update) {
for(Case c: trigger.new ){
if (c.Response__c != null)
if(c.Response__c != Trigger.oldMap.get(c.Id).Response__c )
try{
c.Response_Part1__c = c.Response__c.substring(0,2000);
c.Response_Part2__c = c.Response__c.substring(2001,4000);
}
catch (System.NullPointerException e) {
}
}
}
Best Answer
As an alternative to using substring, you can also use Pattern/Matcher:
This avoids substring exceptions and a particularly nasty set of if statements.