You need to sign in to do that
Don't have an account?

rest api to retrieve accountid and insert order
Hi friends,
I am working on Rest API service and I got stuck in middle and need your help to complete the code.
I have a common field between account and order and based on that field I need to map account Id and insert order.
Kindly refer the below class and need how to get the account id.
Thanks in Advance.
I am working on Rest API service and I got stuck in middle and need your help to complete the code.
I have a common field between account and order and based on that field I need to map account Id and insert order.
Kindly refer the below class and need how to get the account id.
@RestResource(urlMapping='/insertOrder/*') global with sharing class insertOrder { //Insert Method @HttpPost global static String doPost(String cusid, String pl, String res) { Order ord = new Order(); // Need to get the account id. ord.AccountId = acc.Id; // Customer Id is the common field in both account and order. ord.Customer_ID__c = cusid; ord.PL__c = pl; ord.Res__c = res; insert ord; return ord.id; } }
Thanks in Advance.
May I know from where you are getting accId?
ord.AccountId = acc.Id;
// Customer Id is the common field in both account and order.
If CustomerId is common between order and the Account, then you should query for account like:
Account accObj = [SELECT Id FROM Account WHERE Customer_ID__c = cusid];
ord.AccountId = accObj.Id;
All Answers
May I know from where you are getting accId?
ord.AccountId = acc.Id;
// Customer Id is the common field in both account and order.
If CustomerId is common between order and the Account, then you should query for account like:
Account accObj = [SELECT Id FROM Account WHERE Customer_ID__c = cusid];
ord.AccountId = accObj.Id;
Thanks for your reply. This is working.