• Aaron Attard
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

I have this apex trigger & apex class that trigger when a record is created. This works well when sending text as string in the request.setbody, however I need to replace the "name" & "external_id" with values from the created record within inverted commas.

The end result should be sending JSON text as follows:

{
"options": [ {"name": "Job Name A", "priority": 0, "external_id": "a1H0J000005xP6E"} ]
}

//Apex Trigger
trigger [ApexTriggerName] on [ObjectRecord] (after insert)
{AfterInsertCreateJob.jobs();}
//Apex Class
public class AfterInsertCreateJob {
    
    @future(callout=true)
    public static void jobs(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://example.com');
        request.setMethod('POST');
        request.setHeader('Content-Type','application/json');
        request.setHeader('On-Behalf-Of','[userid]');
        request.setHeader('Authorization','[password]');
        request.setBody('{"options":[{"name":"record.name","priority":0,"external_id":"record.id"}]}');
        System.debug('1: ' + request);
        HttpResponse response = http.send(request);
        System.debug('2: ' + response);
    }

}

 
Hey guys

I'm trying to run the flow hereunder but I am getting an error because I am trying to loop through multiple records (approx 2000). The flow works great when I change the filter criteria to only loop through 50 records but I would like to loop through all of them at one go. Is there a way I can do this using the visual flow builder? Unfortunately I'm not that experienced in APEX code.

User-added imageThanks
Aaron
Hey guys

I'm trying to run the flow hereunder but I am getting an error because I am trying to loop through multiple records (approx 2000). The flow works great when I change the filter criteria to only loop through 50 records but I would like to loop through all of them at one go. Is there a way I can do this using the visual flow builder? Unfortunately I'm not that experienced in APEX code.

User-added imageThanks
Aaron

I have this apex trigger & apex class that trigger when a record is created. This works well when sending text as string in the request.setbody, however I need to replace the "name" & "external_id" with values from the created record within inverted commas.

The end result should be sending JSON text as follows:

{
"options": [ {"name": "Job Name A", "priority": 0, "external_id": "a1H0J000005xP6E"} ]
}

//Apex Trigger
trigger [ApexTriggerName] on [ObjectRecord] (after insert)
{AfterInsertCreateJob.jobs();}
//Apex Class
public class AfterInsertCreateJob {
    
    @future(callout=true)
    public static void jobs(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://example.com');
        request.setMethod('POST');
        request.setHeader('Content-Type','application/json');
        request.setHeader('On-Behalf-Of','[userid]');
        request.setHeader('Authorization','[password]');
        request.setBody('{"options":[{"name":"record.name","priority":0,"external_id":"record.id"}]}');
        System.debug('1: ' + request);
        HttpResponse response = http.send(request);
        System.debug('2: ' + response);
    }

}

 
Hey guys

I'm trying to run the flow hereunder but I am getting an error because I am trying to loop through multiple records (approx 2000). The flow works great when I change the filter criteria to only loop through 50 records but I would like to loop through all of them at one go. Is there a way I can do this using the visual flow builder? Unfortunately I'm not that experienced in APEX code.

User-added imageThanks
Aaron