• moh3en
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 1
    Replies

Hi I am having problems getting all the records from salesforce to my mysql database. It seems to copy the first 50 records and then gives an error saying that Error 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Sullivan', '', '', '', '')' at line 1. This is the code that I am using to fetch the data. There are a total of 15,570 records in salesforce.com and by ommiting the function show_error() only 15,472 records are copied into my local database.

 

function update_contact($mySforceConnection){



	echo"**************************************<br>";
	echo"started updating contact table<br>";
try {

	$query = "SELECT AccountId,Email,FirstName,Phone_1__c,Id,MobilePhone,Name,Phone FROM Contact ORDER BY CreatedDate DESC NULLS FIRST";
  $options = new QueryOptions(100);
  $connection = mysql_open();	//opens a connection

  $mySforceConnection->setQueryOptions($options);
  $response = $mySforceConnection->query($query);
  !$done = false;

  //echo "Size of records:  ".$response ->size."\n";

  if ($response->size > 0) {
    while (!$done) {
      foreach ($response->records as $record) {
    $insert = "insert into contact(Id, AccountId, FirstName, Name, MobilePhone, HomePhone, Email, Phone) " .
			     "values ('$record->Id', '$record->AccountId', '$record->FirstName', '$record->Name', '$record->MobilePhone', '$record->Phone_1__c', '$record->Email', '$record->Phone')";//query for insert
   				 $result = mysql_query($insert, $connection) or show_error($record);
    }
      if ($response->done != true) {
        //echo "***** Get Next Chunk *****\n";
        try {
          $response = $mySforceConnection->queryMore($response->queryLocator);
        } catch (Exception $e) {
          print_r($mySforceConnection->getLastRequest());
          echo $e->faultstring;
        }
      } else {
        $done = true;
      }
    }
  }

} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;
}
	echo"finished updating contact table<br>";
	mysql_close($connection);//close connection

}

 THe structure of my table in mysql database is:

 

Id(varchar(18)), AccountId(varchar(18)), FirstName(varchar(40)), Name(varchar(121)), MobilePhone(varchar(40)), HomePhone, Email and Phone are also varchar(40). 

 

Can somebody please help me? I am using the enterprise WSDL.

  • October 11, 2011
  • Like
  • 0

Hi,

I have a custom object called Invoice__c and the fields that it has are Amount_Outstanding__c,Amount_Paid__c,Id,Invoice_Date__c,Name,Payment_Status__c,Related_Job__c

 

Whenever I do a query using the PHP toolkit 20, it only returns the Id for some reason. My query works fine in workbench.developerforce.com, but whenever I run $options = new QueryOptions(200);$mySforceConnection->setQueryOptions($options);  $response = $mySforceConnection->query($query);

Only id is returned as response. Can somebody please help me figure out what the problem is. I have attached my function below:

function update_invoice($mySforceConnection){
	echo"**************************************<br>";
	echo"started updating  invoice table<br>";
try {

  $query = "SELECT Amount_Outstanding__c,Amount_Paid__c,Id,Invoice_Date__c,Name,Payment_Status__c,Related_Job__c FROM Invoice__c ORDER BY CreatedDate DESC NULLS FIRST";
  $options = new QueryOptions(200);
  $connection = mysql_open();	//opens a connection

  $mySforceConnection->setQueryOptions($options);
  $response = $mySforceConnection->query($query);
  print_r($response);
  !$done = false;

  //echo "Size of records:  ".$response ->size."\n";

  if ($response->size > 0) {
    while (!$done) {

      foreach ($response->records as $record) {
        $insert = "insert into invoice__c(Id, Name, Related_Job__c,Invoice_Date__c, Amount_Paid__c, Amount_Outstanding__c, Payment_Status__c) " .
			     "values ('$record->Id', '$record->Name', '$record->Related_Job__c', '$record->Invoice_Date__c', '$record->Amount_Paid__c','$record->Amount_Outstanding__c', '$record->Payment_Status__c')";//query for insert
   		
   		$result = @mysql_unbuffered_query($insert, $connection) or show_error() ;
    }
      if ($response->done != true) {
        echo "***** Get Next Chunk *****\n";
        try {
          $response = $mySforceConnection->queryMore($response->queryLocator);
        } catch (Exception $e) {
          print_r($mySforceConnection->getLastRequest());
          echo $e->faultstring;
        }
      } else {
        $done = true;
      }
    }
  }

} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;
}
	echo"finished updating  invoice table<br>";
	mysql_close($connection);//close connection


}

 The result by doing a print_r($response) gives me 

QueryResult Object ( [queryLocator] => [done] => 1 [records] => Array ( [0] => SObject Object ( [type] => [fields] => [Id] => a01U0000000i4YSIAY ) ) [size] => 1 )

 

 

cheers

