-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsfApexClass
30 lines (28 loc) · 1.21 KB
/
sfApexClass
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
public class ReplaceSpecialCharactersWithDashes {
// Define a class to handle input
public class Request {
@InvocableVariable(label='Input Text' description='Text to process')
public String inputText;
}
// Define a class to handle output
public class Response {
@InvocableVariable(label='Processed Text')
public String outputText;
}
// Invocable method to replace special characters
@InvocableMethod(label='Replace Special Characters' description='Replaces all special characters except hyphens with a hyphen in the given text.')
public static List<Response> replaceSpecialChars(List<Request> requests) {
List<Response> responses = new List<Response>();
for (Request request : requests) {
Response response = new Response();
// Check if inputText is null before replacing characters
if (request.inputText != null) {
response.outputText = request.inputText.replaceAll('[^a-zA-Z0-9-]', '-');
} else {
response.outputText = null; // Explicitly set to null if inputText is null
}
responses.add(response);
}
return responses;
}
}