0

This question may have been asked but I don't find perfect solution so I am posting here. I have to Automate a sales force application and have to create new customer data every time I execute a script. I want to create such that customer name is unique eg: customer 123 etc.

What is best way I can achieve this in Java. I searched SO and Google but they only give alpha numeric random string and I don't want my customer number to look clumsy.

CodingGirl1
  • 21
  • 2
  • 5

1 Answers1

0

There are a few ways actually:

  1. Delete all previous users with given name at the beginning of script execution, and recreate users with the same names. That way you can reuse their names.

  2. Get all users, sort them, see which number was used last, and use the next number.

Both of these options do not really depend on Java features, butmore on logic of names you are creating and maintaining. Two options below generate some integer ID:

  1. Use date/time as your number. For example:

    SimpleDateFormat timestamp = new SimpleDateFormat("yyyyMMddHHmmssSSS");
    String username = "user" + timestamp.format(new Date());
    

    This would give you names like user20181122101458234 unique to millisecond, and also not random.

  2. You can also use Java's UUID as your number (see idea here):

    String username = "user" + new BigInteger(UUID.randomUUID().toString().replaceAll("-", ""), 16).toString()
    

    This would generate name of type user[some big number], which is quite unique

timbre timbre
  • 12,648
  • 10
  • 46
  • 77