Skip to content

easybiblabs/salesforce-sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Salesforce Sync

Queries Salesforce, saves result in local database. Currently only querying the Salesforce Account object.

Contains a console command, a silex service provider, and a standalone service.

Usage

All example code assumes you're using the included EasyBib\Silex\Salesforce\SalesforceServiceProvider in a Silex-y kind of app.

configure

####required

$app['salesforce.username'] = 'username';
$app['salesforce.password'] = 'password accesstoken thingy';

$app['salesforce.fieldmap'] = [
    // the salesforce fields you need => your own local field name
    // see links to salesforce docs at the end of the README
    'Id' => 'id',
    'Owner.Name' => 'owner',
    'Foo_Subscription_Start_Date__c' => 'subscriptionStart',
    'Foo_Name__c' => 'name',
    'Foo_Coupon_Code__c' => 'coupon',
];

// a WHERE/HAVING/LIMIT statement for the salesforce API
// you probably want WHERE roughly like this:
$app['salesforce.filter'] = 'WHERE Foo_Coupon_Code__c != null';

$app['salesforce.upsertfunction'] = $app->protect(function(array $records) use ($app) {
    // UPSERT the salesforce data here, return the number of updated records.
    //
    // Will be called with an array of hash-maps (arrays), with the fields from
    // your fieldmap, e.g:
    //
    //   [
    //      'id' => '123232abcs',
    //      'owner' => 'Some One',
    //      'subscriptionStart' => '1979-01-02',
    //      'name' => NULL,
    //      'coupon' => 'tralalala',
    //   ]
    //
    // This function may get called more than once (once per batch).
    // count($records) will always be more than 0 and less than 2001.
    //
    // You can do what you want here, noSQL, SQL, whatever.
    return $app['em']->getRepository(Entity\Salesforce::class)->batchUpsert($records);
});

optional

// You only need to set this if you don't use composer.
$app['salesforce.wsdlpath'] = 'path/to/salesforce/partner.wsdl.xml';
$app['salesforce.cleanupfunction'] = $app->protect(function(array $ids) use ($app) {
    // You may use this to do a "delete where id not in ($ids)" or something like that.
    // Gets called at the end of a sync(), with all ids of the records we got from salesforce.
});

Once you have all that, register a new EasyBib\Silex\Salesforce\SalesforceServiceProvider.

call

If you use the service provider, you'll have access to the following:

// a Symfony\Component\Console\Command\Command, "salesforce:sync"
// "./console salesforce:sync" syncs all accounts
// "./console salesforce:sync someAccountId123" syncs only that one account
$app['salesforce.command.sync'];

// the EasyBib\Silex\Salesforce\Service, same functionality as the command
$app['salesforce.service'];

// a proxy to a logged-in \SforcePartnerClient, if you're feeling brave
$app['salesforce.client.proxy'];

Docs

Possible fields to select

About

Small wrapper around the salesforce client, to sync stuff from there to a local cache

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •