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
Sahil YadavSahil Yadav 

Passing the Data through POST Method Salesforce to External Application

Hello Developers, 
         I needed to pass an opportunitylineitem from salesforce to external application through Rest Api where in terms of http request the daya willl be passed from salesforce to other end .
But facing System.limit Exception while send the records and suggestion or improvisation needed in the code let me know.
Global class IntegrationClass {
    /*
    @HttpGet
    global static List<opportunity> doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String BuyerId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account result = [SELECT Id, Name, Phone,Bi_Id__c, Website FROM Account WHERE Bi_Id__c = :BuyerId];
        
            
                String acc = result.Id;
                List<Opportunity> opp = [Select id, name, accountId from Opportunity where accountId =:acc ];
                 return opp;
            
           
        
        
    }*/
    public static void sendData(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://www.google.com');
        request.setMethod('POST');
        List<OpportunityLineItem> opp = [Select id, name,ListPrice,UnitPrice, Opportunity.Id,Opportunity.CloseDate, Opportunity.Account.BI_ID__c from OpportunityLineItem where OpportunityId = '' AND Opportunity.Account.BI_ID__c = 'buy-7765'];
        String name = opp[0].name;
        Decimal listPrice = opp[0].ListPrice;
        Decimal unitPrice = opp[0].UnitPrice;
        Date closeDate = opp[0].Opportunity.CloseDate;
        
        
        request.setBody('{"Name":"name", "ListPrice" : "listPrice", "UnitPrice" : "unitPrice" , "CloseDate" : "closeDate"}');
        request.setHeader('Content-Type', 'Application/Json; charset = UTF-8');
        System.debug('!!!'+request);
        HttpResponse response = http.send(request);
        System.debug('!!!'+response);
    }
        

}



====================================================================


Calling Integration Class Method:-

IntegrationClass.sendData();


User-added image


For a Time being End Point Url i keep dummy and created a remote site setting as well