function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
emartemart 

Use API to upsert/add user+opportunity (sale)

Maybe someone can help me with this problem, I'm new to salesforce and this is driving me up the wall…

We have a site that we're moving over to salesforce to manage our customers when they buy from us.  We have an enterprise account, with Person Accounts enabled, and I have a script (from the salesforce API) that adds a new user to salesforce as a result of a new user signing up on our site.  That works very well.

I need to extend this to include:

1. I need to check to make sure the user isn't already there before adding them.
2. Add product purchase into the opportunity fields to be tracked.  For example, one contact may purchase multiple products, and we want to track them individually.
3. Potentially add referral information (partner id?) into the opportunity
4. Return the response from salesforce and put into local db for tracking.

On a basic level, the API script responds with the id of the user that was added, but have had a hard time doing anything with that (tried using array functions, etc.) other than printing to the screen with print_r.  I also don't know how to find out what products I need to reference for the transactions.

Any help that anyone can provide would be most appreciated. 

Here is the script I have now:

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password

define("SOAP_CLIENT_BASEDIR", "phptoolkit-13_1/soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('phptoolkit-13_1/userAuth.php');
try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $sObject = new stdClass();
  $sObject->FirstName = 'George';
  $sObject->LastName = 'Smith';
  $sObject->Phone = '510-555-5555';
  $sObject->PersonEmail = 'test@test.com';
  $sObject->BillingStreet = '12 E Walsh Dr';
  $sObject->BillingCity = 'Aurora';
  $sObject->BillingState = 'CO';
  $sObject->BillingPostalCode = '80234';
  $sObject->BillingCountry = 'US';
  $sObject->PersonMailingStreet = '12 E Walsh Dr';
  $sObject->PersonMailingCity = 'Aurora';
  $sObject->PersonMailingState = 'CO';
  $sObject->PersonMailingPostalCode = '80234';
  $sObject->PersonMailingCountry = 'US';

       
  $createResponse = $mySforceConnection->create(array($sObject), 'Account');
  print_r($createResponse);

} catch (Exception $e) {
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}
?>
jdesrosiersjdesrosiers

@emart:

 

 I suppose that you've probably already seen this link, but i post it anyway :

 http://wiki.developerforce.com/index.php/Salesforce_PHP_Upsert_Tutorial

 

It can help for the upsert part.

Message Edited by jdesrosiers on 01-14-2010 09:54 AM
emartemart

I did see that... I was looking through the docs again after I posted and that does look to solve that problem, so the questions would still remain -

 

1. How can I add a new opportunity line item to signify the purchase of a product.  I really, really wish SF had some way to deal with this more elegantly.  I don't have a funnel like they are set up for, and maybe there's a way just to tag a purchase to a customer instead of all of these hoops (?).

 

2. How do I key on the customer email to make sure the upsert is doing the right thing

 

3. How do I take the new customer info and send it to a local db

 

Thanks!

jdesrosiersjdesrosiers

For the question # 2 : 

Edit your object(customer), and in "Custom Fields & Relationships", click Edit next to the field (email) that you want to act as an external key. And check the External ID checkbox.

And as it is stated in http://wiki.developerforce.com/index.php/Salesforce_PHP_Upsert_Tutorial , your external id can only have one of the following types :

1) Text 
2) Number
3) Email

4) Auto Number 

So the email field should work well.

  

emartemart

That is AWESOME. Thank you so much... that gets me 1/2 way there. 

 

Does anyone have guidance for the product sale question (#1 above)? 

msimondsmsimonds

So  you want to create a new opportunity based of certain conditions?  Sure that could be done, at least from what i am reading in your post.  

 

on number 2 - Are you using a child object to track the products on the opportunity? Like the opportunity line items? 

 

So when you get back the User Id of the user that was added > is that going to be the Owner ID of the opportunity?

 

Sorry I have a whole bunch of questions > feel free to contact me or even take this to my site (look in my sig)

 

I use skype as my main way to discuss issues

 

Sorry it sounds like you are almost there, just a little tweaking needs to be done

 

 

~Mike