Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

Salesforce create account Json

SumathiSomala
All-Star
All-Star

Hi ,
I am using below create account jSON to create account in Salesforce.
I need help to create logic for Alias attribute.

{
"Alias": "${user.firstname.toString().substring(0,1)}${user.lastname.toString().substring(0,4)}",
"Email":"${user?.getEmail()}",
"Username":"${user?.getEmail()}",
"CommunityNickname":"${user?.getFirstname()}${user?.getLastname()}",
"FirstName":"${user?.getFirstname()}",
"LastName":"${user?.getLastname()}",
"TimeZoneSidKey":"America/Los_Angeles",
"LocaleSidKey":"en_US",
"EmailEncodingKey":"ISO-8859-1",
"ProfileId":"${profileId}",
"LanguageLocaleKey":"en_US",
"IsActive":true,
"FederationIdentifier":"${user?.getEmail()}"
}

Alias should print as below.

if users last name length is greater than or equal 4
Firstname: Queng
lastname:richard
Alias: qrich

if users last name length is less than 4 characters
Firstname: Queng
lastname:Le
Alias: qle

i have observed that if users last name is less than the 4 characters pending tasks are not completed with exception

Error in creating user= String index out of range:4

Regards,
Sumathi Somala
If this reply answered your question, please Accept As Solution and give Kudos.
3 REPLIES 3

naveenss
All-Star
All-Star

Hi @SumathiSomala  please find the below logic for Alias. Please make the necessary changes as per your requirement.

"Alias": "${if(user?.lastname!=null && user?.lastname.length()>=4){user?.lastname.toLowerCase().substring(0,4)}else if(user?.lastname!=null && user?.lastname?.length()<4){user?.lastname.toLowerCase()}}",

Let me know if this helps!

 

Regards,
Naveen Sakleshpur
If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.

SumathiSomala
All-Star
All-Star

Thank you @naveenss 

I made small change to this as per my requirement. It is working as excepted. 

"Alias": "${if(user?.lastname!=null && user?.lastname.length()>=4){user?.firstname.toLowerCase().substring(0,1)+user?.lastname.toLowerCase().substring(0,4)}else if(user?.lastname!=null && user?.lastname?.length()<4){user?.firstname.toLowerCase().substring(0,1)+user?.lastname.toLowerCase()}}",

 

Just wanted to know what the difference is between user.lastname and user?.lastname

Regards,
Sumathi Somala
If this reply answered your question, please Accept As Solution and give Kudos.

@SumathiSomala thanks for confirming. 

In user?.lastname, the ? operator is used for null check. This is a groovy shorthand to avoid any null pointer exceptions. 

 

Regards,
Naveen Sakleshpur
If this reply answered your question, please click the Accept As Solution button to help future users who may have a similar problem.