You need to sign in to do that
Don't have an account?
Sahil Yadav
Salesforce Integration Using Rest API
Hello Folks,
I am still exploring on Integration part in salesforce but for now i had come accroseed a requirement that from salesforce i needed to send the opportunitylineitem record from salesforce to external system So here is my code
So I will be getting opportunity line item record which is been needed
to sent and serializing it so the way I sent that seriallized record is the correct way to pass under request body or there is some other way around.
Please let me know or any suggestion
I am still exploring on Integration part in salesforce but for now i had come accroseed a requirement that from salesforce i needed to send the opportunitylineitem record from salesforce to external system So here is my code
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://hookb.in/6JqjXyjp2RsoO0ro3nP7'); request.setMethod('POST'); OpportunityLineItem opp = [Select id, name,ListPrice,UnitPrice, Opportunity.Id,Opportunity.CloseDate, Opportunity.Account.BI_ID__c from OpportunityLineItem Limit 1]; System.debug(JSON.serialize(opp)); String name = opp.name; System.debug('!!!' +name); Decimal listPrice = opp.ListPrice; System.debug('!!!' +listPrice); Decimal unitPrice = opp.UnitPrice; System.debug('!!!' +unitPrice); Date closeDate = opp.Opportunity.CloseDate; System.debug('!!!' +closeDate); request.setBody('{OpportunityLineItem opp}'); request.setBody('{"Name":"any--JUL 2022 Mobile", "ListPrice" : "123.00", "UnitPrice" : "123.00" , "CloseDate" : "2022-07-01 00:00:00"}'); request.setHeader('Content-Type', 'Application/Json; charset = UTF-8'); System.debug('!!!'+request); HttpResponse response = http.send(request); System.debug('!!!'+response); } }
So I will be getting opportunity line item record which is been needed
to sent and serializing it so the way I sent that seriallized record is the correct way to pass under request body or there is some other way around.
Please let me know or any suggestion
Did you check using post man tool with mock response? Do you see similar error?
http://bestirtech.com/blog/2021/03/calling-salesforce-custom-rest-api-postman-example/
https://trailhead.salesforce.com/en/content/learn/modules/postman-api-client
Thanks,