formie
formie copied to clipboard
[SalesForce] Lead are not saved
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
- Add SF integration
- Setup Lead with country from phone
- 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
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.
Got It. Added event
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
.
Added in 2.0.11
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
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);
Thanks Josh! Awesome support!