savagenoob Posted June 14, 2011 Share Posted June 14, 2011 How would I get Id from this array: QueryResult Object ( [queryLocator] => [done] => 1 [records] => Array ( [0] => SObject Object ( [type] => [fields] => [id] => 00QE0000001nvBTMAY ) [1] => SObject Object ( [type] => [fields] => [id] => 00QE0000001nvB5MAI ) ) => 2 ) My code not working: $client = new SforceEnterpriseClient(); $client->createConnection($wsdl); $client->login($user, $pass . $token); $query = "SELECT Id from Lead WHERE Company = 'Jamoke, Inc.'"; $response = $client->query(($query)); print_r($response); $eLEADID = $response->Id; echo "Lead Id:" . $eLEADID; $leadConvert = new stdClass; $leadConvert->convertedStatus='Closed - Converted'; $leadConvert->doNotCreateOpportunity='false'; $leadConvert->leadId=$eLEADID; $leadConvert->overwriteLeadSource='true'; $leadConvert->sendNotificationEmail='true'; $leadConvertArray = array($leadConvert); $leadConvertResponse = $client->convertLead($leadConvertArray); $eLEADID comes up empty.... Im working on Saleforce integration and want to convert a lead to an Account. Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/ Share on other sites More sharing options...
wildteen88 Posted June 14, 2011 Share Posted June 14, 2011 When posting code please wrap it within or tags. Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229580 Share on other sites More sharing options...
savagenoob Posted June 14, 2011 Author Share Posted June 14, 2011 Thanks for the help bro... the code is wrapped in PHP tags... Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229587 Share on other sites More sharing options...
mikesta707 Posted June 14, 2011 Share Posted June 14, 2011 based on the contents of your print_r seems to me you would access the ID with $eLEADID = $response->records['Id']; but thats just a guess Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229589 Share on other sites More sharing options...
wildteen88 Posted June 14, 2011 Share Posted June 14, 2011 Just did a google on the SforceEnterpriseClient class and came across this documentation. As the documentation showws you need to loop over the results ($responce) and convert the records into SObjects. $response = $client->query($query); foreach($response as $record) { $sObject = new SObject($record); // covert current record into SObject echo $sObject->Id; // get the id of the currect record } Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229594 Share on other sites More sharing options...
AbraCadaver Posted June 14, 2011 Share Posted June 14, 2011 There are 2 records there so you would need to loop through them. For the first you would probably use: echo $response->records[0]->id To loop: foreach($response->records as $record) { echo $record->id; } Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229595 Share on other sites More sharing options...
savagenoob Posted June 14, 2011 Author Share Posted June 14, 2011 I tried this earlier, still cant get it. I know its something simple... foreach($response as $record){ $sObject = new SObject($record); echo $sObject->Id; print_r($sObject); } Returns: SObject Object ( [type] => [fields] => ) SObject Object ( [type] => [fields] => ) SObject Object ( [type] => [fields] => [1] => SObject Object ( [type] => [fields] => [id] => 00QE0000001nvB5MAI ) ) SObject Object ( [type] => [fields] => ) and no Id's are output. Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229603 Share on other sites More sharing options...
savagenoob Posted June 14, 2011 Author Share Posted June 14, 2011 Sorry AbraCadaver I should have read your post more carefully... you are right. Thank you for the help, this was driving me nuts. Quote Link to comment https://forums.phpfreaks.com/topic/239352-get-data-from-an-array/#findComment-1229609 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.