A little background may be in order. One day my boss tells me, "We want to integrate our site with Salesforce.com." My initial reaction was "cool, a few more weeks of job security." After a decent amount of work learning about the Salesforce API and creating an prototype library for this project, the project was dropped. So now, I've posted that initial library to github incase other would find it useful.
The idea behind it was to provide an ActiveRecord'ish interface to the salesforce partner API. The salesforce_Table class is meant to be a base class for the table mapping classes.
<?php class mySalesforceAccount extends salesforce_Table { public function __construct() { parent::__construct('Account'); } public function DoBusinessStuffToAccount($param) { // ... } }
Then one could use the child object to manipulate data in the Salesforce Accounts table.
<?php // ... $account = new mySalesforceAccount(); $account->getById($account_id); if ($account->name == 'Acme Co.') { echo 'Don\'t buy rockets!! They are defective!!' }
There is [some] support for loading the layouts from Salesforce's meta data. Currently salesforce_TableLayout handles the display and only does very basic HTML. The future plan was to make this an abstract base class so different displays for layouts would be created by extended the classes.
<?php $account = new mySalesforceAccount(); $account->getById($account_id); $layout = new salesforce_TableLayout($account); // This should show and HTML form similar to the one on salesforce // with the fields containing values from $account already echo $layout->getLayoutDisplay('editLayoutSections');
Finally, save works as well, err.. a good part of the time :P
<?php $account = new mySalesforceAccount(); $account->getById($account_id); // pretending we just received a post from an edit layout form $account->fieldsFromArray($_POST); try { $account->save(); echo 'Yay!! We Saved it!!' } catch (Exception $e) { echo 'ERROR : '.$e->getMessage(); }
Oh well, it's out on github (https://github.com/mgfreshour/salesforce.php) now if you're interested. I'd like to work some more on it and perhaps even get it production ready, but that'd require doing programming at home as well as at work! *yuck*
No comments:
Post a Comment