moh3en

  • September 29, 2011
  • Like
  • 0

Hi,

is it possible to log out of a session using the rest API? if so how can I log out using this method? please let me know as this has taken me a long time to figure out.

 

cheers

  • September 13, 2011
  • Like
  • 0

Hi,

 

I am using oauth2 to connect to the php toolkit. I have managed to log in and use all the api's functions except logout(). How can I log out of a session that I am currently in? whenver i use the $mySforceConnection->logout(); This is the error that I get when I run this function:

Fatal error: Uncaught SoapFault exception: [soapenv:Server] No such operation 'logout' in /home/ygdporta/public_html/demo2/soapclient/SforceBaseClient.php:174 Stack trace: #0 /home/ygdporta/public_html/demo2/soapclient/SforceBaseClient.php(174): SoapClient->__call('logout', Array) #1 /home/ygdporta/public_html/demo2/soapclient/SforceBaseClient.php(174): SoapClient->logout() #2 /home/ygdporta/public_html/demo2/index.php(21): SforceBaseClient->logout() #3 {main} thrown in /home/ygdporta/public_html/demo2/soapclient/SforceBaseClient.php on line 174

 Is there another way to end my session?

  • September 12, 2011
  • Like
  • 0

Hi,

I am trying to get the following output in my code. I already have my instance url and access_token. In the documentation for Oauth2, it tells me to send a get request to the id url followed by an OAuth authorization HTTP header containing the access token. Can someone please give me a sample code on how can I send a get request to the id url? I am trying to get the url for the api endpoint. 

{
	"id":"https://login.salesforce.com/id/00D50000000IZ3ZEAW/00550000001fg5OAAQ",
	"asserted_user":true,
	"user_id":"00550000001fg5OAAQ",
	"organization_id":"00D50000000IZ3ZEAW",
	"username":"user@example.com",
	"nick_name":"user1.2950476911907334E12",
	"display_name":"Sample User",
	"email":"user@example.com",
	"status":{
		"created_date":"2010-11-08T20:55:33.000+0000",
		"body":"Working on OAuth 2.0 article"
	},
	"photos":{
		"picture":"https://c.na1.content.force.com/profilephoto/005/F",
		"thumbnail":"https://c.na1.content.force.com/profilephoto/005/T"
	},
	"urls":{
		"enterprise":"https://na1.salesforce.com/services/Soap/c/{version}/00D50000000IZ3Z",
		"metadata":"https://na1.salesforce.com/services/Soap/m/{version}/00D50000000IZ3Z",
		"partner":"https://na1.salesforce.com/services/Soap/u/{version}/00D50000000IZ3Z",
		"rest":"https://na1.salesforce.com/services/data/v{version}/",
		"sobjects":"https://na1.salesforce.com/services/data/v{version}/sobjects/",
		"search":"https://na1.salesforce.com/services/data/v{version}/search/",
		"query":"https://na1.salesforce.com/services/data/v{version}/query/",
		"recent":"https://na1.salesforce.com/services/data/v{version}/recent/",
		"profile":"https://na1.salesforce.com/00550000001fg5OAAQ"
	},
	"active":true,
	"user_type":"STANDARD",
	"language":"en_US",
	"locale":"en_US",
	"utcOffset":-28800000,
	"last_modified_date":"2011-01-14T23:28:01.000+0000"
}

 I used curl to do the request, but I can not seem to find out why it does not return anything. $url is my  id url and $access_token is my token.  The returning status is always 302 instead of 200. Please I need help on figuring why this is happening. I've red the oauth documentations so many times, but I still can not figure what is wrong. Please I would appreciate it if someone had a look at my code.

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
            array("Authorization: OAuth $access_token"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 200 ) {
        die("Error: call to URL $url failed with status $status, response $json_response, curl_error " .     curl_error($curl) . ", curl_errno " . curl_errno($curl));
    }

 

  • September 12, 2011
  • Like
  • 0

Hi, 

 

I'm new to force.com and I am trying to create a website (customer portal in PHP) so that every salesforce.com member is able to login and see their contacts, invoices, downloadable items(licences) and etc... I've installed the php toolkit 20 and have managed to retrieve my contact's details. However, I have to use a security token in order to login. Is there a way to authenticate and get user specific data without using a security token?thanks in advance.

 

moh3en

  • August 19, 2011
  • Like
  • 0

Hi, 

 

I'm new to force.com and I am trying to create a website (customer portal in PHP) so that every salesforce.com member is able to login and see their contacts, invoices, downloadable items(licences) and etc... I've installed the php toolkit 20 and have managed to retrieve my contact's details. However, I have to use a security token in order to login. Is there a way to authenticate and get user specific data without using a security token?thanks in advance.

 

moh3en

  • August 19, 2011
  • Like
  • 0