I am calling the @InvocableMethod from the Process Builder and @InvocableMethod method is returning the result, how can I take the result and use in Process Builder?  public class GetAccountUsingPhone {      @InvocableMethod     public static List&lt;Account&gt; getAccountsUsingPhone(List&lt;String&gt; phones){         System.debug('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');         System.debug('Phone Values :: '+phones);         List&lt;Account&gt; accounts = [select Id, Name, AccountNumber, Phone from Account where Phone=:phones];         System.debug('Accounts :: '+accounts);         return accounts;     } }
121740
Good morning.  Hopefully this is a simple question, that I've just bone-headedly missed in the documentation.  In process builder how can I access the return value of an Apex InvocableMethod?
20169
Is there a way to soql procesbuilder to tun activation off?  For example  List&lt;Processbuilder&gt; pbColl = new List&lt;Processbuilder&gt;();   Processbuilder pb=[SELECT status FROM Processbuilder WHERE status Active];  for(Processbuilder turnoff : pb){             turnoff.status = false;             pbColl.add(pb)} update pbColl;   If not is there a simple way to turn all activated Processes off/on?
98970
I'm not sure if this is a strange thing to do or not, or if it is some how code smell...but I was wondering if there was a way (some sort of oop pattern would be nice) to "cast" a base type to a form of its derived type. I know this makes little sense as the derived type will have additional functionality that the parent doesn't offer which is in its self not fundamentally sound. But is there some way to do this? Here is a code example to so I can better explain what I"m asking.  public class SomeBaseClass {     public string GetBaseClassName {get;set;}     public bool BooleanEvaluator {get;set;} }  public class SomeDerivedClass : SomeBaseClass {     public void Insert(SqlConnection connection) {           //...random connection stuff           cmd.Parameters["IsItTrue"].Value = this.BooleanEvalutar;           //...     } }  public static void Main(object[] args) {     SomeBaseClass baseClass = new SomeBaseClass();     SomeDerivedClass derClass = (SomeDerivedClass)baseClass;      derClass.Insert(new sqlConnection()); }   I know this seems goofy but is there any way to accomplish something of this sort?
15484
Is it possible to automate the process of picklist values retrieval from the backend?  Here is how I am doing it right now:  @AuraEnabled public static List&lt;String&gt; retrieveMyObjectMyFieldOptions() {     List&lt;String&gt; res = new List&lt;String&gt;();      Schema.DescribeFieldResult fieldResult             = MyObject__c.MyField__c.getDescribe();     List&lt;Schema.PicklistEntry&gt; ple = fieldResult.getPicklistValues();     for(Schema.PicklistEntry f: ple) {         res.add(f.getLabel());         res.add(f.getValue());     }      return res; }   Is it possible to pass two strings to a method and get the same list as above? In other words is it possible to change the signature to the following:   public static retrieveMyObjectMyFieldOptions(String MyObject, String MyField)?
92671
public class ExampleClass {       public static void publishCaseUpdateNotifications(List&lt;Case&gt; cases) {     List&lt;Case_Updated__e&gt; notifications = new List&lt;Case_Updated__e&gt;();     for (Case c: cases) {         notifications.add(new Case_Updated__e(             Case__c = (String)c.Id,             CreatedByName__c = UserInfo.getName(),             CaseNumber__c = c.CaseNumber         ));     }       List&lt;Database.SaveResult&gt; results = EventBus.publish(notifications);      for (Database.SaveResult result : results) {         if (!result.isSuccess()) {             for (Database.Error error : result.getErrors()) {                 System.debug('Error returned: ' +                     error.getStatusCode() +' - '+                     error.getMessage());             }         }       }      }    }   My Test Class: getting error   @isTest   public class ExampleTestClass {    @isTest   static void testClassforExample(){         Case testcase = new Case(Subject ='Test',);      list&lt;Case_Updated__e&gt; caseUpdate =      ExampleClass.publishCaseUpdateNotifications(testcase );       }      }   My Error is Method does not exist or incorrect signature: void publishCaseUpdateNotifications(Case) from the type ExampleTestClass   Please suggest me how to resolve this error.     trigger Cases on Case (after insert) { if(Trigger.isAfter) {     System.debug('I will be replaced shortly!'); }  }   Do we need test class for above trigger. Please suggest me too
105996
When I'm debugging, I often have to deal with methods that does not use an intermediate variable to store the return value :     private int myMethod_1()    {       return 12;    }     private int myMethod_2()    {       return someCall( someValue );    }   Well, in order to recreate a bug, I often have to change values on the fly. Here, I could want to see what happens when myMethode_1 return zero. Same thing for myMethod_2.  Is there a way to do that without modifying the code ? What I would like to do, it's to place a breakpoint on the return line (or on the closing bracket) and type-in a new return value.  Note : I'm using Visual Studio 2005 and Visual Studio 2008.  Thank !
112048
Background  I'm using  to update some picklist values on the fly. (i.e. Every time a record is inserted/updated/deleted in Table A, I'm adding/subtracting picklist values into a MultiselectePicklist in table B).  Since,     An Apex trigger can execute a callout when the callout is invoked within a method defined as asynchronous: that is, defined with the @future keyword.   I implemented a method with the future annotation, and      For Apex code that is executed asynchronously, such as @future methods, Batch Apex jobs, or scheduled Apex jobs, getSessionId returns null.   so, I needed to pass the session Id as a parameter in the method, I implemented something like:  @future (callout=true) public static void addContactPicklistPreference(List&lt;String&gt; preferences, String sessionId){     Schema.DescribeSObjectResult sObjectDescribe = Contact.sObjectType.getDescribe();     String picklistFieldName = 'Preference__c';                    Picklist_MDT.addPicklistValues(sObjectDescribe, picklistFieldName, artists, sessionId); }  public class Picklist_MDT {      public static void addPicklistValues(Schema.DescribeSObjectResult sObjectDescribe, String picklistFieldName, List&lt;String&gt; picklistValueNames, String sessionId) {         MetadataService.MetadataPort service = createService(sessionId);         ...         }       public static MetadataService.MetadataPort createService(String sessionId) {         MetadataService.MetadataPort service = new MetadataService.MetadataPort();         service.SessionHeader = new MetadataService.SessionHeader_element();         service.SessionHeader.sessionId = sessionId;         return service;     } }   And called the addContactPicklistPreference method from trigger context passing it the UserInfo.getSessionId() value.   Problem  This worked just fine in salesforce classic but not in lightning, when it triggers in lightning I'm getting System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: INVALID_SESSION_ID.... Funny thing is that if I put a System.debug(UserInfo.getSessionId()); before calling the addContactPicklistPreference method it prints a valid session Id in both classic and lightning.  I would really appreciate any input about this.
29419
There are a group of private methods in my class, and I need to call one dynamically based on an input value. Both the invoking code and the target methods are in the same instance. The code looks like this:  MethodInfo dynMethod = this.GetType().GetMethod("Draw_" + itemType); dynMethod.Invoke(this, new object[] { methodParams });   In this case, GetMethod() will not return private methods. What BindingFlags do I need to supply to GetMethod() so that it can locate private methods?
8665
I am trying to copy records from one org to other via web services. I am calling a class which has logic written into a trigger. But @ future method is not taking sObject  list as a parameter. Can someone suggest me an alternative?  The Code:  public class webServicesTriggerClass   {     @future public static void webServicesMethod(list&lt;MyFriend__c&gt; mfList)     {         partnerSoapSforceCom.Soap sp = new partnerSoapSforceCom.Soap();       partnerSoapSforceCom.LoginResult lr = sp.login('hitesh.kumar.singh@accenture.com.varun','4Rajyavardhan');      soapSforceComSchemasClassNiralaapp.SessionHeader_element ses = new soapSforceComSchemasClassNiralaapp.SessionHeader_element();      ses.sessionId = lr.sessionId;       soapSforceComSchemasClassNiralaapp.MyFriendsDetailSoapApi vNapp=new soapSforceComSchemasClassNiralaapp.MyFriendsDetailSoapApi();      for(MyFriend__c mf:mfList)       {        string  s1= mf.myEmail__c;        string  s2=mf.friendName__c;         string  s3=mf.friendEmail__c;        string  s4=mf.aboutFriend__c;        integer i1=Integer.ValueOf(mf.age__c);        boolean result=vNapp.addFriendDetails(s1,s2,s3,s4,i1);        system.debug('################' +result);           }     }    }     Trigger-->  trigger webServicesTrigger on MyFriend__c (after insert)     {      webServicesTriggerClass.webServicesMethod(trigger.new);    }     Error--    Error: Compile Error: Unsupported parameter type LIST at line 3 column 30
15435
I fear this is probably a bit of a dummy question, but it has me pretty stumped.  I'm looking for the simplest way possible to pass a method of an object into a procedure, so that the procedure can call the object's method (e.g. after a timeout, or maybe in a different thread).  So basically I want to:   Capture a reference to an object's method. Pass that reference to a procedure. Using that reference, call the object's method from the procedure.   I figure I could achieve the same effect using interfaces, but I thought there was another way, since this "procedure of object" type declaration exists.  The following doesn't work, but might it help explain where I'm confused...?  interface    TCallbackMethod = procedure of object;    TCallbackObject = class     procedure CallbackMethodImpl;     procedure SetupCallback;   end;  implementation  procedure CallbackTheCallback(const callbackMethod: TCallbackMethod); begin   callbackMethod(); end;  procedure TCallbackObject.CallbackMethodImpl; begin   // Do whatever. end;  procedure TCallbackObject.SetupCallback; begin   // following line doesn't compile - it fails with "E2036 Variable required"   CallbackTheCallback(@self.CallbackMethodImpl); end;   (Once the question is answered I'll remove the above code unless it aids the explanation somehow.)
44193
I'm making a call:  myResult = MakeMyCall(inputParams, out messages);   but I don't actually care about the messages.  If it was an input parameter I didn't care about I'd just pass in a null.  If it was the return I didn't care about I'd just leave it off.    Is there a way to do something similar with an out, or do I need to declare a variable that I will then ignore?
53785
So, every time I have written a lambda expression or anonymous method inside a method that I did not get quite right, I am forced to recompile and restart the entire application or unit test framework in order to fix it. This is seriously annoying, and I end up wasting more time than I saved by using these constructs in the first place. It is so bad that I try to stay away from them if I can, even though Linq and lambdas are among my favourite C# features.  I suppose there is a good technical reason for why it is this way, and perhaps someone knows? Furthermore, does anyone know if it will be fixed in VS2010?  Thanks.
60385
I was wondering if it is possible to call a batch from a @future method? The reason I am asking as you may have guessed is because I am trying to call batches from a trigger. Eg: Leads are inserted then call batch after insert trigger on Leads.  I know it is possible to call Database.executeBatch, however there is a limitation to the number of batches you can send. With current FlexQueue implementation you can invoke up to 100 batch calls per a transaction.   But my question is what if I need to send more than that per a transaction?  I was thinking of calling a @future method and in that method I call the batch, but I get this error:      System.AsyncException: Database.executeBatch cannot be called from a   batch start, batch execute, or future method.   Pseudocode:  trigger leadTrigger on Lead(after insert) {      //some code      TriggerHelper.callTheBatch();  }   public without sharing class TriggerHelper {      @future      public static void callTheBatch() {          MyBatchClass myBatchClass1 = new MyBatchClass();          Id batchId = database.executebatch(myBatchClass1, 50);      }  }    Any suggestion or idea?
32170
Is there a way to dynamically invoke a method in the same class for PHP? I don't have the syntax right, but I'm looking to do something similar to this:  $this-&gt;{$methodName}($arg1, $arg2, $arg3);
55978
I have a Process Builder flow set up and I am running some tests around the InvocableMethod Apex code. The tests pass fine in my staging and production environments. Yet, when I try to deploy to production, I get a strange error.  CANNOT_EXECUTE_FLOW_TRIGGER, The record couldn’t be saved because it failed to trigger a flow.  Thankfully I received a somewhat more informative error email.  UPSERT FAILED ---  ERRORS :  (CANNOT_EXECUTE_FLOW_TRIGGER) The record couldn’t be saved because it failed to trigger a flow. common.exception.AssertionException: ORA-20070: Cannot read from apex_class and apex_trigger while running tests ---  for SFDC record with ID : null,  Unfortunately, the deployment has nothing to do with the flow and it is unclear why it is failing. What is the root cause of this error and how can I fix it? EDIT: I found out this is a . The other claimed workaround is to deploy via the Metadata API. UPDATE: Because I was subscribed to the Known Issue, I received the following confirmation this issue is resolved.  We are pleased to notify you that the following Known Issue has been resolved: Executing an InvocableMethod during an apex test run from a change set can cause Errors. Thank you for being patient while we worked to address this issue. Please feel free to reach out to Customer Support if you have further questions. Sincerely, Salesforce Success Team
70153
In the code below I tried in two ways to access the parent version of methodTwo, but the result was always 2. Is there any way to get the 1 result from a ChildClass instance without modifying these two classes?  class ParentClass {     public int methodOne()     {         return methodTwo();     }      virtual public int methodTwo()     {         return 1;     } }  class ChildClass : ParentClass {     override public int methodTwo()     {         return 2;     } }  class Program {     static void Main(string[] args)     {         var a = new ChildClass();         Console.WriteLine("a.methodOne(): " + a.methodOne());         Console.WriteLine("a.methodTwo(): " + a.methodTwo());         Console.WriteLine("((ParentClass)a).methodTwo(): "          + ((ParentClass)a).methodTwo());         Console.ReadLine();     } }   Update ChrisW posted this:     From outside the class, I don't know   any easy way; but, perhaps, I don't   know what happens if you try   reflection: use the Type.GetMethod   method to find the MethodInfo   associated with the method in the   ParentClass, and then call   MethodInfo.Invoke   That answer was deleted. I'm wondering if that hack could work, just for curiosity.
107129
I'm trying to get a list of processes currently owned by the current user (Environment.UserName). Unfortunately, the Process class doesn't have any way of getting the UserName of the user owning a process.  How do you get the UserName of the user which is the owner of a process using the Process class so I can compare it to Environment.UserName?   If your solution requires a pinvoke, please provide a code example.