-4

I have a record type "Item" which requires tax to be calculated. I do not want my users to calculate the tax. I have an external system that has an API that does the calculation. How can i acheive this in an apex trigger. I looked here, but that is using visual force pages. I want to do this in a trigger.

overview of what i am trying to do:

 On record save
    SF($2.53) -> external API

    (external API does some math)

    external API -> SF ($0.07)
    SF update Tax field = $0.07
    SF update total field = $2.53 + $0.07
New contributor
bart2puck is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

closed as off-topic by David Cheng, battery.cord, identigral, EazyE, Lukas Lunow Nov 9 at 1:01

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: SSCCE.org" – David Cheng, battery.cord, identigral, EazyE, Lukas Lunow
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    What have you tried so far? Have you looked at the Trailhead modules Apex Triggers and Apex Integration Services? – David Reed Nov 8 at 14:40
  • Since the question i have tried: salesforce.stackexchange.com/questions/123604/… but now i am getting: System.CalloutException: Callout from triggers are currently not supported.: Trigger.createPOTasks: line 19, column 1 – bart2puck Nov 8 at 14:45
  • You'll need to use an @future method or Queueable Apex. The Apex Integration Services trailhead linked above covers the methodology you'll need to use. – David Reed Nov 8 at 15:45
  • Perfect. I’m headed down that road... thank you – bart2puck Nov 8 at 15:48
0

The solution is to create a trigger that references a class with the desired code in it. adding @future to the class:

trigger:

trigger createPOTasks on Purchase_Order__c (after insert) {
     bartsClass.test();
}

and the class:

public with sharing class bartsClass {
@future (callout=true)
public static void test() {
        Http h = new Http();

        // Instantiate a new HTTP request, specify the method (GET) 
        // as well as the endpoint.
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://server/path/getTax.php?value=2.50');
        req.setMethod('GET');

        // Send the request, and return a response
        HttpResponse res = h.send(req);
        System.debug(res.getBody()); 
    }
}
New contributor
bart2puck is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.