+ Start a Discussion

Split a name?

I have an Object which the Name field starts with "AO-" Now within that is an autonumber. So the field would say for a record after created is AO-01856. How in an Apex Class just get the number from here and not the AO.

I am trying to create a new record for the child object which relates to the parent object.



String has split() function, so name.split('-')[1] should be fine (but you should add more check just in case).




string numstring = name.substring(3);


integer numvalue = integer.valueOf(numstring);

Message Edited by jpwagner on 09-22-2009 04:34 PM