mcheek
(Mark Cheek)
June 19, 2023, 1:41pm
1
When trying to create a new user in SalesForce, one of the requirements is generating a value for the Alias field.
Here are the SalesForce requirements for that field
For the Create profile, I’m just taking the first 8 characters of the identityAttribute uid
{
"name": "Alias",
"transform": {
"name": "SalesForce Username Generator",
"type": "static",
"attributes": {
"salesForceUsername": {
"attributes": {
"name": "uid"
},
"type": "identityAttribute"
},
"value": "$salesForceUsername.substring(0,8)"
}
},
"attributes": {},
"isRequired": false,
"type": "string",
"isMultiValued": false
}
This seems to work fine for some users, but I sometimes see this error when it’s trying to create an account and it’s not super helpful… any ideas?
"errorMessages": [
[
{
"locale": "en-US",
"localeOrigin": "DEFAULT",
"text": "An unexpected error occurred: Error rendering template: $salesForceUsername.substring(0,8)"
}
]
]
The KB article I found isn’t super helpful
sharvari
(Sharvari Bharatiya)
June 19, 2023, 2:34pm
2
Its probably because sometimes your uid could be null/empty or less than 8 characters.
1 Like
mcheek
(Mark Cheek)
June 19, 2023, 2:44pm
3
Null probably won’t happen, but fewer than 8 characters might. I need to look at my non-prod environments and see if I can reproduce this. I think it worked fine with my username (mcheek), but I would have to check.
Is this a situation where you would have to check the length of the uid and if it’s < 8, plug it into the substring?
sharvari
(Sharvari Bharatiya)
June 19, 2023, 2:51pm
4
Yes, that would be way to go. You can achieve that with a combination of Get End of String, First Valid and Sub String transforms.
mcheek
(Mark Cheek)
June 19, 2023, 3:06pm
5
Could this also be done using Velocity?
{
"name": "Alias",
"transform": {
"name": "SalesForce Username Generator",
"type": "static",
"attributes": {
"uid": {
"attributes": {
"name": "uid"
},
"type": "identityAttribute"
},
"value": "#set($uidLength = $uid.length()) #if($uidLength < 8) $uid.substring(0,$uidLength) #else $uid.substring(0,8) #end"
}
},
"attributes": {},
"isRequired": false,
"type": "string",
"isMultiValued": false
}
atarodia
(Animesh Tarodia)
June 19, 2023, 3:15pm
6
Yes, it can be done using Velocity.
Tested this and it works
{
"type": "static",
"attributes": {
"salesForceUsername": {
"attributes": {
"name": "uid"
},
"type": "identityAttribute"
},
"value": "#if($salesForceUsername.length()<8)$salesForceUsername.substring(0,$salesForceUsername.length())#{else}$salesForceUsername.substring(0,8)#end"
},
"internal": false
}
2 Likes
mcheek
(Mark Cheek)
June 19, 2023, 3:20pm
7
Animesh Tarodia:
"type": "static",
"attributes": {
"salesForceUsername": {
"attributes": {
"name": "uid"
},
"type": "identityAttribute"
},
"value": "#if($salesForceUsername.length()<8)$salesForceUsername.substring(0,$salesForceUsername.length())#{else}$salesForceUsername.substring(0,8)#end"
},
"internal": false
Thanks @atarodia , that worked!
1 Like
could you not simplify this line
"value": "#if($salesForceUsername.length()<8)$salesForceUsername.substring(0,$salesForceUsername.length())#{else}$salesForceUsername.substring(0,8)#end"
as
"value": "#if($salesForceUsername.length()<8)$salesForceUsername#{else}$salesForceUsername.substring(0,8)#end"
1 Like
atarodia
(Animesh Tarodia)
June 19, 2023, 9:25pm
9
@iamnithesh Yes, it does makes sense. Thank you
system
(system)
Closed
August 18, 2023, 9:26pm
10
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.