I found this helpful. However, for Salesforce 5 (Drupal 10), the syntax is now a bit different - there's no longer a salesforce_get_api() function. The snippet now needs to be:
use \Drupal\salesforce\SelectQuery; function mymodule_sf_contact_exists($email) { $soql = new SelectQuery('Contact'); $soql->fields = [ 'Id' => 'Id' ]; $soql->addCondition('Email', "'{$email}'"); $result = \Drupal::service('salesforce.client')->query($soql); return ($result->size() > 0); }
In my case I wanted to get the SFID of the contact if it existed. In this case, the last line becomes:
return ($result->size()) ? current($result->records())->id() : NULL;