This is a discussion on Help with API transaction within the Salesforce Coding Discussions forums, part of the Salesforce category; I have the API script that I use to add an account
-
Help with API transaction
I have the API script that I use to add an account (we have Person Accounts enabled) for our Enterprise SalesForce account. Everything in it works just fine there.
The problem I have is with Opportunities. When we have a new sale, we need to be able to add the Account, then add the sale (I'm guessing through opportunities, although that is rather broken for our needs - we don't have a sales funnel, just sales). So in trying to add an opportunity and product through the API I'm running into a brick wall.
So now to the question: How would I add the user, opportunity and opportunitylineitem in the same query (or the most elegant way, if that doesn't work)? In the end I want to either have a new Account with a transaction applied or a current account with a new transaction applied. I'm using pretty much straight API code here, but whatever I've tried to do with the opportunities table has been a disaster. Here's what I'm using now to add an account:
<?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;
}
?>
Any help getting this done would be most appreciated.
-
Maybe I am a little confused so let me see if I understand this correctly.
You have this script that creates an account. You want to be able to put the opportunities and user on the account that has just been created?
I am sure i can help you, but need some more information.
Sorry for all the questions
~Mike
-
question
Thanks for the reply, Mike.. it's always more clear in one's own head 
I think I may have most of it figured out, after a long period of php study across a lot of tutorials (many of them yours). I also downloaded an app called LexiLoader that pretty much saved my bacon, showing me what all the table data looked like, and gave me some extra clues on what to do.
So here's my current idea, maybe you could just give me some feedback -
I would like to change up the Opportunities page to treat each opportunity as a sale, no products attached as a separate line items, but in the opportunity itself, so when you're in a client record and click on opportunity you are pretty much looking at a sales order. Each opportunity then would be a sale of an item. I would get rid of most of the other fields below (on the opportunity page) that don't matter to us, probably just leaving cases. I would then add some custom fields for extra information that comes from my shopping cart (order id, etc.) that I could then use for service of those sales. I would then use custom buttons to call functions and data within the opportunities page that would interact back with my shopping cart to process refunds, etc. We have a lot of things going on there, but I think that would fit our business model much better.
Have you ever heard of anyone doing something like that? Salesforce isn't really set up for our sales process, but I can't believe that we are the only ones doing things like this...
Any feedback you have would be appreciated. And thanks for running this forum/site. This is an awesome resource for someone like me that is just starting to work with salesforce.
-
How new are you to salesforce? I have never heard of Lexiloader, but seems like a cool App. I think that would be a great idea, but what about just creating a custom object and having that do what you need it to. you could create a relationship between the account object and the custom object. I think that you could do all of this via the API using PHP, but do whatever works for you.
I have processes that update our accounts and then also update the opportunities. When you update an object, and you probably already know this, you get back a response object that has the ID of the record that was just updated or inserted. You could then use that ID (from the account object record) and update or insert to the new object or even to the opportunities.
I have some scripts which update a lot of different objects on the fly
You could also use APEX do do what you need.
Your welcome for the site, I just try and help people, I like to do that
I would like to talk offline on this project, seems like an interesting one and would be willing to help you if you need.
~Mike
-
question
Hey Mike,
New as in like 2 weeks ago I started playing around with it. I didn't think about the custom object, that would probably be better than tweaking the opportunity table, just in case someone gets the bright idea of using that later
. I would much rather do everything through the API, as I need to automate the import of data/sales as much as possible. Pretty much the only one that will be using the gui will be the support people.
I did indeed get the ID back, I was having a problem at one point because I wasn't looking at the fact that it was an object, not an array. It was very frustrating, but I've go a handle now how to process that.
I did look at some of the APEX stuff, but I'm not sure about that yet. We have a short ramp on this project, so I needed to get going quickly. I'm sure there will be several projects coming down in the future that may make more sense to use that method instead.
I would welcome any input you have, feel free to email me and we can talk further.
Thanks again,
Eric
-
That is fine you can always contact me via here on email me from my members page. It sounds like a pretty straight forward project and I am sure that I could help you, if you need. I would look into the custom object if I were you, sounds like a better way to go. If you want to contact me, you can send me a private message here or email me a number that I can reach you on
Let me know
Enjoy the weekend
~Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
Bookmarks