3

Using Amount field in a webhook

I've created an Apex class webhook to post from Salesforce to Slack. I have tried with Opportunity.Amount field is defined as a Double or Decimal.

   @InvocableVariable(label='Amount')
   public Double amount;

I use the Apex class in a Process Builder, however when setting the Apex variables, and choosing the Amount field, under Field Reference, the Amount field is not available.

Do I need to declare the Amount field in the APEX in a different way?

BELOW is the APEX

public with sharing class SlackInvoiceRequestPublisher {

private static final String slackURL = 'https://hooks.slack.com/services/XXX';

public class InvReqForm {
    @InvocableVariable(label='Account Name')
    public String accountName;
    @InvocableVariable(label='Amount')
    public Decimal amount;
}

@InvocableMethod(label='Post to Slack Invoice Request Forms')
public static void postToInvoiceRequest(List<InvReqForm> formfields) {
    InvReqForm o = formfields[0]; // If bulk, only post first to avoid overloading Slack channel
    Map<String,Object> msg = new Map<String,Object>();
    msg.put('text', 'Invoice Request Submitted:\n' 
            + '\n Account Name: ' + o.accountName 
            + '\n Total Contract Value: '+ o.amount 

    msg.put('mrkdwn', true);
    String body = JSON.serialize(msg);    
    System.enqueueJob(new QueueableSlackCall(slackURL, 'POST', body));
}

public class QueueableSlackCall implements System.Queueable, Database.AllowsCallouts {

    private final String url;
    private final String method;
    private final String body;

    public QueueableSlackCall(String url, String method, String body) {
        this.url = url;
        this.method = method;
        this.body = body;
    }

    public void execute(System.QueueableContext ctx) {
        HttpRequest req = new HttpRequest();
        req.setEndpoint(url);
        req.setMethod(method);
        req.setBody(body);
        Http http = new Http();
        HttpResponse res = http.send(req);
    }

}

}

6
  • @kristin, make sure you are compliant with the InvocableVariable Considerations
    – glls
    Commented Jan 5, 2018 at 15:57
  • @phil - as far as I know I am compliant. I changed the type to Decimal, but that didn't make a difference. Any suggestions?
    – Kristin
    Commented Jan 5, 2018 at 17:26
  • @phil - the code you pasted above is inside an inner class "container", right? Commented Jan 6, 2018 at 4:37
  • ...or, more importantly, your invocable method is taking a list as a parameter, right? Commented Jan 6, 2018 at 4:46
  • I think the answer to the question is "yes". I am a lowly Salesforce Admin, getting assistance from a developer on our engineering team, so am not totally sure of terminology. I updated the question above with the Apex class. Is it possible you just can't reference a currency field in an invocable variable? The workaround is to create a formula field that returns a number and reference the currency field.
    – Kristin
    Commented Jan 6, 2018 at 6:29

1 Answer 1

0

Another work-around for this limitation is to use a formula to set the value to a Currency reference. See screenshot

Example

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .