I have installed this module and added login information. I am able to use the "Examine Data Structure" Test/Demo to list my salesforce standard and custom object definitions. However, when I use the other Test/Demo options like "Export your user account as a contact" I get a warning at top of the screen:

warning: Invalid argument supplied for foreach() in /home/sapkerb1/public_html/drupal/sites/all/modules/salesforce/salesforce_api/salesforce_api.module on line 575.

In the bottom half of the screen I see an error because salesforce is telling me that a required field is missing - [LastName]. This is understandable, but I am not sure why the warning is shown and hence I have opened this ticket.

Comments

aaronbauman’s picture

Priority: Normal » Minor

line 575 loops through the relevant fieldmap's fields array.
If php throws a warning, then perhaps you haven't defined any fields to be mapped to Salesforce.

TimAlsop’s picture

I have just installed the module, added login details and then tried to use the Test/Demo features. This is when I get this warning. I have not defined any fieldmaps - I have opened another ticket for that. Is this warning shown because I need to create a fieldmap for user object in drupal to map to contact in salesforce before I can use the Test/Demo ?

TimAlsop’s picture

I defined a fieldmap for user account to contact mapping - now the warning is not shown.

Maybe a better error can be shown when there is no fieldmap setup for the object, instead of a php warning which is not easy to understand ?

aaronbauman’s picture

Title: warning: Invalid argument supplied for foreach() in /home/sapkerb1/public_html/drupal/sites/all/modules/salesforce/salesforce_ap » Test / Demo exports need to be rewritten
Component: User interface » Code
Priority: Minor » Normal

Tim,
Upon closer examination, I see that the demo export function arbitrarily chooses fieldmaps with id 1 (for a Contact) and id 10 (for a Campaign). It's a wonder the demo ever worked. Perhaps in the past these fieldmaps were created automatically, but this will almost always fail unless the user follows a very specific set of steps.

Even if we try to use a fieldmap created by the user, certainly we'll run into issues like failing validation.
Finally, it's not necessary to use a fieldmap to demonstrate that the salesforce api works.

here are some ideas of how to fix the test / demo:

  • the test / demo calls sf->client->upsert directly, populate random values or existing drupal object (easiest)
  • the test / demo forces the user to create a fieldmap first, populate random values or an existing drupal object (more reliable, less user friendly)
  • salesforce module provides an example / default fieldmap, populate random values (more difficult, potentially more useful)
  • provide a custom form for the user to choose their preferred salesforce (and/or fieldmap) and enter their own values or choose an existing drupal object (also more difficult, arguably most useful)
TimAlsop’s picture

Aaron,

I think it is ok for the fieldmap used by the test/demo to be created when the module is installed. The reason for this, is that the contact object in salesforce is a standard object, so the required fields can be configured and mapped in the fieldmap, and are unlikely to require changes. If for some reason the module user has special requirements, they can change the pre-installed fieldmap and then use the test/demo button. The test/demo button would need to check if the fieldmap for contact<->user is created and give friendly message if not, which would be the case if it has been manually removed after installation of the module.

Regarding the campaign - I am a bit confused as to why a salesforce campaing would ever need to be kept in sync with a drupal object - there are valid use cases for case, contact, account, lead etc. but campaign is used for marketing campaign tracking and a campaign record is only created when a marketing manager sets up a new lead generation campaign, then each lead/contact which relates to the campaign links to the campaign which was created by the marketing department.

Thanks,
Tim

aaronbauman’s picture

Tim:
If a default fieldmap is provided for user->Contact, I think we can safely omit any demo dealing with "Campaign" object.

TimAlsop’s picture

Yes, I agree. Also, perhaps the default objects should just be lead and contact instead of lead/contact/campaign.

aaronbauman’s picture

Status: Active » Fixed

Implemented new hook_default_salesforce_field_maps and implementations for sf_node and sf_user (latest dev).
sf_user and sf_node now ship with default fieldmaps for User object and Page node, which can be overridden.
Both of these fieldmaps are now used in the demo section.

http://drupal.org/cvs?commit=372240

Status: Fixed » Closed (fixed)

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

EvanDonovan’s picture

Status: Closed (fixed) » Active

Sorry to reopen this issue, but I am revisiting the demos for 7.x-2.x, and it looks like Tim still has a valid point - why is Node:Page->Campaign the default fieldmapping. Node->Case would be a much better example of a valid use case for this module. Would you be open to changing the default node fieldmapping accordingly?

kostajh’s picture

I don't have any objections to that.

EvanDonovan’s picture

Ok, I'll probably do that in the next few weeks on 7.x at least.

EvanDonovan’s picture

Status: Active » Closed (fixed)