+ Reply to Thread
Results 1 to 1 of 1

Thread: Create User On Salesforce with PHP

  1. #1
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15

    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

+ Reply to Thread

LinkBacks (?)

  1. Hits: 2
    12-17-2009, 05:09 AM
  2. Hits: 1
    02-17-2009, 03:15 PM
  3. Hits: 1
    01-07-2009, 12:11 AM
  4. Hits: 2
    11-27-2008, 12:03 PM
  5. Hits: 8
    11-12-2008, 04:01 PM
  6. Hits: 1
    10-02-2008, 10:35 AM
  7. Hits: 1
    08-10-2008, 04:45 PM
  8. Hits: 1
    06-29-2008, 05:13 AM
  9. Hits: 2
    06-24-2008, 11:52 AM
  10. Hits: 1
    06-23-2008, 03:52 PM
  11. Hits: 1
    06-20-2008, 10:39 PM
  12. Hits: 2
    01-25-2008, 12:03 AM
  13. Hits: 1
    01-07-2008, 05:44 AM
  14. Hits: 86
    01-03-2008, 12:31 AM
  15. Hits: 1
    10-18-2007, 05:35 AM
  16. Hits: 1
    10-02-2007, 07:25 AM
  17. Hits: 1
    09-25-2007, 12:16 PM
  18. Hits: 1
    09-24-2007, 08:10 PM
  19. Hits: 11
    09-21-2007, 08:58 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1