I am able to log in to Salesforce through the API in php. Brief Code:
define('USERNAME', getenv(<myuserkey>));
define('PASSWORD', getenv(<mypwkey));
define('SECURITY_TOKEN', getenv(mytokenkey));
$sfconn = new SforceEnterpriseClient();
$sfconn->createConnection('soap/sfwsdl.xml');
$sfconn->login(USERNAME,PASSWORD . SECURITY_TOKEN);
Later, I call a query like this:
$sfqry = "SELECT Id, QualifiedApiName, NamespacePrefix, DeveloperName, MasterLabel, Label, PluralLabel, DefaultCompactLayoutId, IsCustomizable, IsApexTriggerable, IsWorkflowEnabled, IsCompactLayoutable, KeyPrefix, IsQueryable from entitydefinition";
$response = $sfconn->query($sfqry);
I get data results back, the usual 'object' which has a 'records' property. But in looking at the list in records, EVERY single 'Id' value is the same - e.g. 000000000AAA (15 zeros, 3 A's). Other data looks fine (e.g. QualifiedApiName and other fields are different for each record). I have used the same query in the Salesforce SOQL page and Ids are definitely different - and the other fields match what I'm getting back through my PHP query.
I have queried other objects as well, and they too seem to be returning 00000000000AAA for the Id.
In the XML file I have set up, I see the base definition of SObject as this:
<!-- Base sObject (abstract) -->
<complexType name="sObject">
<sequence>
<element name="fieldsToNull" type="xsd:string" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<element name="Id" type="tns:ID" nillable="true" />
</sequence>
</complexType>
And, of course, I see the other objects being based off that one.
I've been researching this for over 2 days. I'm afraid I may have missed something very basic since I can't find anyone else reporting this problem.
My Answer:
'SALESFORCE_USERNAME');
define('PASSWORD', getenv('SALESFORCE_PASSWORD'));
define('SECURITY_TOKEN', getenv('SALESFORCE_SECURITY_TOKEN'));
require_once ('soapclient/SforceEnterpriseClient.php');
$mySforceConnection = new SforceEnterpriseClient();
$mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
$query = "SELECT Id, Name FROM Account LIMIT 5";
$response = $mySforceConnection->query($query);
foreach ($response->records as $record) {
echo "Id: " . $record->Id . " Name: " . $record->Name . "
";
}
?>
In this code snippet, I am querying Salesforce for the Id and Name of the first 5 Account records and printing them out. However, if the Id values returned are all the same, it could be due to a couple of reasons:
1. The query is not correctly retrieving distinct records: Make sure that the query you are using is correctly retrieving distinct records. If the query is not filtering out duplicate records, you may see the same Id value multiple times.
2. There is a bug in the Salesforce SOAP API or your PHP code: Check for any bugs in your code that may be causing the Id values to be the same. Make sure that you are correctly parsing and handling the response from the Salesforce API.
3. The Salesforce data itself has duplicate Id values: It is highly unlikely, but if the Salesforce data itself has duplicate Id values for different records, you may see the same Id value multiple times in your query results.
To troubleshoot this issue, you can try running the same query directly in the Salesforce UI to see if the Id values are indeed the same. You can also try querying a different object or using a different query to see if the issue persists.
Rate this post
3 of 5 based on 5353 votesComments