Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambdas in Salesforce Apex

Does Apex support the concept of lambdas?

Ultimately, I am trying to DRY up some really repetitive code in my tests, so I'd love to be able to pass functions around, something like this (C#-esq)

public static TestMethod void some_test_method(){
  Arrange( ()=>
    // some setup stuff
  );
  Act( ()=>
    // test action
  );
  System.assertEquals(...);
}
like image 694
James Maroney Avatar asked Feb 20 '13 01:02

James Maroney


People also ask

Does Apex support lambda?

Apex supports concurrent “single-run” idempotent deployments, and multi-function deployments. Deploying three Node applications on AWS Lambda, using Apex. With Apex, you can invoke a Lambda function by way of a JSON-formatted command. You can also reconfigure and delete functions.

What is lambda in Salesforce?

Salesforce provides several Lambda functions for use in your Service Cloud Voice contact flows. These functions are used by the sample contact flows, and you can also use them in your own contact flows. To learn more about Lambda functions, see Amazon's AWS Lambda Developer Guide.

Are closures the same as lambdas?

A lambda expression is an anonymous function and can be defined as a parameter. The Closures are like code fragments or code blocks that can be used without being a method or a class. It means that Closures can access variables not defined in its parameter list and also assign it to a variable.

Are lambdas faster?

Lambda functions are inline functions and thus execute comparatively faster.


1 Answers

Apex doesn't have lambdas. In fact, it doesn't even have anonymous classes. (That would have been your next question.) You're going to have to stick with declared classes. Apex does support Java-ish interfaces and abstract classes.

like image 74
Jeremy Ross Avatar answered Sep 24 '22 22:09

Jeremy Ross