In order to create a simple event bus to implement a communication infrastructure for microservice I hit this question:  How can I invoke multiple Action with different generic types?
1947
What's the best way to call a generic method when the type parameter isn't known at compile time, but instead is obtained dynamically at runtime?  Consider the following sample code - inside the Example() method, what's the most concise way to invoke GenericMethod&lt;T&gt;() using the Type stored in the myType variable?  public class Sample {     public void Example(string typeName)     {         Type myType = FindType(typeName);          // What goes here to call GenericMethod&lt;T&gt;()?         GenericMethod&lt;myType&gt;(); // This doesn't work          // What changes to call StaticMethod&lt;T&gt;()?         Sample.StaticMethod&lt;myType&gt;(); // This also doesn't work     }      public void GenericMethod&lt;T&gt;()     {         // ...     }      public static void StaticMethod&lt;T&gt;()     {         //...     } }
90674
I'll confess up front that my knowledge of event architecture is limited:  Can the cometd library that we can use to listen for Streaming API and Platform Events also be used to listen to external (i.e. non-Salesforce) event buses?  We're hoping to make Salesforce a subscriber to replace polling integrations through the REST API.
7972
I am trying all my level best to know how the Tooling API is used. Can someone suggest or show me with a small example on how do I create a apexClass in a controller method.   I have already generated metadataservice from WSDL.
89212
Method chaining is the only way I know to build fluent interfaces. Here's an example in C#: John john = new JohnBuilder()     .AddSmartCode(&quot;c#&quot;)     .WithfluentInterface(&quot;Please&quot;)     .ButHow(&quot;Dunno&quot;);  Assert.IsNotNull(john);    [Test]     public void Should_Assign_Due_Date_With_7DayTermsVia_Invoice_Builder()     {         DateTime now = DateTime.Now;          IInvoice invoice = new InvoiceBuilder()             .IssuedOn(now)             .WithInvoiceNumber(40)             .WithPaymentTerms(PaymentTerms.SevenDays)             .Generate();          Assert.IsTrue(invoice.DateDue == now.AddDays(7));     }  So how do others create fluent interfaces. How do you create it? What language/platform/technology is needed?
43162
I have two different @wire methods that are calling Apex methods to get different results from two different objects.  After this information has been retrieved by each @wire respectively, I'd like to afterwards compare the results and set a few other attributes on the page.  How do I achieve this?  Should I use connectedCallback() or renderedCallback() or neither?  Is there a better way to do multiple Apex method calls then process them afterwards within the JS when the component loads?  I'm hoping there's a graceful way to accomplish this in LWC without having to chain Promises, or having to handle all of this within a single Apex method call.
44387
I am looking for good ideas for implementing a generic way to have a single line (or anonymous delegate) of code execute with a timeout.  TemperamentalClass tc = new TemperamentalClass(); tc.DoSomething();  // normally runs in 30 sec.  Want to error at 1 min   I'm looking for a solution that can elegantly be implemented in many places where my code interacts with temperamental code (that I can't change).  In addition, I would like to have the offending "timed out" code stopped from executing further if possible.
69671
I've been looking at ways to implement gmail-like messaging inside a browser, and arrived at the  concept. However, I haven't been able to find a good .NET implementation that allows me to do this within IIS (our application is written in ASP.NET 2.0).   The solutions I found (or could think of, for that matter) require leaving a running thread per user - so that it could return a response to him once he gets a message. This doesn't scale at all, of course.  So my question is - do you know of an ASP.NET implementation for Comet that works in a different way? Is that even possible with IIS?
16158
Consider this example (typical in OOP books):    I have an Animal class, where each Animal can have many friends. And subclasses like Dog, Duck, Mouse etc which add specific behavior like bark(), quack() etc.  Here's the Animal class:  public class Animal {     private Map&lt;String,Animal&gt; friends = new HashMap&lt;&gt;();      public void addFriend(String name, Animal animal){         friends.put(name,animal);     }      public Animal callFriend(String name){         return friends.get(name);     } }   And here's some code snippet with lots of typecasting:  Mouse jerry = new Mouse(); jerry.addFriend("spike", new Dog()); jerry.addFriend("quacker", new Duck());  ((Dog) jerry.callFriend("spike")).bark(); ((Duck) jerry.callFriend("quacker")).quack();   Is there any way I can use generics for the return type to get rid of the typecasting, so that I can say      jerry.callFriend("spike").bark(); jerry.callFriend("quacker").quack();   Here's some initial code with return type conveyed to the method as a parameter that's never used.   public&lt;T extends Animal&gt; T callFriend(String name, T unusedTypeObj){     return (T)friends.get(name);         }   Is there a way to figure out the return type at runtime without the extra parameter using instanceof? Or at least by passing a class of the type instead of a dummy instance. I understand generics are for compile time type-checking, but is there a workaround for this?
15717
I'd like to do something like this:  &gt;&gt; foo = @() functionCall1() functionCall2()   So that when I said:  &gt;&gt; foo()   It would execute functionCall1() and then execute functionCall2().  (I feel that I need something like the )  EDIT:  functionCall1 and functionCall2 are not necessarily functions that return values.
52925
I built a custom form that saves the data to multiple lists with on click; it works pretty well for its intended use (keeping the data related). Thing is I am totally new at jQuery and SPServices, but am learning.   I would like to know if SPService/jQuery will allow me to use the aspx control to upload a single document to a library? I have seen plugins out there for multiple file uploads so I assume this is possible, but all of these seem way to much for what I am trying to do, and I would like to learn how to do it.  Does anyone know if this is possible? Could provide simple example or explanation or reference?  Appreciate it as always!
38828
How do I setup a class that represents an interface?  Is this just an abstract base class?
52784
This question appears to have been answered several times on here, but none of the solutions are working for me.  I have an Apex function defined like so:  @RemoteAction global static ActivityWrapper createActivity(Activity__c activity)   And when I call this Javascript function:  Controller.createActivity(     {ForWeek__c: "2014-04-21T08:00:00.000Z",      Notes__c: "sdfsdf",      Type__c: "Referral",      Id: null,      sObjectType: "Activity__c"}, callback);   I always get back this error message:  Visualforce Remoting Exception: Unexpected type for Controller.createActivity(Activity__c)   As far as I know this is all that is required, but I can't get past this.
18625
I would like to ensure that I only subscribe once in a particular class for an event on an instance.  For example I would like to be able to do the following:  if (*not already subscribed*) {     member.Event += new MemeberClass.Delegate(handler); }   How would I go about implementing such a guard?
41125
I have been looking at the plugin API a bit more in depth recently and I was wondering what real differences there were between action and filter hooks. They both are events that receive data as a parameter and they seem to both be able to do the same things.  Obviously I see that actions are called when actions take place and filters are called when data is manipulated, but it seems to just be a semantic naming difference.  Besides semantics and what they are used for, what real differences are there between them?
94858
I am new to lightning experience and components. I have been through some blogs and code that guide through the basics, but other than that I haven't had much hands-on experience.  My question is:  When to use component events vs application events? If I have nested components (parent &amp; child) and if the events are of type Component, will the parent be able to handle events fired from child, and vice versa?  Also, I've noticed there are two ways to get an instance of an event (say TestEvent) -      component.getEvent("TestEvent");   and      $A.get("e.c:TestEvent");   Is there any difference between the both? What do "$A" &amp; "e" in the second form, represent?  Thanks in advance for your reply!
13551
UPDATE   I have combined various answers from here into a 'definitive' answer on a .  Original question  In my code I have an event publisher, which exists for the whole lifetime of the application (here reduced to bare essentials):  public class Publisher {     //ValueEventArgs&lt;T&gt; inherits from EventArgs     public event EventHandler&lt;ValueEventArgs&lt;bool&gt;&gt; EnabledChanged;  }   Because this publisher can be used all over the place, I was quite pleased with myself for creating this little helper class to avoid re-writing the handling code in all subscribers:  public static class Linker {     public static void Link(Publisher publisher, Control subscriber)     {          publisher.EnabledChanged += (s, e) =&gt; subscriber.Enabled = e.Value;     }      //(Non-lambda version, if you're not comfortable with lambdas)     public static void Link(Publisher publisher, Control subscriber)     {          publisher.EnabledChanged +=              delegate(object sender, ValueEventArgs&lt;bool&gt; e)              {                   subscriber.Enabled = e.Value;              };     } }   It worked fine, until we started using it on smaller machines, when I started getting the occasional:  System.ComponentModel.Win32Exception Not enough storage is available to process this command   As it turns out, there is one place in the code where subscribers controls are being dynamically created, added and removed from a form. Given my advanced understanding of garbage collection etc (i.e. none, until yesterday), I never thought to clear up behind me, as in the vast majority of cases, the subscribers also live for the lifetime of the application.  I've fiddled around a while with , but it doesn't work with anonymous delegates (not for me anyway).  Is there anyway out of this problem? I really would like to avoid having to copy-paste boiler-plate code all over the shop.  (Oh, and don't bother with asking me WHY we are creating and destroying controls all the time, it wasn't my design decision...)  (PS: It's a winforms application, but we've upgraded to VS2008 and .Net 3.5, should I consider using the ?)  (PPS: Good , but if anyone can come up with an equivalent to the WeakEventHandler which avoids me having to remember to explicitly UnLink/Dispose, that would be cool...)  EDIT I must admit that I worked around this problem by "recycling" the controls in question. However the workaround has come back to haunt me as the 'key' I was using is apparently non-unique (sob). I've just discovered other links  (tried this - seems to be a bit too weak - GC clears delegates even if target is still alive, same problem with  below),  (forces you to modify publisher, and doesn't really work with anonymous delegates) and  (cited-as-incomplete by Dustin Campbell).   It occurs to me that what I'm looking for may be semantically impossible - closures are designed to 'hang around even after I'm gone'.   I've found another workaround, so I'll stick with that, pending a .
43884
With events being fired and also handled in a helper, I have multiple copies of simple constants and so there is some risk of silent failure due to typos.  Given the helper functions are defined as properties of an object, it appears possible to define constants in the same way and reference them via the helper instance:  ({     ADD_ACTION : 'ADD',     EDIT_ACTION : 'EDIT',      onRowAction : function(component, event, helper) {         var action = event.getParam('action');         switch(action.name) {             case this.ADD_ACTION:                 ...             case this.EDIT_ACTION:                 ...         }     }, })   But is there a better way to share constants between helper methods in a single Lightning Component?  PS  itzmukeshy7's use of objects to group the constants is a nice refinement:  ({     actions: {         ADD: 'ADD',         EDIT: 'EDIT'     },      onRowAction : function(component, event, helper) {         var action = event.getParam('action');         switch(action.name) {             case this.actions.ADD:                 ...             case this.actions.EDIT:                 ...         }     }, })