{
    "timestamp": "2026-03-18 15:55:14",
    "message": "❌ Impossible de déterminer le convertedStatus du Lead via \/describe",
    "context": []
}
{
    "timestamp": "2026-03-18 15:55:15",
    "message": "❌ Create Contact failed",
    "context": {
        "http": 400,
        "res": [
            {
                "duplicateResult": {
                    "allowSave": true,
                    "duplicateRule": "Standard_Contact_Duplicate_Rule",
                    "duplicateRuleEntityType": "Contact",
                    "errorMessage": "You're creating a duplicate record. We recommend you use an existing record instead.",
                    "matchResults": [
                        {
                            "entityType": "Lead",
                            "errors": [],
                            "matchEngine": "FuzzyMatchEngine",
                            "matchRecords": [
                                {
                                    "additionalInformation": [],
                                    "fieldDiffs": [],
                                    "matchConfidence": 100,
                                    "record": {
                                        "attributes": {
                                            "type": "Lead",
                                            "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000Ro0LRMAZ"
                                        },
                                        "Id": "00QAs00000Ro0LRMAZ"
                                    }
                                }
                            ],
                            "rule": "Standard_Lead_Match_Rule_v1_0",
                            "size": 1,
                            "success": true
                        }
                    ]
                },
                "errorCode": "DUPLICATES_DETECTED",
                "message": "You're creating a duplicate record. We recommend you use an existing record instead."
            }
        ],
        "client": {
            "FirstName": "Second",
            "LastName": "Test",
            "Email": "secondtest@gmail.com",
            "Phone": "",
            "Post": ""
        },
        "accountId": "001As00000ulKPdIAM"
    }
}
{
    "timestamp": "2026-03-18 16:02:51",
    "message": "❌ Impossible de déterminer le convertedStatus du Lead via \/describe",
    "context": []
}
{
    "timestamp": "2026-03-18 16:02:52",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006As00000ONXFBIA5",
        "contactId": "003As00000zlbgxIAA",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-03-18 16:02:53",
    "message": "⚠️ Impossible de déterminer convertedStatus pour Lead. Conversion ignorée (opp existante réutilisée).",
    "context": {
        "leadId": "00QAs00000Ro0LRMAZ"
    }
}
{
    "timestamp": "2026-03-18 16:02:54",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-03-18 16:02:54",
    "message": "❌ Create Visited_Unit__c failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "Type de visite: bad value for restricted picklist field: Visite",
                "errorCode": "INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST",
                "fields": [
                    "Type_de_visite_c__c"
                ]
            }
        ],
        "payload": {
            "Visite__c": "a03As00000zlbnPIAQ",
            "Asset__c": "02iAs000005NkJHIA0",
            "RecordTypeId": "0128a000000tkjSAAQ",
            "Type_de_visite_c__c": "Visite",
            "Notes__c": "",
            "Comments__c": "",
            "Positive_Aspects__c": "",
            "Negative_Aspects__c": ""
        }
    }
}
{
    "timestamp": "2026-03-18 16:02:54",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000ONXFBIA5",
        "VisitId": "a03As00000zlbnPIAQ",
        "VisitMode": "update",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": false,
                "unit": "1153",
                "http": 400,
                "res": [
                    {
                        "message": "Type de visite: bad value for restricted picklist field: Visite",
                        "errorCode": "INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST",
                        "fields": [
                            "Type_de_visite_c__c"
                        ]
                    }
                ]
            }
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Philippe",
            "LastName": "LaRochelle",
            "Email": "philippe@minuitmoinsune.com",
            "Job": "Artiste 3D - Associé"
        },
        "Clients": [
            {
                "FirstName": "Philippe",
                "LastName": "LaRochelle",
                "Email": "philippe@minuitmoinsune.com",
                "Phone": "4188888888",
                "Post": "5454"
            },
            {
                "FirstName": "Yannick",
                "LastName": "Gilbert",
                "Email": "Yannick@minuitmoinsune.com",
                "Phone": "4555555555",
                "Post": "454"
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.03.18",
            "VisitTime": 321.6983642578125,
            "Pet": "Gros chien de 36lbs",
            "UnitsSeeked": [
                "3.5",
                "4.5"
            ],
            "Comment": "Ceci est une note au vendeur, 123."
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "philippe@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": null
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('philippe@minuitmoinsune.com','Yannick@minuitmoinsune.com') OR Phone IN ('4188888888','4555555555'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "philippe@minuitmoinsune.com",
            "Yannick@minuitmoinsune.com"
        ],
        "phones": [
            "4188888888",
            "4555555555"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Philippe",
                "LastName": "LaRochelle",
                "Email": "philippe@minuitmoinsune.com",
                "Phone": "4188888888",
                "Post": "5454"
            },
            {
                "FirstName": "Yannick",
                "LastName": "Gilbert",
                "Email": "Yannick@minuitmoinsune.com",
                "Phone": "4555555555",
                "Post": "454"
            }
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:15",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "philippe@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As00000zlN1JIAU"
                    },
                    "Id": "003As00000zlN1JIAU",
                    "AccountId": "001As00000ul27tIAA",
                    "Email": "philippe@minuitmoinsune.com",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Philippe",
                    "LastName": "LaRochelle"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "philippe@minuitmoinsune.com",
        "phone": "4188888888",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As00000zlN1JIAU"
            },
            "Id": "003As00000zlN1JIAU",
            "AccountId": "001As00000ul27tIAA",
            "Email": "philippe@minuitmoinsune.com",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Philippe",
            "LastName": "LaRochelle"
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001As00000ul27tIAA"
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "philippe@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As00000zlN1JIAU"
                    },
                    "Id": "003As00000zlN1JIAU",
                    "AccountId": "001As00000ul27tIAA",
                    "Email": "philippe@minuitmoinsune.com",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Philippe",
                    "LastName": "LaRochelle"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "philippe@minuitmoinsune.com",
        "phone": "4188888888",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As00000zlN1JIAU"
            },
            "Id": "003As00000zlN1JIAU",
            "AccountId": "001As00000ul27tIAA",
            "Email": "philippe@minuitmoinsune.com",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Philippe",
            "LastName": "LaRochelle"
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As00000zlN1JIAU",
        "accountId": "001As00000ul27tIAA"
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Yannick@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As00000yb6yMIAQ"
                    },
                    "Id": "003As00000yb6yMIAQ",
                    "AccountId": "001As00000tgz0zIAA",
                    "Email": "yannick@minuitmoinsune.com",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Yannick",
                    "LastName": "Gilbert"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:16",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "Yannick@minuitmoinsune.com",
        "phone": "4555555555",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As00000yb6yMIAQ"
            },
            "Id": "003As00000yb6yMIAQ",
            "AccountId": "001As00000tgz0zIAA",
            "Email": "yannick@minuitmoinsune.com",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Yannick",
            "LastName": "Gilbert"
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact re-parented to family account",
    "context": {
        "contactId": "003As00000yb6yMIAQ",
        "fromAccountId": "001As00000tgz0zIAA",
        "toAccountId": "001As00000ul27tIAA"
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As00000yb6yMIAQ",
        "accountId": "001As00000ul27tIAA"
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000ul27tIAA",
        "contactIds": [
            "003As00000zlN1JIAU",
            "003As00000yb6yMIAQ"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Philippe LaRochelle",
            "StageName": "Qualification",
            "CloseDate": "2026-04-23",
            "AccountId": "001As00000ul27tIAA",
            "Description": "Ceci est une note au vendeur, 123.",
            "Contact__c": "003As00000zlN1JIAU",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As00000zlN1JIAU"
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As00000zlN1JIAU",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As00000zlN1JIAU'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "OpportunityContactRole",
                        "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KAs00000deFGPMA2"
                    },
                    "OpportunityId": "006As00000ONR89IAH",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006As00000ONR89IAH"
                        },
                        "Id": "006As00000ONR89IAH",
                        "Name": "Philippe LaRochelle",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-03-18T13:56:44.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006As00000ONR89IAH",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KAs00000deFGPMA2"
            },
            "OpportunityId": "006As00000ONR89IAH",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006As00000ONR89IAH"
                },
                "Id": "006As00000ONR89IAH",
                "Name": "Philippe LaRochelle",
                "StageName": "Qualification",
                "CreatedDate": "2026-03-18T13:56:44.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006As00000ONR89IAH"
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006As00000ONR89IAH",
        "contactId": "003As00000zlN1JIAU",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-03-24 18:11:20",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000ONR89IAH",
            "Contact_1__c": "003As00000zlN1JIAU",
            "Contact_2__c": "003As00000yb6yMIAQ",
            "Meeting_Date_Time__c": "2026-03-18T18:11:20Z",
            "Meeting_Notes__c": "Ceci est une note au vendeur, 123.",
            "Visit_Duration__c": 6
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:22",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As0000103oB3IAI",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As0000103oB3IAI",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:22",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "4204_mtrl",
            "3803_mtrl",
            "3603_mtrl",
            "4202_mtrl"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:22",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-03-24 18:11:22",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-03-24 18:11:22",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": {
            "3803": {
                "Unit": "3803",
                "ServicesAndOptionsIncluded": [
                    "Internet haute vitesse",
                    "Air climatisé",
                    "Eau chaude",
                    "Piscine au toit",
                    "Salle de loisirs",
                    "Salle de cinéma",
                    "Simulateur de golf"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Stationnement intérieur",
                        "Number": 1,
                        "Price": 125
                    }
                ],
                "ServicesAndOptionsPrice": 125,
                "UnitPrice": 4780,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 4905
            },
            "4202": {
                "Unit": "4202",
                "ServicesAndOptionsIncluded": [
                    "Internet haute vitesse",
                    "Air climatisé",
                    "Eau chaude",
                    "Piscine au toit",
                    "Salle de loisirs",
                    "Salle de cinéma",
                    "Simulateur de golf"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Stationnement intérieur",
                        "Number": 1,
                        "Price": 125
                    }
                ],
                "ServicesAndOptionsPrice": 125,
                "UnitPrice": 3940,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 4065
            }
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:25",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000ONR89IAH",
        "VisitId": "a03As0000103oB3IAI",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": false,
                "unit": "4204_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "3803_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "3603_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "4202_mtrl",
                "error": "Asset introuvable (lookup smart)."
            }
        ]
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Philippe",
            "LastName": "LaRochelle",
            "Email": "philippe@minuitmoinsune.com",
            "Job": "Artiste 3D - Associé"
        },
        "Clients": [
            {
                "FirstName": "Lead",
                "LastName": "Test",
                "Email": "leadtest@lead.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.03.18",
            "VisitTime": 321.6983642578125,
            "Pet": "Gros chien de 36lbs",
            "UnitsSeeked": [
                "3.5",
                "4.5"
            ],
            "Comment": "Ceci est une note au vendeur, 123."
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "philippe@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": null
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('leadtest@lead.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "leadtest@lead.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Lead",
                        "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000RuXoCMAV"
                    },
                    "Id": "00QAs00000RuXoCMAV",
                    "FirstName": "Lead",
                    "LastName": "Test",
                    "Company": "Test",
                    "Email": "leadtest@lead.ca",
                    "Phone": null,
                    "Status": "New",
                    "IsConverted": false,
                    "ConvertedOpportunityId": null
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000RuXoCMAV"
            },
            "Id": "00QAs00000RuXoCMAV",
            "FirstName": "Lead",
            "LastName": "Test",
            "Company": "Test",
            "Email": "leadtest@lead.ca",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000RuXoCMAV"
            },
            "Id": "00QAs00000RuXoCMAV",
            "FirstName": "Lead",
            "LastName": "Test",
            "Company": "Test",
            "Email": "leadtest@lead.ca",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - lead trouvé, entrée dans le flow de conversion",
    "context": {
        "leadId": "00QAs00000RuXoCMAV",
        "leadEmail": "leadtest@lead.ca",
        "leadStatus": "New"
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - convertedStatus",
    "context": {
        "convertedStatus": "Qualified"
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "leadtest@lead.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "leadtest@lead.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - contact existant avant conversion Lead",
    "context": {
        "primaryEmail": "leadtest@lead.ca",
        "existingContact": null
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG create_all - payload conversion Lead final",
    "context": {
        "leadId": "00QAs00000RuXoCMAV",
        "convertPayload": {
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Lead Test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:11:57",
    "message": "DEBUG sf_convert_lead - URL Apex REST appelée",
    "context": {
        "instanceUrl": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com",
        "url": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com\/services\/apexrest\/convertLead",
        "payload": {
            "leadId": "00QAs00000RuXoCMAV",
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Lead Test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG sf_convert_lead - réponse conversion via Apex REST",
    "context": {
        "leadId": "00QAs00000RuXoCMAV",
        "http": 200,
        "res": "{\"errors\":[],\"leadId\":\"00QAs00000RuXoCMAV\",\"opportunityId\":\"006As00000OUDMzIAP\",\"contactId\":\"003As0000103e6uIAA\",\"accountId\":\"001As00000v2pSIIAY\",\"success\":true}"
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG create_all - résultat conversion Lead",
    "context": {
        "leadConversion": {
            "leadId": "00QAs00000RuXoCMAV",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Lead Test"
            },
            "res": "{\"errors\":[],\"leadId\":\"00QAs00000RuXoCMAV\",\"opportunityId\":\"006As00000OUDMzIAP\",\"contactId\":\"003As0000103e6uIAA\",\"accountId\":\"001As00000v2pSIIAY\",\"success\":true}"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "❌ Lead conversion failed; fallback to classic create",
    "context": {
        "leadConversion": {
            "leadId": "00QAs00000RuXoCMAV",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Lead Test"
            },
            "res": "{\"errors\":[],\"leadId\":\"00QAs00000RuXoCMAV\",\"opportunityId\":\"006As00000OUDMzIAP\",\"contactId\":\"003As0000103e6uIAA\",\"accountId\":\"001As00000v2pSIIAY\",\"success\":true}"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "leadtest@lead.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103e6uIAA"
                    },
                    "Id": "003As0000103e6uIAA",
                    "AccountId": "001As00000v2pSIIAY",
                    "Email": "leadtest@lead.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Lead",
                    "LastName": "Test"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "leadtest@lead.ca",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103e6uIAA"
            },
            "Id": "003As0000103e6uIAA",
            "AccountId": "001As00000v2pSIIAY",
            "Email": "leadtest@lead.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Lead",
            "LastName": "Test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001As00000v2pSIIAY"
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "leadtest@lead.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103e6uIAA"
                    },
                    "Id": "003As0000103e6uIAA",
                    "AccountId": "001As00000v2pSIIAY",
                    "Email": "leadtest@lead.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Lead",
                    "LastName": "Test"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "leadtest@lead.ca",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103e6uIAA"
            },
            "Id": "003As0000103e6uIAA",
            "AccountId": "001As00000v2pSIIAY",
            "Email": "leadtest@lead.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Lead",
            "LastName": "Test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As0000103e6uIAA",
        "accountId": "001As00000v2pSIIAY"
    }
}
{
    "timestamp": "2026-03-24 18:12:02",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000v2pSIIAY",
        "contactIds": [
            "003As0000103e6uIAA"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Lead Test",
            "StageName": "Qualification",
            "CloseDate": "2026-04-23",
            "AccountId": "001As00000v2pSIIAY",
            "Description": "Ceci est une note au vendeur, 123.",
            "Contact__c": "003As0000103e6uIAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As0000103e6uIAA"
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As0000103e6uIAA",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As0000103e6uIAA'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "OpportunityContactRole",
                        "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KAs00000djLl2MAE"
                    },
                    "OpportunityId": "006As00000OUDMzIAP",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006As00000OUDMzIAP"
                        },
                        "Id": "006As00000OUDMzIAP",
                        "Name": "Lead Test",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-03-24T18:12:00.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006As00000OUDMzIAP",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KAs00000djLl2MAE"
            },
            "OpportunityId": "006As00000OUDMzIAP",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006As00000OUDMzIAP"
                },
                "Id": "006As00000OUDMzIAP",
                "Name": "Lead Test",
                "StageName": "Qualification",
                "CreatedDate": "2026-03-24T18:12:00.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006As00000OUDMzIAP"
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006As00000OUDMzIAP",
        "contactId": "003As0000103e6uIAA",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG create_all - tentative conversion Lead sans création d'Opportunity",
    "context": {
        "leadId": "00QAs00000RuXoCMAV",
        "convertPayload": {
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": true,
            "accountId": "001As00000v2pSIIAY",
            "contactId": "003As0000103e6uIAA"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG sf_convert_lead - URL Apex REST appelée",
    "context": {
        "instanceUrl": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com",
        "url": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com\/services\/apexrest\/convertLead",
        "payload": {
            "leadId": "00QAs00000RuXoCMAV",
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": true,
            "accountId": "001As00000v2pSIIAY",
            "contactId": "003As0000103e6uIAA"
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG sf_convert_lead - réponse conversion via Apex REST",
    "context": {
        "leadId": "00QAs00000RuXoCMAV",
        "http": 500,
        "res": [
            {
                "errorCode": "APEX_ERROR",
                "message": "System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, This lead was already converted to the contact Lead Test on 2026-03-24.: []\n\nClass.LeadConverterAPI.convertLead: line 38, column 1"
            }
        ]
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "ℹ️ Lead converted without Opportunity (existing opp reused)",
    "context": {
        "http": 500,
        "resp": [
            {
                "errorCode": "APEX_ERROR",
                "message": "System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, This lead was already converted to the contact Lead Test on 2026-03-24.: []\n\nClass.LeadConverterAPI.convertLead: line 38, column 1"
            }
        ],
        "mode": "convert_no_opportunity"
    }
}
{
    "timestamp": "2026-03-24 18:12:03",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000OUDMzIAP",
            "Contact_1__c": "003As0000103e6uIAA",
            "Meeting_Date_Time__c": "2026-03-18T18:12:03Z",
            "Meeting_Notes__c": "Ceci est une note au vendeur, 123.",
            "Visit_Duration__c": 6
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:04",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As0000103iiMIAQ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As0000103iiMIAQ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:04",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "4204_mtrl",
            "3803_mtrl",
            "3603_mtrl",
            "4202_mtrl"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:12:04",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-03-24 18:12:04",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-03-24 18:12:04",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": {
            "3803": {
                "Unit": "3803",
                "ServicesAndOptionsIncluded": [
                    "Internet haute vitesse",
                    "Air climatisé",
                    "Eau chaude",
                    "Piscine au toit",
                    "Salle de loisirs",
                    "Salle de cinéma",
                    "Simulateur de golf"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Stationnement intérieur",
                        "Number": 1,
                        "Price": 125
                    }
                ],
                "ServicesAndOptionsPrice": 125,
                "UnitPrice": 4780,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 4905
            },
            "4202": {
                "Unit": "4202",
                "ServicesAndOptionsIncluded": [
                    "Internet haute vitesse",
                    "Air climatisé",
                    "Eau chaude",
                    "Piscine au toit",
                    "Salle de loisirs",
                    "Salle de cinéma",
                    "Simulateur de golf"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Stationnement intérieur",
                        "Number": 1,
                        "Price": 125
                    }
                ],
                "ServicesAndOptionsPrice": 125,
                "UnitPrice": 3940,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 4065
            }
        }
    }
}
{
    "timestamp": "2026-03-24 18:12:08",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000OUDMzIAP",
        "VisitId": "a03As0000103iiMIAQ",
        "VisitMode": "create",
        "LeadConversion": {
            "http": 500,
            "resp": [
                {
                    "errorCode": "APEX_ERROR",
                    "message": "System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, This lead was already converted to the contact Lead Test on 2026-03-24.: []\n\nClass.LeadConverterAPI.convertLead: line 38, column 1"
                }
            ],
            "mode": "convert_no_opportunity"
        },
        "VisitedUnits": [
            {
                "ok": false,
                "unit": "4204_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "3803_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "3603_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "4202_mtrl",
                "error": "Asset introuvable (lookup smart)."
            }
        ]
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Philippe",
            "LastName": "LaRochelle",
            "Email": "philippe@minuitmoinsune.com",
            "Job": "Artiste 3D - Associé"
        },
        "Clients": [
            {
                "FirstName": "Test",
                "LastName": "Test",
                "Email": "test@test.test",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.03.18",
            "VisitTime": 321.6983642578125,
            "Pet": "Gros chien de 36lbs",
            "UnitsSeeked": [
                "3.5",
                "4.5"
            ],
            "Comment": "Ceci est une note au vendeur, 123."
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "philippe@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": null
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('test@test.test'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "test@test.test"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Lead",
                        "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000RuWKQMA3"
                    },
                    "Id": "00QAs00000RuWKQMA3",
                    "FirstName": "Test",
                    "LastName": "test",
                    "Company": "test",
                    "Email": "test@test.test",
                    "Phone": null,
                    "Status": "New",
                    "IsConverted": false,
                    "ConvertedOpportunityId": null
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000RuWKQMA3"
            },
            "Id": "00QAs00000RuWKQMA3",
            "FirstName": "Test",
            "LastName": "test",
            "Company": "test",
            "Email": "test@test.test",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QAs00000RuWKQMA3"
            },
            "Id": "00QAs00000RuWKQMA3",
            "FirstName": "Test",
            "LastName": "test",
            "Company": "test",
            "Email": "test@test.test",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - lead trouvé, entrée dans le flow de conversion",
    "context": {
        "leadId": "00QAs00000RuWKQMA3",
        "leadEmail": "test@test.test",
        "leadStatus": "New"
    }
}
{
    "timestamp": "2026-03-24 18:35:10",
    "message": "DEBUG create_all - convertedStatus",
    "context": {
        "convertedStatus": "Qualified"
    }
}
{
    "timestamp": "2026-03-24 18:35:11",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "test@test.test",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:11",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "test@test.test",
        "phone": null
    }
}
{
    "timestamp": "2026-03-24 18:35:11",
    "message": "DEBUG create_all - contact existant avant conversion Lead",
    "context": {
        "primaryEmail": "test@test.test",
        "existingContact": null
    }
}
{
    "timestamp": "2026-03-24 18:35:11",
    "message": "DEBUG create_all - payload conversion Lead final",
    "context": {
        "leadId": "00QAs00000RuWKQMA3",
        "convertPayload": {
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Test Test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:11",
    "message": "DEBUG sf_convert_lead - URL Apex REST appelée",
    "context": {
        "instanceUrl": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com",
        "url": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com\/services\/apexrest\/convertLead",
        "payload": {
            "leadId": "00QAs00000RuWKQMA3",
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Test Test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG sf_convert_lead - réponse conversion via Apex REST",
    "context": {
        "leadId": "00QAs00000RuWKQMA3",
        "http": 200,
        "res": "{\"errors\":[],\"leadId\":\"00QAs00000RuWKQMA3\",\"opportunityId\":\"006As00000OUEHRIA5\",\"contactId\":\"003As0000103cjvIAA\",\"accountId\":\"001As00000v2sziIAA\",\"success\":true}"
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG create_all - résultat conversion Lead",
    "context": {
        "leadConversion": {
            "leadId": "00QAs00000RuWKQMA3",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Test Test"
            },
            "res": "{\"errors\":[],\"leadId\":\"00QAs00000RuWKQMA3\",\"opportunityId\":\"006As00000OUEHRIA5\",\"contactId\":\"003As0000103cjvIAA\",\"accountId\":\"001As00000v2sziIAA\",\"success\":true}"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "❌ Lead conversion failed; fallback to classic create",
    "context": {
        "leadConversion": {
            "leadId": "00QAs00000RuWKQMA3",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Test Test"
            },
            "res": "{\"errors\":[],\"leadId\":\"00QAs00000RuWKQMA3\",\"opportunityId\":\"006As00000OUEHRIA5\",\"contactId\":\"003As0000103cjvIAA\",\"accountId\":\"001As00000v2sziIAA\",\"success\":true}"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "test@test.test",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103cjvIAA"
                    },
                    "Id": "003As0000103cjvIAA",
                    "AccountId": "001As00000v2sziIAA",
                    "Email": "test@test.test",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Test",
                    "LastName": "test"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "test@test.test",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103cjvIAA"
            },
            "Id": "003As0000103cjvIAA",
            "AccountId": "001As00000v2sziIAA",
            "Email": "test@test.test",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Test",
            "LastName": "test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001As00000v2sziIAA"
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "test@test.test",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103cjvIAA"
                    },
                    "Id": "003As0000103cjvIAA",
                    "AccountId": "001As00000v2sziIAA",
                    "Email": "test@test.test",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Test",
                    "LastName": "test"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "test@test.test",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As0000103cjvIAA"
            },
            "Id": "003As0000103cjvIAA",
            "AccountId": "001As00000v2sziIAA",
            "Email": "test@test.test",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Test",
            "LastName": "test"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As0000103cjvIAA",
        "accountId": "001As00000v2sziIAA"
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000v2sziIAA",
        "contactIds": [
            "003As0000103cjvIAA"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Test Test",
            "StageName": "Qualification",
            "CloseDate": "2026-04-23",
            "AccountId": "001As00000v2sziIAA",
            "Description": "Ceci est une note au vendeur, 123.",
            "Contact__c": "003As0000103cjvIAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As0000103cjvIAA"
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As0000103cjvIAA",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As0000103cjvIAA'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "OpportunityContactRole",
                        "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KAs00000djLjQMAU"
                    },
                    "OpportunityId": "006As00000OUEHRIA5",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006As00000OUEHRIA5"
                        },
                        "Id": "006As00000OUEHRIA5",
                        "Name": "Test Test",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-03-24T18:35:11.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006As00000OUEHRIA5",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KAs00000djLjQMAU"
            },
            "OpportunityId": "006As00000OUEHRIA5",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006As00000OUEHRIA5"
                },
                "Id": "006As00000OUEHRIA5",
                "Name": "Test Test",
                "StageName": "Qualification",
                "CreatedDate": "2026-03-24T18:35:11.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006As00000OUEHRIA5"
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006As00000OUEHRIA5",
        "contactId": "003As0000103cjvIAA",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG create_all - tentative conversion Lead sans création d'Opportunity",
    "context": {
        "leadId": "00QAs00000RuWKQMA3",
        "convertPayload": {
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": true,
            "accountId": "001As00000v2sziIAA",
            "contactId": "003As0000103cjvIAA"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:13",
    "message": "DEBUG sf_convert_lead - URL Apex REST appelée",
    "context": {
        "instanceUrl": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com",
        "url": "https:\/\/gestiontrudelalliance123--artisans.sandbox.my.salesforce.com\/services\/apexrest\/convertLead",
        "payload": {
            "leadId": "00QAs00000RuWKQMA3",
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": true,
            "accountId": "001As00000v2sziIAA",
            "contactId": "003As0000103cjvIAA"
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:14",
    "message": "DEBUG sf_convert_lead - réponse conversion via Apex REST",
    "context": {
        "leadId": "00QAs00000RuWKQMA3",
        "http": 500,
        "res": [
            {
                "errorCode": "APEX_ERROR",
                "message": "System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, This lead was already converted to the contact Test test on 2026-03-24.: []\n\nClass.LeadConverterAPI.convertLead: line 38, column 1"
            }
        ]
    }
}
{
    "timestamp": "2026-03-24 18:35:14",
    "message": "ℹ️ Lead converted without Opportunity (existing opp reused)",
    "context": {
        "http": 500,
        "resp": [
            {
                "errorCode": "APEX_ERROR",
                "message": "System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, This lead was already converted to the contact Test test on 2026-03-24.: []\n\nClass.LeadConverterAPI.convertLead: line 38, column 1"
            }
        ],
        "mode": "convert_no_opportunity"
    }
}
{
    "timestamp": "2026-03-24 18:35:14",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000OUEHRIA5",
            "Contact_1__c": "003As0000103cjvIAA",
            "Meeting_Date_Time__c": "2026-03-18T18:35:14Z",
            "Meeting_Notes__c": "Ceci est une note au vendeur, 123.",
            "Visit_Duration__c": 6
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:14",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As0000103Nk6IAE",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As0000103Nk6IAE",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:14",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "4204_mtrl",
            "3803_mtrl",
            "3603_mtrl",
            "4202_mtrl"
        ]
    }
}
{
    "timestamp": "2026-03-24 18:35:14",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-03-24 18:35:15",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-03-24 18:35:15",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": {
            "3803": {
                "Unit": "3803",
                "ServicesAndOptionsIncluded": [
                    "Internet haute vitesse",
                    "Air climatisé",
                    "Eau chaude",
                    "Piscine au toit",
                    "Salle de loisirs",
                    "Salle de cinéma",
                    "Simulateur de golf"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Stationnement intérieur",
                        "Number": 1,
                        "Price": 125
                    }
                ],
                "ServicesAndOptionsPrice": 125,
                "UnitPrice": 4780,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 4905
            },
            "4202": {
                "Unit": "4202",
                "ServicesAndOptionsIncluded": [
                    "Internet haute vitesse",
                    "Air climatisé",
                    "Eau chaude",
                    "Piscine au toit",
                    "Salle de loisirs",
                    "Salle de cinéma",
                    "Simulateur de golf"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Stationnement intérieur",
                        "Number": 1,
                        "Price": 125
                    }
                ],
                "ServicesAndOptionsPrice": 125,
                "UnitPrice": 3940,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 4065
            }
        }
    }
}
{
    "timestamp": "2026-03-24 18:35:18",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000OUEHRIA5",
        "VisitId": "a03As0000103Nk6IAE",
        "VisitMode": "create",
        "LeadConversion": {
            "http": 500,
            "resp": [
                {
                    "errorCode": "APEX_ERROR",
                    "message": "System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, This lead was already converted to the contact Test test on 2026-03-24.: []\n\nClass.LeadConverterAPI.convertLead: line 38, column 1"
                }
            ],
            "mode": "convert_no_opportunity"
        },
        "VisitedUnits": [
            {
                "ok": false,
                "unit": "4204_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "3803_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "3603_mtrl",
                "error": "Asset introuvable (lookup smart)."
            },
            {
                "ok": false,
                "unit": "4202_mtrl",
                "error": "Asset introuvable (lookup smart)."
            }
        ]
    }
}
{
    "timestamp": "2026-04-08 14:35:50",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "John",
                "LastName": "Wick",
                "Email": "john.wick.actif2prep@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.04.08",
            "VisitTime": 66.093536376953125,
            "Pet": "",
            "UnitsSeeked": [
                "3.5",
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:50",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "thomas.raymond@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000001ng5aYAA"
                    },
                    "Id": "005OF000001ng5aYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('john.wick.actif2prep@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "john.wick.actif2prep@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "John",
                "LastName": "Wick",
                "Email": "john.wick.actif2prep@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-04-08 14:35:51",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-04-08 14:35:52",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001As00000vgHEvIAM",
        "payload": {
            "Name": "John Wick",
            "Phone": null,
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:52",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:52",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-04-08 14:35:52",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-04-08 14:35:57",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003As000010iaTvIAI",
        "accountId": "001As00000vgHEvIAM",
        "payload": {
            "FirstName": "John",
            "LastName": "Wick",
            "Email": "john.wick.actif2prep@trudel.ca",
            "Phone": null,
            "AccountId": "001As00000vgHEvIAM",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:57",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000vgHEvIAM",
        "contactIds": [
            "003As000010iaTvIAI"
        ]
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "John Wick",
            "StageName": "Qualification",
            "CloseDate": "2026-05-08",
            "AccountId": "001As00000vgHEvIAM",
            "Description": "",
            "Contact__c": "003As000010iaTvIAI",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As000010iaTvIAI"
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As000010iaTvIAI",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As000010iaTvIAI'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003As000010iaTvIAI"
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-04-08 14:35:58",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "John Wick",
            "StageName": "Qualification",
            "CloseDate": "2026-05-08",
            "AccountId": "001As00000vgHEvIAM",
            "Description": "",
            "Contact__c": "003As000010iaTvIAI",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-04-08 14:36:00",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006As00000OkUYLIA3",
            "success": true,
            "errors": []
        },
        "oppId": "006As00000OkUYLIA3"
    }
}
{
    "timestamp": "2026-04-08 14:36:00",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000OkUYLIA3",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003As000010iaTvIAI",
            "Meeting_Date_Time__c": "2026-04-08T14:36:00Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 2
        }
    }
}
{
    "timestamp": "2026-04-08 14:36:02",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As000010ilAqIAI",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As000010ilAqIAI",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-04-08 14:36:02",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1250_Le18Juillet-2",
            "1476_Le18Juillet-2",
            "1077_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-04-08 14:36:02",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-04-08 14:36:03",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-04-08 14:36:03",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-04-08 14:36:03",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1250_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-08 14:36:04",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1476_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-08 14:36:04",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1077_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-08 14:36:04",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000OkUYLIA3",
        "VisitId": "a03As000010ilAqIAI",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1250_Le18Juillet-2",
                "id": "a01As00000vg6wVIAQ",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1476_Le18Juillet-2",
                "id": "a01As00000vgDkpIAE",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1077_Le18Juillet-2",
                "id": "a01As00000vgDplIAE",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "John",
                "LastName": "Wick",
                "Email": "john.wick.actif2prep@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.04.09",
            "VisitTime": 28.827297210693359375,
            "Pet": "",
            "UnitsSeeked": [
                "3.5",
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "thomas.raymond@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000001ng5aYAA"
                    },
                    "Id": "005OF000001ng5aYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('john.wick.actif2prep@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "john.wick.actif2prep@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "John",
                "LastName": "Wick",
                "Email": "john.wick.actif2prep@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:05",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
                    },
                    "Id": "003As000010iaTvIAI",
                    "AccountId": "001As00000vgHEvIAM",
                    "Email": "john.wick.actif2prep@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "John",
                    "LastName": "Wick"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
            },
            "Id": "003As000010iaTvIAI",
            "AccountId": "001As00000vgHEvIAM",
            "Email": "john.wick.actif2prep@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "John",
            "LastName": "Wick"
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001As00000vgHEvIAM"
    }
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
                    },
                    "Id": "003As000010iaTvIAI",
                    "AccountId": "001As00000vgHEvIAM",
                    "Email": "john.wick.actif2prep@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "John",
                    "LastName": "Wick"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
            },
            "Id": "003As000010iaTvIAI",
            "AccountId": "001As00000vgHEvIAM",
            "Email": "john.wick.actif2prep@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "John",
            "LastName": "Wick"
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As000010iaTvIAI",
        "accountId": "001As00000vgHEvIAM"
    }
}
{
    "timestamp": "2026-04-09 13:34:06",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000vgHEvIAM",
        "contactIds": [
            "003As000010iaTvIAI"
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "John Wick",
            "StageName": "Qualification",
            "CloseDate": "2026-05-09",
            "AccountId": "001As00000vgHEvIAM",
            "Description": "",
            "Contact__c": "003As000010iaTvIAI",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As000010iaTvIAI"
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As000010iaTvIAI",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As000010iaTvIAI'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003As000010iaTvIAI"
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-04-09 13:34:07",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "John Wick",
            "StageName": "Qualification",
            "CloseDate": "2026-05-09",
            "AccountId": "001As00000vgHEvIAM",
            "Description": "",
            "Contact__c": "003As000010iaTvIAI",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:11",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006As00000OlhA9IAJ",
            "success": true,
            "errors": []
        },
        "oppId": "006As00000OlhA9IAJ"
    }
}
{
    "timestamp": "2026-04-09 13:34:11",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000OlhA9IAJ",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003As000010iaTvIAI",
            "Meeting_Date_Time__c": "2026-04-09T13:34:11Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 1
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:13",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As000010ljcIIAQ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As000010ljcIIAQ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:13",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1150_Le18Juillet-2",
            "1276_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:13",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-04-09 13:34:13",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-04-09 13:34:13",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-04-09 13:34:14",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1150_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-09 13:34:14",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1276_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-09 13:34:14",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000OlhA9IAJ",
        "VisitId": "a03As000010ljcIIAQ",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1150_Le18Juillet-2",
                "id": "a01As00000vjXQRIA2",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1276_Le18Juillet-2",
                "id": "a01As00000vjP9XIAU",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "John",
                "LastName": "Wick",
                "Email": "john.wick.actif2prep@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.04.09",
            "VisitTime": 28.827297210693359375,
            "Pet": "",
            "UnitsSeeked": [
                "3.5",
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "thomas.raymond@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000001ng5aYAA"
                    },
                    "Id": "005OF000001ng5aYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('john.wick.actif2prep@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "john.wick.actif2prep@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "John",
                "LastName": "Wick",
                "Email": "john.wick.actif2prep@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
                    },
                    "Id": "003As000010iaTvIAI",
                    "AccountId": "001As00000vgHEvIAM",
                    "Email": "john.wick.actif2prep@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "John",
                    "LastName": "Wick"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
            },
            "Id": "003As000010iaTvIAI",
            "AccountId": "001As00000vgHEvIAM",
            "Email": "john.wick.actif2prep@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "John",
            "LastName": "Wick"
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001As00000vgHEvIAM"
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
                    },
                    "Id": "003As000010iaTvIAI",
                    "AccountId": "001As00000vgHEvIAM",
                    "Email": "john.wick.actif2prep@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "John",
                    "LastName": "Wick"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "john.wick.actif2prep@trudel.ca",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010iaTvIAI"
            },
            "Id": "003As000010iaTvIAI",
            "AccountId": "001As00000vgHEvIAM",
            "Email": "john.wick.actif2prep@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "John",
            "LastName": "Wick"
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As000010iaTvIAI",
        "accountId": "001As00000vgHEvIAM"
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000vgHEvIAM",
        "contactIds": [
            "003As000010iaTvIAI"
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "John Wick",
            "StageName": "Qualification",
            "CloseDate": "2026-05-09",
            "AccountId": "001As00000vgHEvIAM",
            "Description": "",
            "Contact__c": "003As000010iaTvIAI",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As000010iaTvIAI"
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As000010iaTvIAI",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:17",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As000010iaTvIAI'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-04-09 13:34:18",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:18",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003As000010iaTvIAI"
    }
}
{
    "timestamp": "2026-04-09 13:34:18",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-04-09 13:34:18",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "John Wick",
            "StageName": "Qualification",
            "CloseDate": "2026-05-09",
            "AccountId": "001As00000vgHEvIAM",
            "Description": "",
            "Contact__c": "003As000010iaTvIAI",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:18",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006As00000OlhBlIAJ",
            "success": true,
            "errors": []
        },
        "oppId": "006As00000OlhBlIAJ"
    }
}
{
    "timestamp": "2026-04-09 13:34:19",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000OlhBlIAJ",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003As000010iaTvIAI",
            "Meeting_Date_Time__c": "2026-04-09T13:34:19Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 1
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:19",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As000010lti5IAA",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As000010lti5IAA",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-04-09 13:34:19",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1150_Le18Juillet-2",
            "1276_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-04-09 13:34:19",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-04-09 13:34:20",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-04-09 13:34:20",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-04-09 13:34:20",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1150_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-09 13:34:20",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1276_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-09 13:34:21",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000OlhBlIAJ",
        "VisitId": "a03As000010lti5IAA",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1150_Le18Juillet-2",
                "id": "a01As00000vjIOEIA2",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1276_Le18Juillet-2",
                "id": "a01As00000vjRA8IAM",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-04-14 13:53:50",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Nathan ",
                "LastName": "Drake",
                "Email": "thomas.raymond+nathandrake@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.04.14",
            "VisitTime": 77.766326904296875,
            "Pet": "",
            "UnitsSeeked": [
                "3.5",
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:50",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "thomas.raymond@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000001ng5aYAA"
                    },
                    "Id": "005OF000001ng5aYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('thomas.raymond+nathandrake@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "thomas.raymond+nathandrake@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Nathan ",
                "LastName": "Drake",
                "Email": "thomas.raymond+nathandrake@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-04-14 13:53:51",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-04-14 13:53:52",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001As00000vtDrvIAE",
        "payload": {
            "Name": "Nathan  Drake",
            "Phone": null,
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:52",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:52",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-04-14 13:53:52",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003As000010xNUkIAM",
        "accountId": "001As00000vtDrvIAE",
        "payload": {
            "FirstName": "Nathan ",
            "LastName": "Drake",
            "Email": "thomas.raymond+nathandrake@trudel.ca",
            "Phone": null,
            "AccountId": "001As00000vtDrvIAE",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000vtDrvIAE",
        "contactIds": [
            "003As000010xNUkIAM"
        ]
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Nathan  Drake",
            "StageName": "Qualification",
            "CloseDate": "2026-05-14",
            "AccountId": "001As00000vtDrvIAE",
            "Description": "",
            "Contact__c": "003As000010xNUkIAM",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As000010xNUkIAM"
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As000010xNUkIAM",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As000010xNUkIAM'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003As000010xNUkIAM"
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-04-14 13:53:55",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Nathan  Drake",
            "StageName": "Qualification",
            "CloseDate": "2026-05-14",
            "AccountId": "001As00000vtDrvIAE",
            "Description": "",
            "Contact__c": "003As000010xNUkIAM",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-04-14 13:53:58",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006As00000Oqm17IAB",
            "success": true,
            "errors": []
        },
        "oppId": "006As00000Oqm17IAB"
    }
}
{
    "timestamp": "2026-04-14 13:53:59",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000Oqm17IAB",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003As000010xNUkIAM",
            "Meeting_Date_Time__c": "2026-04-14T13:53:59Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 2
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:00",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As000010xJ9OIAU",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As000010xJ9OIAU",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:00",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1306_Le21Mars-1",
            "1023_Le21Mars-2"
        ]
    }
}
{
    "timestamp": "2026-04-14 13:54:01",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-04-14 13:54:01",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-04-14 13:54:01",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-04-14 13:54:01",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1306_Le21Mars-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-14 13:54:02",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1023_Le21Mars-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-14 13:54:02",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000Oqm17IAB",
        "VisitId": "a03As000010xJ9OIAU",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1306_Le21Mars-1",
                "id": "a01As00000vt7L3IAI",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1023_Le21Mars-2",
                "id": "a01As00000vt751IAA",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Nathan ",
                "LastName": "Drake",
                "Email": "thomas.raymond+nathandrake@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.04.14",
            "VisitTime": 77.766326904296875,
            "Pet": "",
            "UnitsSeeked": [
                "3.5",
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "thomas.raymond@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000001ng5aYAA"
                    },
                    "Id": "005OF000001ng5aYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG find_existing_lead_for_clients - requête Lead",
    "context": {
        "soql": "SELECT Id, FirstName, LastName, Company, Email, Phone, Status, IsConverted, ConvertedOpportunityId\r\n             FROM Lead\r\n             WHERE IsConverted = false\r\n             AND (Email IN ('thomas.raymond+nathandrake@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "thomas.raymond+nathandrake@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Nathan ",
                "LastName": "Drake",
                "Email": "thomas.raymond+nathandrake@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010xNUkIAM"
                    },
                    "Id": "003As000010xNUkIAM",
                    "AccountId": "001As00000vtDrvIAE",
                    "Email": "thomas.raymond+nathandrake@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Nathan",
                    "LastName": "Drake"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010xNUkIAM"
            },
            "Id": "003As000010xNUkIAM",
            "AccountId": "001As00000vtDrvIAE",
            "Email": "thomas.raymond+nathandrake@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Nathan",
            "LastName": "Drake"
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001As00000vtDrvIAE"
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010xNUkIAM"
                    },
                    "Id": "003As000010xNUkIAM",
                    "AccountId": "001As00000vtDrvIAE",
                    "Email": "thomas.raymond+nathandrake@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Nathan",
                    "LastName": "Drake"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "thomas.raymond+nathandrake@trudel.ca",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003As000010xNUkIAM"
            },
            "Id": "003As000010xNUkIAM",
            "AccountId": "001As00000vtDrvIAE",
            "Email": "thomas.raymond+nathandrake@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Nathan",
            "LastName": "Drake"
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003As000010xNUkIAM",
        "accountId": "001As00000vtDrvIAE"
    }
}
{
    "timestamp": "2026-04-14 13:54:08",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001As00000vtDrvIAE",
        "contactIds": [
            "003As000010xNUkIAM"
        ]
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Nathan  Drake",
            "StageName": "Qualification",
            "CloseDate": "2026-05-14",
            "AccountId": "001As00000vtDrvIAE",
            "Description": "",
            "Contact__c": "003As000010xNUkIAM",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003As000010xNUkIAM"
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003As000010xNUkIAM",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - requête",
    "context": {
        "soql": "SELECT OpportunityId, Opportunity.Id, Opportunity.Name, Opportunity.StageName, Opportunity.CreatedDate\r\n                 FROM OpportunityContactRole\r\n                 WHERE ContactId = '003As000010xNUkIAM'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Id != null\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003As000010xNUkIAM"
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Nathan  Drake",
            "StageName": "Qualification",
            "CloseDate": "2026-05-14",
            "AccountId": "001As00000vtDrvIAE",
            "Description": "",
            "Contact__c": "003As000010xNUkIAM",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006As00000OqgetIAB",
            "success": true,
            "errors": []
        },
        "oppId": "006As00000OqgetIAB"
    }
}
{
    "timestamp": "2026-04-14 13:54:09",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006As00000OqgetIAB",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003As000010xNUkIAM",
            "Meeting_Date_Time__c": "2026-04-14T13:54:09Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 2
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:10",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03As000010xEg2IAE",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03As000010xEg2IAE",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-04-14 13:54:10",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1306_Le21Mars-1",
            "1023_Le21Mars-2"
        ]
    }
}
{
    "timestamp": "2026-04-14 13:54:10",
    "message": "⚠️ SF query RecordType failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "\n             ORDER BY IsDefault DESC, CreatedDate ASC\n                      ^\nERROR at Row:5:Column:23\nNo such column 'IsDefault' on entity 'RecordType'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.",
                "errorCode": "INVALID_FIELD"
            }
        ],
        "sobjectType": "Visited_Unit__c"
    }
}
{
    "timestamp": "2026-04-14 13:54:10",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjSAAQ"
    }
}
{
    "timestamp": "2026-04-14 13:54:10",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-04-14 13:54:10",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1306_Le21Mars-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-14 13:54:11",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1023_Le21Mars-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-04-14 13:54:11",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006As00000OqgetIAB",
        "VisitId": "a03As000010xEg2IAE",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1306_Le21Mars-1",
                "id": "a01As00000vt9eiIAA",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1023_Le21Mars-2",
                "id": "a01As00000vt6nAIAQ",
                "http": 201
            }
        ]
    }
}
