Coder Social home page Coder Social logo

Comments (5)

cesarParra avatar cesarParra commented on September 23, 2024 1

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.

cesarParra avatar cesarParra commented on September 23, 2024

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

image

from expression.

liumiaowilson avatar liumiaowilson commented on September 23, 2024

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.

cesarParra avatar cesarParra commented on September 23, 2024

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.

liumiaowilson avatar liumiaowilson commented on September 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.