Skip to main content
6 answers
  1. Jul 12, 2020, 10:31 PM

    here are some extra steps that may help

    String id= 'KC-012345';

    System.debug('===raw=='+id);

    Integer index = id.lastIndexOf('-');

    String text = id.substring(index+1);

    System.debug('===text=='+ text);

    Integer textToNumber= Integer.valueOf(text);

    System.debug('===text to number==='+ textToNumber);

    textToNumber++;

    System.debug('===new text to number==='+ textToNumber);

    String numberToText = String.ValueOf(textToNumber);

    System.debug('---padded number ---' + numberToText.leftPad(6,'0'));

    String newEmp = 'KC-'+ numberToText.leftPad(6,'0');

    System.debug('new ID '+ newEmp);

    Pardon all the debugs , but if you post it to an Execute Anonymous window you will see exactly what is happening.

    Regards

    Andrew

     
Loading
0/9000