and more in a single search tool across platforms. Read the announcement here. |
08/02/2023 10:25 AM
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
Solved! Go to Solution.
08/02/2023 10:18 PM - edited 08/02/2023 10:19 PM
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!
08/02/2023 11:45 PM
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
08/03/2023 12:27 AM
@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.