Comments (5)
Got it, that makes sense. It might be possible but you will probably need to do some trickery in the custom function to hide some of the complexity away.
For example you could do the bulk call once and hold it in-memory in a static variable or in a Singleton to then grab the information as needed from memory, and thus just calling the API once (the first time the function is called). I have an example of doing that for a function that simulates getting product prices: https://github.com/cesarParra/expression/blob/main/unpackaged/examples/expression-conf/main/default/custom-functions/GetListPrice.cls
All prices are fetched in the beginning but subsequent calls just grab from the cache so I can do GETLISTPRICE(Id) on a record-by-record basis.
Could be other ways of achieving it but that's just an idea.
from expression.
Hi @liumiaowilson.
You should be able to receive and return collections (lists/maps) as Object
as well, you would only need to do the correct casting.
So for example I could have a custom function like this which just appends a string to each Id (in your case you would call your endpoint in bulk):
global with sharing class RestFetcher implements IExpressionFunction {
global Object execute(List<Object> args) {
List<SObject> receivedRecords = (List<SObject>) args[0];
List<String> accountIds = new List<String>();
for (SObject acc : receivedRecords) {
accountIds.add(acc.Id + ' ' + 'Custom Modification To Record');
}
return accountIds;
}
where I receive an argument which is a list in the index 0 of the parameters, and then I can return back a list as well.
In the expression I can then call then use the returned list to continue modifying the data as desired
from expression.
Yeah this approach works. But can I have admin configure expressions to run like this: RestFetcher(id) = true
as a dynamic criteria to filter a batch of records in memory in apex?
from expression.
I'd need to be more familiar with the implementation/use case.
You have the option of either passing more info to the Apex side through arguments, or on the other hand doing the filtering on the Expression side with the data that is coming back.
But whichever path you will probably need to have a separation between the function call to the Rest API and the filtering you want to do, since it won't really be able to batch it up for you since it won't have the context of what is coming back from the rest call. It'd be similar to apex where if you want to do something in bulk first you need to create the list, and then perform the operation in different steps.
from expression.
The scenario is like this: we have a custom rule that admins can specify an expression as a criteria to filter the records that we want to execute some certain actions on a daily basis. I would like to use the flexibility of the expression so that admins can specify the criteria for each record, instead of handling a collection of records(too complex for admins to configure). We can provide some custom functions that wrap our existing call-outs and process the output in the functions so that admins can easily use them. It would be ideal if the custom functions can execute like invocable actions, which support passing in bulkified parameters and returning bulkified results. Hope that I have made myself clear.
from expression.
Related Issues (20)
- Invocable endpoint
- Release core language as managed package
- Release component library as managed package.
- Flowbite migration
- Improve component configuration through custom LWC Experience Builder editors
- Playground "Validate" button should be disabled while running
- Playground errors should reset when the "Validate" button is hit
- Move Component docs to Github site HOT 1
- Improve the way LWC component contracts work
- Spring '24 updates
- Explore the usage of shadcn/ui for a reusable component library
- Run expression for a batch of records? HOT 1
- List Start Index 0 or 1? HOT 1
- The Github icon of the documentation site does not link back to the expression URL
- Investigate more use cases for embedded collections and query resolution
- Investigate which other functions could use `needChildrenResolution`
- Interpret both sets and lists
- Add FLATTEN function
- Resolving of nested custom context Map<String, Object> not working. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expression.