• Turner Nelson
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
I'm trying to get a contact from a custom object, but am struggling on how to do so. The custom object is called 'Opportunity Request' (API Name: 'Sales_Request__c'), which is a child object to an 'Opportunity', so one Opportunity can have many Opportunity Requests. On the Opportunity Request there is a field named 'Prospect Contact', which is not pulled from the Opportunity, but is selected when creating the Opportunity Request. How would I get this field since it is on a custom object and I'm unfamiliar of the IDs needed?
I currently have a problem involving triggers, futures, callouts, and HttpResponses.

Currently, when my trigger is called, it calls a future function, which contains a callout to make a POST Http Request. This POST request is expecting a Http Response. From what I've been researching, my method is completing before the response comes back, which should only take several seconds, but the future is complete before it responds. I've seen there are continuation object options as well, but since futures are Static methods, I'm not sure that is an option. Here is what I have so far:
 
Public class Provision_Trial_Trigger_API_Callout {
   
   @future(callout=true)
   public static Void execute(Map<String, String> config) {
       try {

            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setEndpoint(config.get('endpoint'));
            request.setMethod(config.get('method'));
            request.setBody(config.get('body'));
            config.remove('endpoint');
            config.remove('method');
            config.remove('body');
            for (String key : config.keySet()) {
                request.setHeader(key, config.get(key));
            }
            HttpResponse response = http.send(request);
            //the above line appears to be causing the function to stop
            //and no line below it or above it will execute if not commented out
            if (response.getStatusCode() == 200){
                 //do stuff
            }else{
                System.debug('fail');
            }
        } catch(DmlException e) {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
    }

}

I've tried to make a wait() function, but this function doesn't work when the 'HttpResponse response = http.send(request);' line is not commented out.

Any thoughts or suggestions how to overcome this? I'm open to using Continuations, but unsure of when they are to be used.
I currently have a problem involving triggers, futures, callouts, and HttpResponses.

Currently, when my trigger is called, it calls a future function, which contains a callout to make a POST Http Request. This POST request is expecting a Http Response. From what I've been researching, my method is completing before the response comes back, which should only take several seconds, but the future is complete before it responds. I've seen there are continuation object options as well, but since futures are Static methods, I'm not sure that is an option. Here is what I have so far:
 
Public class Provision_Trial_Trigger_API_Callout {
   
   @future(callout=true)
   public static Void execute(Map<String, String> config) {
       try {

            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setEndpoint(config.get('endpoint'));
            request.setMethod(config.get('method'));
            request.setBody(config.get('body'));
            config.remove('endpoint');
            config.remove('method');
            config.remove('body');
            for (String key : config.keySet()) {
                request.setHeader(key, config.get(key));
            }
            HttpResponse response = http.send(request);
            //the above line appears to be causing the function to stop
            //and no line below it or above it will execute if not commented out
            if (response.getStatusCode() == 200){
                 //do stuff
            }else{
                System.debug('fail');
            }
        } catch(DmlException e) {
            System.debug('The following exception has occurred: ' + e.getMessage());
        }
    }

}

I've tried to make a wait() function, but this function doesn't work when the 'HttpResponse response = http.send(request);' line is not commented out.

Any thoughts or suggestions how to overcome this? I'm open to using Continuations, but unsure of when they are to be used.