forked from mh884/LoadOpenSSLPublicKeyAndEncryptWithRSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProcessBuilderCreatePrefillGuest
53 lines (41 loc) · 2.02 KB
/
ProcessBuilderCreatePrefillGuest
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
global without sharing class ProcessBuilderCreatePrefillGuest {
@InvocableMethod
global static void execute(list<ProcessBuilderPrefillParameters> processBuilderPrefillParameters) {
string siteURL = processBuilderPrefillParameters[0].hostedURLPrefix;
if (string.isEmpty(siteURL)) {
siteURL = null;
}
string formRecordId = processBuilderPrefillParameters[0].formRecordId;
string prefillFieldAPIName = processBuilderPrefillParameters[0].prefillFieldAPIName;
id objectRecordId = Id.valueOf(processBuilderPrefillParameters[0].sfRecordId);
string objectName = objectRecordId.getSObjectType().getDescribe().getName();
list<string> recordIds = new List<string>();
for (ProcessBuilderPrefillParameters objParamters : processBuilderPrefillParameters) {
recordIds.add(objParamters.sfRecordId);
}
map<string,string> prefillUrl = VisualAntidote.FastFormsUtilities.generatePrefillUrlLink(FormRecordId ,recordIds, siteURL);
List<SObject> objsToUpdate = new List<SObject>();
String soql = 'SELECT ID, '+ PrefillFieldAPIName +' FROM '+ objectName +' WHERE ID IN:recordIds';
Map<Id, sObject> objRecordsMap = new Map<Id, sObject>();
objRecordsMap.putAll(Database.query(soql));
for (string recordId : prefillUrl.keyset()) {
if (objRecordsMap.containsKey(recordId)) {
sObject o = objRecordsMap.get(recordId);
string prefillRecordURL = prefillUrl.get(recordId);
o.put(PrefillFieldAPIName, prefillRecordURL);
objsToUpdate.add(o);
}
}
update objsToUpdate;
}
global class ProcessBuilderPrefillParameters {
@InvocableVariable
global string sfRecordId;
@InvocableVariable
global string prefillFieldAPIName;
@InvocableVariable
global string formRecordId;
@InvocableVariable
global string hostedURLPrefix;
}
}