You need to sign in to do that
Don't have an account?
Kris Webster
API Query HELP
I am trying to query salesforce data based on information that I am pulling from our HR system via a REST API callout to the HR system.
Basically I am tring to find all contacts in my Salesforce org where the first name = the first name in the API Call. I know that first name is not specific enough, but I am starting here and once I can get records to match I will use a more unique identifier.
Here is my code. I NEED HELP WITH LINE 28! I have left out authorization lines for privacy sake.
Basically I am tring to find all contacts in my Salesforce org where the first name = the first name in the API Call. I know that first name is not specific enough, but I am starting here and once I can get records to match I will use a more unique identifier.
Here is my code. I NEED HELP WITH LINE 28! I have left out authorization lines for privacy sake.
request.setMethod('GET'); HttpResponse response = http.send(request); // If the request is successful, parse the JSON response. if (response.getStatusCode() == 200) { // Deserializes the JSON string into collections of posts. Map<String,Object> wrapper = (Map<String,Object>) JSON.deserializeUntyped(response.getBody()); if (wrapper.containsKey('data')) { Map<String, Object> wrapper2 = (Map<String,Object>) wrapper.get('data'); if(wrapper2.containsKey('data')) { List<Object> people = (List<Object>)wrapper2.get('data'); for (Object peopleWrapper : people) { Map<String,Object> Employees = (Map<String,Object>) peopleWrapper; if(Employees.containsKey('last_name')){ String ZenefitsLastName = (String) Employees.get('last_name'); String ZenefitsFirstName = (String) Employees.get('first_name'); String ZenefitseEmployeeId = (String) Employees.get('id'); List<Contact> contactList = [SELECT Id, FirstName, LastName FROM Contact WHERE FirstName = Employees.get('first_name') LIMIT 200]; //we now need to find all contacts in SF that match the contacts in Employees //once we have matches we need to synce each ID system.debug('Employees ' + Employees); system.debug('last name ' + ZenefitsLastName); system.debug('Employee id ' + ZenefitseEmployeeId); system.debug('first name ' + ZenefitsFirstName); system.debug('Contact list ' + contactList); } } } return null; } return null; } return null; }
Try adjusting your query to : That would answer your question for the query.
However, I would be concerned about the structure of your code, in that you have the SELECT query inside a For Loop - which will cause issues with Too Many SOQLs.
I would consider a format like:
Regards
Andrew
All Answers
List<Contact> contactList = [SELECT Id, FirstName, LastName FROM Contact WHERE FirstName = Employees.get('first_name') LIMIT 200];
Try adjusting your query to : That would answer your question for the query.
However, I would be concerned about the structure of your code, in that you have the SELECT query inside a For Loop - which will cause issues with Too Many SOQLs.
I would consider a format like:
Regards
Andrew
When I used the term "UniqueIds", it can be whatever you are using as your key to find the contacts.
So if we look at the example I posted, you could go It would depend on the structure of your deserialized JSON
It would be better if the key was something more unique than Last Name, so if you have an HR record Id which you could set up as a field on the contact record. I would assume there is some common key between the two systems.
Regards
Andrew