Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String strClass = 'BatchUtil';
- String strMethod = 'updateAccounts'
- ExecuteAnonymousResult[] = binding.executeanonymous(string apexcode);
- string output = soapSforceCom200608Apex.evalString('string first = 'foo'; string second = 'bar'; string result = first + second; System.debug(LoggingLevel.Error, result);');
- System.assertEquals('foobar', output);
- System.debug(output);
- > ToolingAPI x = new ToolingAPI(); ToolingAPI.ExecuteAnonymousResult
- > toolingResult = x.executeAnonymousUnencoded("Your apex code as a
- > string here");
- public class Extension implements Callable {
- // Actual method
- String concatStrings(String stringValue) {
- return stringValue + stringValue;
- }
- // Actual method
- Decimal multiplyNumbers(Decimal decimalValue) {
- return decimalValue * decimalValue;
- }
- // Dispatch actual methods
- public Object call(String action, Map<String, Object> args) {
- switch on action {
- when 'concatStrings' {
- return this.concatStrings((String)args.get('stringValue'));
- }
- when 'multiplyNumbers' {
- return this.multiplyNumbers((Decimal)args.get('decimalValue'));
- }
- when else {
- throw new ExtensionMalformedCallException('Method not implemented');
- }
- }
- }
- public class ExtensionMalformedCallException extends Exception {}
- }
- @IsTest
- private with sharing class ExtensionCaller {
- @IsTest
- private static void givenConfiguredExtensionWhenCalledThenValidResult() {
- // Given
- String className = 'Extension'; // Variable to demonstrate setting class name
- String methodName = 'multiplyNumbers'; // Variable to demonstrate setting method name
- Decimal decimalTestValue = 10;
- // When
- Callable extension = (Callable) Type.forName(className).newInstance();
- Decimal result = (Decimal) extension.call(methodName, new Map<String, Object> { 'decimalValue' => decimalTestValue });
- // Then
- System.assertEquals(100, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement