-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
not ready for consumption at the moment.
Signed-off-by: kpoorman <kjp@codefriar.com>
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
force-app/main/default/classes/experiments/AutoCallable.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Created by kpoorman on 10/2/23. | ||
*/ | ||
|
||
public with sharing class AutoCallable { | ||
public Map<String, Map<String, Object>> findCallableMethods( | ||
String className | ||
) { | ||
if (!isValidClass(className)) { | ||
throw new AutoCallableException('Invalid Class Name'); | ||
} | ||
|
||
ApexClass apexClass = [ | ||
SELECT Id, Name, Body | ||
FROM ApexClass | ||
WHERE Name = :className | ||
WITH SYSTEM_MODE | ||
]; | ||
Pattern publicMethodSignatureMatcher = Pattern.compile( | ||
'public\\s+(?!static\\s+)(\\w+)\\s+(\\w+)\\s*\\([^\\)]*\\)' | ||
); | ||
Matcher publicMethodSignatures = publicMethodSignatureMatcher.matcher( | ||
apexClass.Body | ||
); | ||
Map<String, Map<String, Object>> methodMap = new Map<String, Map<String, Object>>(); | ||
while (publicMethodSignatures.find()) { | ||
System.debug( | ||
'#### found Signature ' + publicMethodSignatures.group() | ||
); | ||
String methodSignature = publicMethodSignatures.group(); | ||
methodSignature = methodSignature.replace('(', ' ') | ||
.replace(')', ''); | ||
System.debug('#### methodSignature without () ' + methodSignature); | ||
String[] parts = methodSignature.split(' ', 3); | ||
|
||
String methodReturnType = parts[1]; | ||
System.debug('#### methodReturnType ' + methodReturnType); | ||
String methodName = parts[2]; | ||
System.debug('#### methodName ' + methodName); | ||
String methodParams = parts[3] != null ? parts[3] : ''; | ||
System.debug('#### methodParams ' + methodParams); | ||
Map<String, Object> methodInfo = new Map<String, Object>(); | ||
methodInfo.put('name', methodName); | ||
methodInfo.put('params', methodParams); | ||
methodMap.put(methodName, methodInfo); | ||
} | ||
return methodMap; | ||
} | ||
|
||
public Boolean isValidClass(String className) { | ||
Type isType = Type.forName(className); | ||
return isType != null; | ||
} | ||
|
||
public class AutoCallableException extends Exception { | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
force-app/main/default/classes/experiments/AutoCallable.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>58.0</apiVersion> | ||
<status>Active</status> | ||
</ApexClass> |