1

I'm trying to find a way to break up a string in a Custom Salesforce field (CID__c) and return a portion of that field to another cell (for examples sake....Test__c).

The String will be in the structure 'A:B:C:D:E:F:G:H:I:J', where I'd always want to return the text between the 6th and 7th delimiter (:). For example if CID__c equals "dd:cm:qa:aw:0na0:wa:qa:vw:pp", I'd want to return "qa" and pass it to an external field Test__c.

This operation should only be completed if CID__c is not null.

I'm a complete novice when it comes to any Apex code but I've checked out the different String methods. The Split String method doesn't seem too difficult, but it appears that it will return all the text fields broken up by the : delimiter.

Any help would be much appreciated!!

1

Yes, String.split() is returning String[] but you can access the element you need.

String str = 'dd:cm:qa:aw:0na0:wa:qa:vw:pp';
String[] myArr = str.split(':');
String str2;

if(myArr != null && myArr.size()>5){
  str2 = myArr[6];  
}

// assign this str2 to your other field as you want
  • Cool. Kindly mark this as answer so that others won't spend their time to read the post and replying which is already answered. – highfive Aug 28 '14 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.