当 运行 通过进程构建器时,我的 APEX InvocableMethod 返回错误时遇到问题

I am having a problem with my APEX InvocableMethod returning an error when run through process builder

我已经通过 Process builder 创建了一个 运行 的可调用方法。尽管 class 在通过一些更改触发时可以正常工作,但是当 运行 通过流程构建器对其进行设置时,我会收到错误消息。据我确定,它正在发生,因为调用不是 运行 异步进行的。

话虽这么说,我已经尝试将 classes 分开并在将来调用,但我无法弄清楚如何将我拥有的三个字符串从可调用 class 传递到我的呼声class。

任何帮助都会很棒!

public class SendText {

        public class DataWrapper {

        @InvocableVariable(label='Correspondence Name' required=true)
        public String CorrespondenceName;
        @InvocableVariable(label='Phone Number' required=true)
        public String PhoneNumber;
        @InvocableVariable(label='Text Message' required=true)
        public String textMessage;

    }

    @InvocableMethod(label='Send Text Message')
    public static void callSendTextMessage (List<DataWrapper> passedData) {

        for (DataWrapper dw: passedData) {

        //Basic Info needed to send request
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://api.podium.com/api/v2/conversations');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json');
        request.setHeader('Accept', 'application/json');
        request.setHeader('Authorization', 'API Key');

        //Create the 4 required fields for Podium
        Map<String, String> message = new Map<String, String>{
            'customerPhoneNumber' => dw.PhoneNumber,
            'message' => dw.textMessage,
            'locationId' => '49257',
            'customerName' => dw.CorrespondenceName
        };

        String messageJson = JSON.serialize(message);
        System.debug(messageJson);

        request.setBody(messageJson);
        HttpResponse response = http.send(request);

        // Parse the JSON response
        if (response.getStatusCode() != 201) {
            System.debug('The status code returned was not expected: ' +
               response.getStatusCode() + ' ' + response.getStatus());
        } else {
            System.debug(response.getBody());
        }
        }
    }

}

不确定您是否尝试过 Queueable Apex 但我是这样做的,试试这个:

public class SendText {

    public class DataWrapper {

        @InvocableVariable(label='Correspondence Name' required=true)
        public String CorrespondenceName;

        @InvocableVariable(label='Phone Number' required=true)
        public String PhoneNumber;

        @InvocableVariable(label='Text Message' required=true)
        public String textMessage;

    }

    @InvocableMethod(label='Send Text Message')
    public static void callSendTextMessage (List<DataWrapper> passedData) {

        Id jobId = System.enqueueJob(new TextMessaeQueueable(passedData));
        System.debug('Text messages job Id => ' + jobId);
    }

    private class TextMessaeQueueable implements Queueable, Database.AllowsCallouts {

        private List<DataWrapper> wrappedData;

        public TextMessaeQueueable(List<DataWrapper> passedData) {
            this.wrappedData = passedData
        }

        public void execute(QueueableContext context) {

            for (DataWrapper dw: this.wrappedData) {

                //Basic Info needed to send request
                Http http = new Http();
                HttpRequest request = new HttpRequest();
                request.setEndpoint('https://api.podium.com/api/v2/conversations');
                request.setMethod('POST');
                request.setHeader('Content-Type', 'application/json');
                request.setHeader('Accept', 'application/json');
                request.setHeader('Authorization', 'API Key');

                //Create the 4 required fields for Podium
                Map<String, String> message = new Map<String, String>{
                    'customerPhoneNumber' => dw.PhoneNumber,
                    'message' => dw.textMessage,
                    'locationId' => '49257',
                    'customerName' => dw.CorrespondenceName
                };

                String messageJson = JSON.serialize(message);
                System.debug(messageJson);

                request.setBody(messageJson);
                HttpResponse response = http.send(request);

                // Parse the JSON response
                if (response.getStatusCode() != 201) {
                    System.debug('The status code returned was not expected: ' +
                        response.getStatusCode() + ' ' + response.getStatus());
                } else {
                    System.debug(response.getBody());
                }
            }
        }
    }
}