March 17, 2020

String Split method in Apex in Salesforce

Sample Code:

String str = 'abc-xyz-123';
List < String > strList = str.split( '-' );
System.debug( 'List String is ' + strList );


Output:


2 comments:

  1. Hi,

    Hope you are doing well!

    How can i pass this. i have custom label which is having two email address and i need to pass this in toaddress. But i am getting an error like below

    Initial expression is of incorrect type, expected: String but was: List

    Code starts from:

    string toaddressList =label.ADM_Rm_OtherAdddress;
    String[] toaddresssplit =toaddressList.split(',');

    String[]toAddresses = new String[] {toaddresssplit};

    ReplyDelete
    Replies
    1. Use toAddresses = toAddresssplit; and let me know whether it works.

      Delete