$account = new account($acc_slcode); foreach ($force_records as $record) { if (isset($record->Id)) { $account->set_sf_fields($record); $existing_record = $ms_sql->get_record_sf_id('account', $record->Id); if ($existing_record) { $ms_sql->update('account', $account->compare_for_sql($existing_record), $record->Id); } else { $ms_sql->insert('account', $account->get_sql_record()); } $contact = new contact(array($account->get_primary_keys()['SLCODE'], 0)); } else { $contact = new contact(array($con_slcode, 0)); } foreach ($record->Contacts as $rec) { $contact->set_sf_fields($rec); $existing_record = $ms_sql->get_record_sf_id('contacts', $rec->Id); if ($existing_record) { $ms_sql->update('contacts', $contact->compare_for_sql($existing_record), $rec->Id); } else { $ms_sql->insert('contacts', $contact->get_sql_record()); } } } foreach ($sql_records as $company => $slcode) { $insert_accounts = array(); $update_accounts = array(); foreach ($slcode as $record) { if ($record['Account']) { $account = new account(); $account->set_sql_fields($record['Account']);