Obama '08

               
   

Go Back   Mike Simonds > Salesforce > Salesforce Coding Discussions

This is a discussion on Create Record on Custom Object using PHP within the Salesforce Coding Discussions forums, part of the Salesforce category; Over at the Salesforce.com developer forums Paul asked for some help on

Reply
 
LinkBack (13) Thread Tools Rate Thread
  #1  
Old 09-12-2007, 07:47 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 Record on Custom Object using PHP

Over at the Salesforce.com developer forums Paul asked for some help on his custom object to create records in a custom object he had created for his Org, called PFC_API and could not get the script to work.

Here is an working script with some of the fields from his script that I have tested against my developers org. I created the same fields in an object that I created called PFC_API:

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


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

$campaign_read "My Campaign";
$document_read "My Document";
$emailid "contact@email.com";
$sfid "00550000000wI2LAAU";
$ownerid $sfid;
$name "Samsung";




$mystuff = array('Name' => $name,
                 
'OwnerId' => $ownerid,
                 
'PFC_Campaign__c' => $campaign_read,
                 
'PFC_Document_Name__c' => $document_read,
                 
'PFC_Contact_Email__c' => $emailid,
                 
'Contact__c' => $sfid,
                 
'PFC_Action__c' => 'Read', );

//clean contacts to allow changing of characters to XML
$mystuff array_map('htmlspecialchars'$mystuff);

//try to add contact from form
try 
{
    
//salesforce login and wsdl
    
$wsdl './includes/soapclient/partner.wsdl.xml';
    
$userName "changeme";
    
$password "changeme";

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


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


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

    if (
$result->success
    {
        echo 
"New Record has been added to your custom Object with and 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;
}


?>
This works and should work for anyone that needs to modify it for their custom object


~Mike
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2  
Old 11-06-2007, 12:38 PM
Junior Member
 
Join Date: Oct 2007
Posts: 5
Exclamation help Creating contacts

@Mike

I used your code to try to create a record. I slightly modified the array and the object type.

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'        => '00550000000wI2LAAU',
                 
'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 "email@gmail.com";
    
$password "somepassword";

    
//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 
    {
        
//print "Unsucessful Create<br>";
        
$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;
}


?>
I get this error:

invalid cross reference id

have any ideas how to fix this error?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 11-06-2007, 02:25 PM
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

Ncee

Can you post just the lines that you changed? and did you use this example or the one from this URL > Create User On Salesforce with PHP


~Mike

PS > maybe you could email me the script if you do not want to post it here
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 11-06-2007, 03:04 PM
Junior Member
 
Join Date: Oct 2007
Posts: 5
Exclamation RE:

Mike,

I used the code at Create User On Salesforce with PHP and modified the username and password to my cridentials.

PHP Code:

$userName 
"email@gmail.com";
$password "somepassword"
Do you think it might have something to do with the profileID in the array?

~NCEE
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 11-06-2007, 03:19 PM
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

yes that is what the error is telling me!

I got that profile ID from my dev instance, try and switch yours and rerun the script
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-record-custom-object-using-php-t51.html
Posted By For Type Date
Community - PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 08-20-2008 12:01 PM
Community - PHP, SF API and Custom Objects - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 08-15-2008 02:25 PM
Community - PHP, SF API and Custom Objects - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 06-30-2008 01:07 AM
Community - Re: PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 06-09-2008 10:53 PM
Community - PHP, SF API and Custom Objects - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 04-25-2008 02:38 AM
Community - PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 04-02-2008 07:27 PM
PHP Batching (2) - Perl, PHP, Python & Ruby Development This thread Refback 10-30-2007 09:55 PM
PHP Batching (2) - Perl, PHP, Python & Ruby Development This thread Refback 09-24-2007 08:17 AM
Community - PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-17-2007 04:45 PM
Community - Re: PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-12-2007 03:43 PM
Community - Re: PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-12-2007 03:35 PM
salesforce.com: Blogs, Photos, Videos and more on Technorati This thread Refback 09-12-2007 12:41 PM
Community - PHP Batching (2) - Perl, PHP, Python & Ruby Development - Salesforce.com Community This thread Refback 09-12-2007 08:25 AM



Powered by vBulletin


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

1 2 3 4 5