function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
doubleminusdoubleminus 

REST callout not working at all....

So I'm trying to make a call out to a REST web service and am having a hard time. The end goal is that it will retrieve a string, and place it into a text field. Right now, I'm just trying to get the service to retrieve any basic information, as a starting point. And in the code, I'm trying to say: If you retrieve nothing...just update the field_debug__c field.

 

Next question, if I have multiple parameters to put into a header...how do I do that? For example, I need to provide an API key here, and an ACCEPT statement (=txt/xml). I'm sure setting twice, like I'm doing below, is wrong. How do I do this?

 

Apex class:

 

public class pullApprover {

    @future (callout=true)
    public static void restCallout(String id) {

      Case cas = [select id, val_flag__c, field_debug__c from Case where id=:id];

      HttpRequest req = new HttpRequest();

      //Set HTTPRequest params
      req.setMethod('GET');
      req.setEndpoint('https://rest.test.com/api/accounts/10');

      String APIKEY = '1234567';

      req.setHeader('X-API-KEY', APIKEY);
      req.setHeader('ACCEPT', '=text/xml');

      Http http = new Http();
      HTTPResponse res = http.send(req);
      System.debug(res.getBody());

      // Update case
     cas.field_debug__c = res.getBody();

 

 

And the trigger:

 

trigger dataPull on Case (after update) {

    Case[] cases = Trigger.new;

	pullName.restCallout(Trigger.new[0].Id);

	System.debug(Trigger.new[0].Id + '');
}

 

 

And I'm using that cas.field_debug__c to test if the case is even updating. It is not.

 

Any assistance is much appreciated.

 

double

doubleminusdoubleminus

I just greatly simplified the above code and post, to make troubleshooting easier.

 

Still no luck. No fields would update. Debug logs show no exceptions and show asynch call going out. Regardless of whether it returns anything useful...that cas.field_debug__c should be updating, right?