Salesforce Import implements hook_cron() and calls the Salesforce API getUpdated() function with three parameters: object type, start date, end date. Salesforce responds with a list of Salesforce IDs that have been updated for the time range.

The problem is that this can result in obtaining SFIDs that our import process doesn’t care about. For example, if you are using SF User to sync Drupal users with Salesforce Leads/Contacts, you might not care about Salesforce records without an e-mail address.

For a current implementation I'm working on, 50-60% of the records returned by getUpdated() are objects that we do not want to import. If you're dealing with a few hundred records that's not a big deal; if there are 100,000+ it becomes a bigger concern.

Proposed solution

Salesforce Import should use a more versatile implementation for selecting items to import.

This would be done in two parts. The first part is to start storing the last_import and last_export time for Salesforce records #1147180: Store time of last import, last export and initial creation for items in salesforce_object_map table.

Once we have that information, we can use it when querying Salesforce for updated records in hook_cron.

Example SOQL query:

	$query = $sf->client->query("SELECT $fields FROM '%s' WHERE LastModifiedDate > %d", $object_type, $last_cron_run);
	

In the example above, $fields would be “Id, LastModifiedDate”, and whatever other fields an admin wanted to specify (i.e. Email).

The next step would be to run a query against {salesforce_object_map} and confirm that the last_import date is older than the LastModifiedDate coming from the Salesforce query. If that date is older then the SFID would be added to {sf_import_queue} table.

Finally users with the ‘administer salesforce’ permission should also be allowed to create custom queries so that additional WHERE clauses could be added.

Comments

kostajh’s picture

Issue summary: View changes

Updated issue summary.

kostajh’s picture

Status: Active » Needs review
StatusFileSize
new9.04 KB

Ok, here is a patch that adds the functionality defined above. I did some limiting testing on this and hope to do testing with larger batches of records early next week.

Make sure you apply patch in #1147180: Store time of last import, last export and initial creation for items in salesforce_object_map table first.

EvanDonovan’s picture

Thanks, kostajh, for writing this. This answers my question from #1147180: Store time of last import, last export and initial creation for items in salesforce_object_map table.

This is a requirement for a project in 7.x that I am working on, so I am very glad that I didn't have to write this myself.

Hopefully, I will test this later today.

kostajh’s picture

StatusFileSize
new9.06 KB

Re-rolled after #1147180: Store time of last import, last export and initial creation for items in salesforce_object_map table was committed. Also a minor fix for properly displaying the default SOQL query in the SF Import administration screen.

kostajh’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Needs review » Patch (to be ported)

Committed to 6.x-2.x-dev: http://drupalcode.org/project/salesforce.git/commit/aa1bce4. This could be further refined, but it works without issue and we can deal with improvements later on.

EvanDonovan’s picture

Glad to hear this is working well enough to commit in 6.x.

Will proceed with the port to 7.x, then. Hopefully, it will not require much re-rolling.

EvanDonovan’s picture

Status: Patch (to be ported) » Fixed

Ported and added to 7.x-2.x. Seems to be working, but haven't done very intensive tests yet. Will be doing those shortly for my current project.

Since I was behind on porting your patches to sf_import from 6.x-2.x, I rolled most of them into this commit. Hope that's OK: http://drupalcode.org/project/salesforce.git/commit/15fb273.

By the way, I discovered some issues while porting that looked like they might have been issues previously. When I have more time, I could try to describe those.

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Updated issue summary.