I am iterating over the values from a JSON response in an hourly job and putting those values into a map. From there I'd like to compare each map elements key to the Customer__c JobId field.
If the map's key already exists in Salesforce, then I want to remove that particular map key element from the map. When I use the remove() method with the map, it seems to be deleting all of the map elements.
How can I check for a duplicate value (Map key = Customer__c JOB Id), and insert only those map keys that don't already exist in Salesforce? Thank you in advance.
map<string,Customer__c> rec2insert = new map <string,Customer__c>();
map<string,Customer__c> rec2insert2 = new map <string,Customer__c>();
List<Customer__c> conList1 = [Select Id, JOB_ID__c from Customer__c where JOB_ID__c != null];
for(String s :scope){
Customer__c cod = new Customer__c(); //stores fax details
Customer__c cod2 = new Customer__c(); // to be updated
//Second callout below
cod = CustomerBuilder.getOutBoundRecords(s);
cod2 = cod;
cod2.Name = cod.Name;
cod2.JOB_ID__c = s;
if(cod2.Start_Date__c != null ){
rec2insert.put(s,cod2);
}
}
for(Customer__c cc : conList1){
if(rec2insert.size() > 0 && rec2insert.contains(cc.JOB_ID__c){
rec2insert.remove(cc.JOB_ID__c);
}
Else{
system.debug('NO Values for insert found');
}
}
insert rec2insert.values();
}