I have a JSON loop-back file coming from Python that I need apex code to filter through the JSON and tell me the value of a field or if it is null so that it can then auto match whether a lead needs to be created/update/ or an opportunity need to be updated/ or an account. I have my code working to taken information for one object but not for multiple. The source data raw data is not grouped with Lead, Opps, Contacts, or Accounts. It is all one record that will need to shorted based on if a field has data or if it is null.
@RestResource (urlMapping='/Leads')
global with sharing class LeadRest {
@HttpPost
global static String doPost(Lead[] Leads) {
Lead[] LeadsToInsert = new List<Lead>();
Lead[] LeadsToUpdate = new List<Lead>();
for(Lead ldr : Leads) {
if (ldr.id == null){
LeadsToInsert.add(ldr);
}
else {
LeadsToUpdate.add(ldr);
}
}
update LeadsToUpdate;
insert LeadsToInsert;
return Leads[0].LastName;
}
@HttpGet
global static Lead[] doGet() {
Lead[] Leads = [Select
Firstname,
Lastname,
Middlename,
Suffix,
Phone,
Secondary_phone__c,
Street,
City,
Statecode,
Postalcode,
Country,
Region__c,
Date_of_birth__c,
Age__c,
Email,
LeadSource,
Race_ethnicity__c,
Gender__c,
Citizenship__c,
from Lead limit 10
];
return Leads;
}
}