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
Reshmi SmijuReshmi Smiju 

Heroku Integration _Trail issue

Hi
Being a new comer in Integration, I tried to update a Custom field in Salesforce called Order Number , that would receive from Heroku.  Following is my REST Call out class.

public class EXT_HEROKU_Fetch_Order{

    public class ExternalOrder{
        public String Id{get;set;}
        public Integer Order_Number{get;set;}
    }
    
    public static void addOrder(List<Id> InvoiceIds){
        JSONGenerator gen = JSON.createGenerator(true);
            gen.writeStartArray();
            for(ID InvoiceID :InvoiceIds){
                gen.writeStartObject();
                gen.writeStringField('Id',InvoiceID);
                gen.WriteEndObject();
            }
            gen.writeEndArray();
        String jsonOrders = gen.getAsString();
        HttpRequest req = new HttpRequest();
            req.setMethod('POST');
            req.setEndPoint('http://enigmatic-cove-9866.herokuapp.com/order');
            req.setHeader('content-type', 'application/json');
            req.setBody(jsonOrders);
        Http http = new Http();
        HttpResponse res = http.send(req);
                // query the invoicceids
            List<Invoice__c> invoices = [select Id from Invoice__c where Id IN :InvoiceIds];
                // Deserialize the JSON string into List of ExternalOrder Wrapper.
            List<ExternalOrder> orders = (List<ExternalOrder>)JSON.deserialize(res.getBody(),List<ExternalOrder>.class);
                //  Cast the values in the Invoice Id List as a Key-Value Pair
            Map<ID,Invoice__c> invoiceMap = new Map<ID, Invoice__c> (invoices);
            
            for(ExternalOrder order : orders){
                Invoice__c invoice = invoiceMap.get(order.Id);
                Invoice.Order_Number__c = String.valueOf(order.Order_Number);
            }
            update invoices;
     }
I created an Invoice in SFDC. I tried to run in Developer console, before writing a trigger. and getting the following error User-added image

User-added image

It would be great, if you could pls let me know, what is the issue with my code.
Thank you
Regards
Reshmi
pconpcon
The problem is that you are doing a POST against the URL when you should be doing a GET.  Change your line from
 
req.setMethod('POST');

to read
 
req.setMethod('GET');

NOTE: When adding code please use the "Add a code sample" button (icon <>) to increase readability and make it easier to reference.