-
Notifications
You must be signed in to change notification settings - Fork 0
/
EinsteinChatbotsUpdatePhone.cls
37 lines (35 loc) · 1.52 KB
/
EinsteinChatbotsUpdatePhone.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
global class EinsteinChatbotsUpdatePhone
{
@InvocableMethod(label='Einstein Chatbots - Update Phone' description='Allows the user to change the Phone number for their Community User and Contact')
global static List<Contact> updatePhone(List<UpdateStringRequest> requests)
{
List<Contact> results = new List<Contact>();
For (UpdateStringRequest request : requests)
{
system.debug('property value:' + request.value);
if (request.objContact != null && request.objContact.Id != null && String.IsNotBlank(request.value))
{
Contact currentContact = request.objContact;
currentContact.Phone = request.value;
update currentContact;
//Update user Phone
List<User> CommunityUser = [SELECT Id, email, Phone FROM USER WHERE ContactId =: request.objContact.id LIMIT 1];
if (CommunityUser != null && CommunityUser.size() > 0)
{
User CurrentUser = CommunityUser[0];
currentUser.Phone = request.value;
update currentUser;
}
return new List<Contact>{currentContact};
}
}
return new List<Contact>{requests[0].objContact};
}
global class UpdateStringRequest
{
@InvocableVariable(required=true)
global string value;
@InvocableVariable(required=true)
global Contact objContact;
}
}