SHARE
TWEET

Untitled

a guest Jun 25th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String strClass = 'BatchUtil';
  2. String strMethod = 'updateAccounts'
  3.      
  4. ExecuteAnonymousResult[] = binding.executeanonymous(string apexcode);
  5.      
  6. string output = soapSforceCom200608Apex.evalString('string first = 'foo'; string second = 'bar'; string result = first + second; System.debug(LoggingLevel.Error, result);');  
  7. System.assertEquals('foobar', output);  
  8. System.debug(output);
  9.      
  10. > ToolingAPI x = new ToolingAPI(); ToolingAPI.ExecuteAnonymousResult
  11. > toolingResult = x.executeAnonymousUnencoded("Your apex code as a
  12. > string here");
  13.      
  14. public class Extension implements Callable {
  15.  
  16.    // Actual method
  17.    String concatStrings(String stringValue) {
  18.      return stringValue + stringValue;
  19.    }
  20.  
  21.    // Actual method
  22.    Decimal multiplyNumbers(Decimal decimalValue) {
  23.      return decimalValue * decimalValue;
  24.    }
  25.  
  26.    // Dispatch actual methods
  27.    public Object call(String action, Map<String, Object> args) {
  28.      switch on action {
  29.        when 'concatStrings' {
  30.          return this.concatStrings((String)args.get('stringValue'));
  31.        }
  32.        when 'multiplyNumbers' {
  33.          return this.multiplyNumbers((Decimal)args.get('decimalValue'));
  34.        }
  35.        when else {
  36.         throw new ExtensionMalformedCallException('Method not implemented');
  37.        }
  38.      }
  39.    }
  40.  
  41.    public class ExtensionMalformedCallException extends Exception {}
  42. }
  43.      
  44. @IsTest
  45. private with sharing class ExtensionCaller {
  46.  
  47.    @IsTest
  48.    private static void givenConfiguredExtensionWhenCalledThenValidResult() {
  49.  
  50.       // Given
  51.       String className = 'Extension'; // Variable to demonstrate setting class name
  52.       String methodName = 'multiplyNumbers'; // Variable to demonstrate setting method name
  53.       Decimal decimalTestValue = 10;
  54.  
  55.       // When
  56.       Callable extension = (Callable) Type.forName(className).newInstance();
  57.       Decimal result = (Decimal) extension.call(methodName, new Map<String, Object> { 'decimalValue' => decimalTestValue });
  58.  
  59.       // Then
  60.       System.assertEquals(100, result);
  61.    }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top