Obama '08

               
   

Go Back   Mike Simonds > Salesforce > Salesforce Coding Discussions

This is a discussion on Create User On Salesforce with PHP within the Salesforce Coding Discussions forums, part of the Salesforce category; Garside over at the Salesforce forums was having an issue with creating

Reply
 
LinkBack (13) Thread Tools Rate Thread
  #1  
Old 09-21-2007, 08:48 AM
Administrator
 
Join Date: May 2007
Posts: 246
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike
Create User On Salesforce with PHP

Garside over at the Salesforce forums was having an issue with creating a new user and was getting an error:

Code:
INVALID_CROSS_REFERENCE_KEY
I copied his code and added it to a small script that I have:


PHP Code:
<?php
ini_set
("soap.wsdl_cache_enabled""0");


require_once (
'./includes/soapclient/SforcePartnerClient.php');
require_once (
'./includes/soapclient/SforceHeaderOptions.php');

$mystuff = array('Username'         => 'user@email.com'// change this to a valid email
                 
'LastName'         => 'Wiley',
                 
'FirstName'        => 'Mike',
                 
'Email'            => 'user@email.com'// change this to a valid email
                 
'Alias'            => 'MWile',
                 
'IsActive'         => 'true',
                 
'TimeZoneSidKey'   => 'America/New_York',
                 
'LocaleSidKey'     => 'en_US',
                 
'EmailEncodingKey' => 'ISO-8859-1',
                 
'ProfileId'        => '00e50000000r9vdAAA',
                 
'LanguageLocaleKey'=> 'en_US');
//clean User to allow changing of characters to XML
$mystuff array_map('htmlspecialchars'$mystuff);

//try to add User from from array
try 
{
    
//salesforce login and wsdl
    
$wsdl './includes/soapclient/partner.wsdl.xml';
    
$userName "user@email.com"// change this to a valid email
    
$password "password"// change this to a valid password

    //connect to salesforce
    
$client = new SforcePartnerClient();
    
$client->createConnection($wsdl);
    
$loginResult $client->login($userName$password);

    
$sObject = new sObject();
    
$sObject->type 'User';
    
$sObject->fields $mystuff;


    
//this part adds the contact to salesforce
    
$result $client->create(array($sObject));

    if (
$result->success
    {
        echo 
"New User has been added to your instance of Salesforce with an Id of " $result->id "<br />";
        echo 
"**************** ALL DONE ****************<br />";
        exit;
    } 
    else 
    {
        
$errMessage $result->errors->message;
        echo 
$errMessage;
    }

}
catch (
exception $e
{
    
// This is reached if there is a major problem in the data or with
    // the salesforce.com connection. Normal data errors are caught by
    // salesforce.com
    
echo '<pre>' print_r($etrue) . '</pre>';
    return 
false;
    exit;
}


?>
just make sure you change the emails in the user to someone valid and your salesforce login and password

This script worked for me

let me know if it doesn't for you

~Mike

Last edited by mike; 09-21-2007 at 10:31 AM. Reason: Correct Spelling Error
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

LinkBacks (?)
LinkBack to this Thread: http://www.mikesimonds.com/create-user-salesforce-php-t54.html
Posted By For Type Date
Community - Re: INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 08-10-2008 04:45 PM
Community - INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 06-29-2008 05:13 AM
Community - Re: post data from php to accounts not lead - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 06-24-2008 11:52 AM
Community - post data from php to accounts not lead - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 06-23-2008 03:52 PM
Community - Re: post data from php to accounts not lead - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 06-20-2008 10:39 PM
Community - INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 01-25-2008 12:03 AM
Community - Re: INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 01-07-2008 05:44 AM
Community - INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 01-03-2008 12:31 AM
INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development This thread Refback 10-18-2007 05:35 AM
Community - Re: INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 10-02-2007 07:25 AM
Community - Re: INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-25-2007 12:16 PM
Community - INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-24-2007 08:10 PM
Community - INVALID_CROSS_REFERENCE_KEY when trying to create user with PHP Toolkit - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-21-2007 08:58 AM



Powered by vBulletin


SEO by vBSEO 3.2.0 RC8 ©2008, Crawlability, Inc.

1 2 3 4 5