formie icon indicating copy to clipboard operation
formie copied to clipboard

[SalesForce] Lead are not saved

Open umkasanki opened this issue 2 years ago • 2 comments

Description The leads are not saved in Salesforce anymore. We have checked and the issue is with the Country field. When we disable the Country field in the form settings, the integration works and the lead is sent to SF. When it's enabled, the integration breaks.

Sentry: 2022-06-30 12:11:10 [-][1609][-][error][formie] Salesforce: API error: “[{"message":"There's a problem with this country, even though it may appear correct. Please select a country/territory from the list of valid countries.: Country","errorCode":"FIELD_INTEGRITY_EXCEPTION","fields":["Country"]}]” /app/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

Lead mapping: изображение

Form изображение

изображение

изображение

изображение

изображение

Steps to reproduce

  1. Add SF integration
  2. Setup Lead with country from phone
  3. Submit form

Form settings

Please pick from the options below.

  • Multi-page form: No
  • Submission Method: Ajax
  • Client-side Validation: Yes
  • Custom Form Templates: YNo

Additional info

  • Plugin version: 1.6.1
  • Craft version: Craft Pro 3.7.46
  • Multi-site: Yes or No

Additional context

umkasanki avatar Jun 30 '22 10:06 umkasanki

Right, so the country value from a phone number field will only be the ISO value for the country that it resolves to. I believe Salesforce will need the full country name, which is not something the Phone field supports (yet).

We'll probably need to look into a way to provide both the ISO code and full country name and the ability to select either one from the integration settings.

I would recommend removing that mapping and using a proper Address or Text field if you need to capture the country information from the user. Or there are events you can use to modify the payload sent to Salesforce through PHP, you can lookup the full country name from the ISO code and swap it out.

engram-design avatar Jul 01 '22 10:07 engram-design

Got It. Added event

umkasanki avatar Jul 04 '22 09:07 umkasanki

Added the ability to pick the country ISO and full name for the next release. To get this early, change your verbb/formie requirement in composer.json to:

"require": {
  "verbb/formie": "dev-craft-4 as 2.0.10",
  "...": "..."
}

Then run composer update.

engram-design avatar Sep 13 '22 11:09 engram-design

Added in 2.0.11

engram-design avatar Sep 18 '22 06:09 engram-design

Hi @engram-design . Previously we used this code to fix the country:

        Event::on(Submissions::class, Submissions::EVENT_BEFORE_TRIGGER_INTEGRATION, static function(TriggerIntegrationEvent $event) {
            // Salesforce integration
            if ($event->integration instanceof Salesforce) {
                /* @var Submission $submission */
                $submission = $event->submission;
                $phoneNumber = $submission->phoneNumber;
                if (true === isset($phoneNumber) && $phoneNumber instanceof \verbb\formie\models\Phone && true === isset($phoneNumber->country)) {
                    $countryIsoMap = Craft::$app->config->getConfigFromFile('formie')['customCountries'];
                    $submission->phoneNumber->country = $countryIsoMap[$phoneNumber->country];
                }
            }
        });

This worked fine until the Craft update to v4. After the update, this trick stopped working :(

Salesforce: API error: “[{"message":"There's a problem with this country, even though it may appear correct. Please select a country/territory from the list of valid countries.: Country","errorCode":"FIELD_INTEGRITY_EXCEPTION","fields":["Country"]}]” /home/forge/builds/bkbn/master/61/app/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113

Could you check what could be the problem? Thanks.

Craft Pro 4.3.6 Formie |2.0.20

umkasanki avatar Jan 11 '23 16:01 umkasanki

Might have something to do with:

$submission->phoneNumber->country = $countryIsoMap[$phoneNumber->country];

Which isn't the correct way to set element field values in Craft 4.

$phoneNumber = $submission->phoneNumber;
$phoneNumber->country = $countryIsoMap[$phoneNumber->country];

$submission->setFieldValue('phoneNumber', $phoneNumber);

engram-design avatar Jan 11 '23 21:01 engram-design

Thanks Josh! Awesome support!

umkasanki avatar Jan 12 '23 08:01 umkasanki