{
    "timestamp": "2026-05-05 18:42:24",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-05-05 18:42:24",
    "message": "✅ Nouveau token obtenu et sauvegardé."
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Yannick",
            "LastName": "Gilbert",
            "Email": "yannick@minuitmoinsune.com",
            "Job": "Développeur"
        },
        "Clients": [
            {
                "FirstName": "Chocolat",
                "LastName": "Cafe",
                "Email": "chocolat.cafe@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026-05-05",
            "MeetingDateTime": "2026-05-05T18:40:37Z",
            "VisitTime": 52,
            "WalkIn": false,
            "VisitedUnitRecordTypeDeveloperName": "Default",
            "Building": "Bâtiment A",
            "UnitsSeeked": [
                "3.5",
                "4.5",
                "Studio"
            ],
            "Comment": "Visite test (UI) - création Visit__c + Visited_Unit__c",
            "VisitedUnits": [
                {
                    "Unit": "203",
                    "ClientInterest": "High",
                    "TypeDeVisite": "Visite",
                    "Notes": "Beau plan, bon prix.",
                    "Comments": "<p>Client très intéressé.<\/p>",
                    "PositiveAspects": [
                        "Luminosité",
                        "Vue"
                    ],
                    "NegativeAspects": [
                        "Bruit"
                    ]
                },
                {
                    "Unit": "305",
                    "ClientInterest": "Medium",
                    "TypeDeVisite": "Visite",
                    "Notes": "À revoir avec conjoint."
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": "2026-05-05T18:40:37Z",
        "meetingDateTimeIso": "2026-05-05T18:40:37Z"
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "✅ lookup_asset_by_building_name - trouvé (LIKE)",
    "context": {
        "assetId": "02iOF0000041cGjYAI",
        "buildingGroupId": null,
        "building": "203"
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "203",
        "residentialBuildingAssetId": "02iOF0000041cGjYAI",
        "buildingGroupId": null
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "yannick@minuitmoinsune.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": null
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "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 ('chocolat.cafe@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "chocolat.cafe@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "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\/00QbZ00000GDhPJUA1"
                    },
                    "Id": "00QbZ00000GDhPJUA1",
                    "FirstName": "Chocolat",
                    "LastName": "Cafe",
                    "Company": "Chocolat Cafe",
                    "Email": "chocolat.cafe@trudel.ca",
                    "Phone": null,
                    "Status": "New",
                    "IsConverted": false,
                    "ConvertedOpportunityId": null
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QbZ00000GDhPJUA1"
            },
            "Id": "00QbZ00000GDhPJUA1",
            "FirstName": "Chocolat",
            "LastName": "Cafe",
            "Company": "Chocolat Cafe",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QbZ00000GDhPJUA1"
            },
            "Id": "00QbZ00000GDhPJUA1",
            "FirstName": "Chocolat",
            "LastName": "Cafe",
            "Company": "Chocolat Cafe",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('chocolat.cafe@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucun Contact trouvé",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - lead trouvé, entrée dans le flow de conversion",
    "context": {
        "leadId": "00QbZ00000GDhPJUA1",
        "leadEmail": "chocolat.cafe@trudel.ca",
        "leadStatus": "New"
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - convertedStatus",
    "context": {
        "convertedStatus": "Qualified"
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - contact existant avant conversion Lead",
    "context": {
        "primaryEmail": "chocolat.cafe@trudel.ca",
        "existingContact": null
    }
}
{
    "timestamp": "2026-05-05 18:42:27",
    "message": "DEBUG create_all - payload conversion Lead final",
    "context": {
        "leadId": "00QbZ00000GDhPJUA1",
        "convertPayload": {
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Chocolat Cafe"
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:28",
    "message": "DEBUG create_all - nullification picklists Lead avant conversion",
    "context": {
        "count": 28,
        "fields": [
            "Language__c",
            "Business_Type__c",
            "Disqualification_Reason__c",
            "Current_situation__c",
            "Type_of_current_property__c",
            "Sector_of_interest__c",
            "et4ae5__Mobile_Country_Code__c",
            "Current_Residence__c",
            "No_specific_date__c",
            "Current_Sector__c",
            "Type_of_unit__c",
            "Bathroom_equipment__c",
            "Type_of_laundry_room__c",
            "Orientation_of_the_sun__c",
            "Floor_of_the_unit__c",
            "Number_of_bathroom_washroom__c",
            "State_of_the_unit__c",
            "View_of_the_unit__c",
            "Office__c",
            "Pet_type_2__c",
            "Pet_type__c",
            "Contact_Preference__c",
            "Deceased_Relative__c",
            "Priority_Needs_Prospect__c",
            "Age_Group_2__c",
            "Age_Group_3__c",
            "Age_Group__c",
            "ic_Newsletter_Requested_if_Disqualified__c"
        ],
        "http": 400
    }
}
{
    "timestamp": "2026-05-05 18:42:28",
    "message": "DEBUG sf_convert_lead - URL Apex REST appelée",
    "context": {
        "instanceUrl": "https:\/\/gestiontrudelalliance123--cl.sandbox.my.salesforce.com",
        "url": "https:\/\/gestiontrudelalliance123--cl.sandbox.my.salesforce.com\/services\/apexrest\/convertLead",
        "payload": {
            "leadId": "00QbZ00000GDhPJUA1",
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Chocolat Cafe"
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:28",
    "message": "DEBUG sf_convert_lead - réponse conversion via Apex REST",
    "context": {
        "leadId": "00QbZ00000GDhPJUA1",
        "http": 200,
        "res": {
            "errors": [
                "ConvertLead failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, Don't have sufficient access to Lead.: [Id]"
            ],
            "success": false
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:28",
    "message": "DEBUG create_all - résultat conversion Lead",
    "context": {
        "leadConversion": {
            "leadId": "00QbZ00000GDhPJUA1",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Chocolat Cafe"
            },
            "res": {
                "errors": [
                    "ConvertLead failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, Don't have sufficient access to Lead.: [Id]"
                ],
                "success": false
            }
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:28",
    "message": "❌ Lead conversion failed; fallback to classic create",
    "context": {
        "leadConversion": {
            "leadId": "00QbZ00000GDhPJUA1",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Chocolat Cafe"
            },
            "res": {
                "errors": [
                    "ConvertLead failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, Don't have sufficient access to Lead.: [Id]"
                ],
                "success": false
            }
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:28",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001bZ00000NsWQiQAN",
        "payload": {
            "Name": "Chocolat Cafe",
            "Phone": null,
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-05 18:42:29",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-05-05 18:42:30",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003bZ00000XhRQBQA3",
        "accountId": "001bZ00000NsWQiQAN",
        "payload": {
            "FirstName": "Chocolat",
            "LastName": "Cafe",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "AccountId": "001bZ00000NsWQiQAN",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:30",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001bZ00000NsWQiQAN",
        "contactIds": [
            "003bZ00000XhRQBQA3"
        ]
    }
}
{
    "timestamp": "2026-05-05 18:42:30",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Chocolat Cafe",
            "StageName": "Qualification",
            "CloseDate": "2026-06-04",
            "AccountId": "001bZ00000NsWQiQAN",
            "Description": "Visite test (UI) - création Visit__c + Visited_Unit__c",
            "Contact__c": "003bZ00000XhRQBQA3",
            "Residential_Building__c": "02iOF0000041cGjYAI",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003bZ00000XhRQBQA3"
    }
}
{
    "timestamp": "2026-05-05 18:42:30",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003bZ00000XhRQBQA3",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-05 18:42:30",
    "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 = '003bZ00000XhRQBQA3'\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-05-05 18:42:31",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:31",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003bZ00000XhRQBQA3"
    }
}
{
    "timestamp": "2026-05-05 18:42:31",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-05 18:42:31",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Chocolat Cafe",
            "StageName": "Qualification",
            "CloseDate": "2026-06-04",
            "AccountId": "001bZ00000NsWQiQAN",
            "Description": "Visite test (UI) - création Visit__c + Visited_Unit__c",
            "Contact__c": "003bZ00000XhRQBQA3",
            "Residential_Building__c": "02iOF0000041cGjYAI",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-05 18:42:31",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 400,
        "resp": [
            {
                "message": "Value does not exist or does not match filter criteria.",
                "errorCode": "FIELD_FILTER_VALIDATION_EXCEPTION",
                "fields": [
                    "Residential_Building__c"
                ]
            }
        ],
        "oppId": null
    }
}
{
    "timestamp": "2026-05-05 18:42:31",
    "message": "❌ Create Opportunity failed",
    "context": {
        "http": 400,
        "res": [
            {
                "message": "Value does not exist or does not match filter criteria.",
                "errorCode": "FIELD_FILTER_VALIDATION_EXCEPTION",
                "fields": [
                    "Residential_Building__c"
                ]
            }
        ],
        "payload": {
            "Name": "Chocolat Cafe",
            "StageName": "Qualification",
            "CloseDate": "2026-06-04",
            "AccountId": "001bZ00000NsWQiQAN",
            "Description": "Visite test (UI) - création Visit__c + Visited_Unit__c",
            "Contact__c": "003bZ00000XhRQBQA3",
            "Residential_Building__c": "02iOF0000041cGjYAI",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:24",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-05 18:44:26",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Chocolat",
                "LastName": "Cafe",
                "Email": "chocolat.cafe@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.04",
            "VisitTime": 65.64731597900390625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:26",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-05 18:44:26",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-05 18:44:26",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-05 18:44:26",
    "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-05-05 18:44:26",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-05 18:44:26",
    "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 ('chocolat.cafe@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "chocolat.cafe@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "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\/00QbZ00000GDhPJUA1"
                    },
                    "Id": "00QbZ00000GDhPJUA1",
                    "FirstName": "Chocolat",
                    "LastName": "Cafe",
                    "Company": "Chocolat Cafe",
                    "Email": "chocolat.cafe@trudel.ca",
                    "Phone": null,
                    "Status": "New",
                    "IsConverted": false,
                    "ConvertedOpportunityId": null
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QbZ00000GDhPJUA1"
            },
            "Id": "00QbZ00000GDhPJUA1",
            "FirstName": "Chocolat",
            "LastName": "Cafe",
            "Company": "Chocolat Cafe",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": {
            "attributes": {
                "type": "Lead",
                "url": "\/services\/data\/v62.0\/sobjects\/Lead\/00QbZ00000GDhPJUA1"
            },
            "Id": "00QbZ00000GDhPJUA1",
            "FirstName": "Chocolat",
            "LastName": "Cafe",
            "Company": "Chocolat Cafe",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "Status": "New",
            "IsConverted": false,
            "ConvertedOpportunityId": null
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('chocolat.cafe@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003bZ00000XhRQBQA3",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003bZ00000XhRQBQA3'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR vide, fallback Contact__c",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via Contact__c",
    "context": {
        "contactId": "003bZ00000XhRQBQA3",
        "soql": "SELECT Id, Building_Group__c\r\n                 FROM Opportunity\r\n                 WHERE Contact__c = '003bZ00000XhRQBQA3'\r\n                 AND IsClosed = false\r\n                 AND CreatedDate = LAST_N_DAYS:365\r\n                 ORDER BY CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucune Opportunity trouvée",
    "context": {
        "contactId": "003bZ00000XhRQBQA3"
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - lead trouvé, entrée dans le flow de conversion",
    "context": {
        "leadId": "00QbZ00000GDhPJUA1",
        "leadEmail": "chocolat.cafe@trudel.ca",
        "leadStatus": "New"
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - convertedStatus",
    "context": {
        "convertedStatus": "Qualified"
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XhRQBQA3"
                    },
                    "Id": "003bZ00000XhRQBQA3",
                    "AccountId": "001bZ00000NsWQiQAN",
                    "Email": "chocolat.cafe@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Chocolat",
                    "LastName": "Cafe"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - contact existant avant conversion Lead",
    "context": {
        "primaryEmail": "chocolat.cafe@trudel.ca",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XhRQBQA3"
            },
            "Id": "003bZ00000XhRQBQA3",
            "AccountId": "001bZ00000NsWQiQAN",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Chocolat",
            "LastName": "Cafe"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - payload conversion Lead final",
    "context": {
        "leadId": "00QbZ00000GDhPJUA1",
        "convertPayload": {
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Chocolat Cafe",
            "ownerId": "005OF000001ng5aYAA",
            "contactId": "003bZ00000XhRQBQA3",
            "accountId": "001bZ00000NsWQiQAN"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - nullification picklists Lead avant conversion",
    "context": {
        "count": 28,
        "fields": [
            "Language__c",
            "Business_Type__c",
            "Disqualification_Reason__c",
            "Current_situation__c",
            "Type_of_current_property__c",
            "Sector_of_interest__c",
            "et4ae5__Mobile_Country_Code__c",
            "Current_Residence__c",
            "No_specific_date__c",
            "Current_Sector__c",
            "Type_of_unit__c",
            "Bathroom_equipment__c",
            "Type_of_laundry_room__c",
            "Orientation_of_the_sun__c",
            "Floor_of_the_unit__c",
            "Number_of_bathroom_washroom__c",
            "State_of_the_unit__c",
            "View_of_the_unit__c",
            "Office__c",
            "Pet_type_2__c",
            "Pet_type__c",
            "Contact_Preference__c",
            "Deceased_Relative__c",
            "Priority_Needs_Prospect__c",
            "Age_Group_2__c",
            "Age_Group_3__c",
            "Age_Group__c",
            "ic_Newsletter_Requested_if_Disqualified__c"
        ],
        "http": 400
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG sf_convert_lead - URL Apex REST appelée",
    "context": {
        "instanceUrl": "https:\/\/gestiontrudelalliance123--cl.sandbox.my.salesforce.com",
        "url": "https:\/\/gestiontrudelalliance123--cl.sandbox.my.salesforce.com\/services\/apexrest\/convertLead",
        "payload": {
            "leadId": "00QbZ00000GDhPJUA1",
            "convertedStatus": "Qualified",
            "doNotCreateOpportunity": false,
            "opportunityName": "Chocolat Cafe",
            "accountId": "001bZ00000NsWQiQAN",
            "contactId": "003bZ00000XhRQBQA3",
            "ownerId": "005OF000001ng5aYAA"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG sf_convert_lead - réponse conversion via Apex REST",
    "context": {
        "leadId": "00QbZ00000GDhPJUA1",
        "http": 200,
        "res": {
            "errors": [
                "ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []"
            ],
            "success": false
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - résultat conversion Lead",
    "context": {
        "leadConversion": {
            "leadId": "00QbZ00000GDhPJUA1",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Chocolat Cafe",
                "ownerId": "005OF000001ng5aYAA",
                "contactId": "003bZ00000XhRQBQA3",
                "accountId": "001bZ00000NsWQiQAN"
            },
            "res": {
                "errors": [
                    "ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []"
                ],
                "success": false
            }
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "❌ Lead conversion failed; fallback to classic create",
    "context": {
        "leadConversion": {
            "leadId": "00QbZ00000GDhPJUA1",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Chocolat Cafe",
                "ownerId": "005OF000001ng5aYAA",
                "contactId": "003bZ00000XhRQBQA3",
                "accountId": "001bZ00000NsWQiQAN"
            },
            "res": {
                "errors": [
                    "ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []"
                ],
                "success": false
            }
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:27",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XhRQBQA3"
                    },
                    "Id": "003bZ00000XhRQBQA3",
                    "AccountId": "001bZ00000NsWQiQAN",
                    "Email": "chocolat.cafe@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Chocolat",
                    "LastName": "Cafe"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XhRQBQA3"
            },
            "Id": "003bZ00000XhRQBQA3",
            "AccountId": "001bZ00000NsWQiQAN",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Chocolat",
            "LastName": "Cafe"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001bZ00000NsWQiQAN"
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XhRQBQA3"
                    },
                    "Id": "003bZ00000XhRQBQA3",
                    "AccountId": "001bZ00000NsWQiQAN",
                    "Email": "chocolat.cafe@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Chocolat",
                    "LastName": "Cafe"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "chocolat.cafe@trudel.ca",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XhRQBQA3"
            },
            "Id": "003bZ00000XhRQBQA3",
            "AccountId": "001bZ00000NsWQiQAN",
            "Email": "chocolat.cafe@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Chocolat",
            "LastName": "Cafe"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003bZ00000XhRQBQA3",
        "accountId": "001bZ00000NsWQiQAN"
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001bZ00000NsWQiQAN",
        "contactIds": [
            "003bZ00000XhRQBQA3"
        ]
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Chocolat Cafe",
            "StageName": "Qualification",
            "CloseDate": "2026-06-04",
            "AccountId": "001bZ00000NsWQiQAN",
            "Description": "",
            "Contact__c": "003bZ00000XhRQBQA3",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003bZ00000XhRQBQA3"
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003bZ00000XhRQBQA3",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02ibZ000003J10IQAS",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02ibZ000003J10IQAS'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-05 18:44:28",
    "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 = '003bZ00000XhRQBQA3'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02ibZ000003J10IQAS'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-05 18:44:29",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:29",
    "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 = '003bZ00000XhRQBQA3'\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-05-05 18:44:29",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:29",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003bZ00000XhRQBQA3"
    }
}
{
    "timestamp": "2026-05-05 18:44:29",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-05 18:44:29",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Chocolat Cafe",
            "StageName": "Qualification",
            "CloseDate": "2026-06-04",
            "AccountId": "001bZ00000NsWQiQAN",
            "Description": "",
            "Contact__c": "003bZ00000XhRQBQA3",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:29",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006bZ00000VzzxaQAB",
            "success": true,
            "errors": []
        },
        "oppId": "006bZ00000VzzxaQAB"
    }
}
{
    "timestamp": "2026-05-05 18:44:30",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000VzzxaQAB",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003bZ00000XhRQBQA3",
            "Meeting_Date_Time__c": "2026-05-04T18:44:30Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 66
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:32",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03bZ00000XhdfpQAB",
        "savedOppId": "006bZ00000VzzxaQAB",
        "expectedOppId": "006bZ00000VzzxaQAB"
    }
}
{
    "timestamp": "2026-05-05 18:44:32",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03bZ00000XhdfpQAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03bZ00000XhdfpQAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:32",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1050_Le18Juillet-2",
            "826_Le18Juillet-1",
            "1177_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-05 18:44:32",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-05 18:44:32",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": {
            "1177": {
                "Unit": "1177",
                "ServicesAndOptionsIncluded": [
                    "Piscine extérieure au toit",
                    "Salle de mise en forme",
                    "Cuisine d’été",
                    "Salle de réception ($)",
                    "Suite d’invité locative ($)",
                    "Stations lave-auto",
                    "Salle de rangement à vélos sécurisée",
                    "Eau chaude",
                    "Air climatisé"
                ],
                "ServicesAndOptions": [],
                "ServicesAndOptionsMultiple": [
                    {
                        "Name": "Rangement grillagé sur étage (à partir de)",
                        "Number": 1,
                        "Price": 75
                    },
                    {
                        "Name": "Rangement grillagé souterrain (à partir de)",
                        "Number": 1,
                        "Price": 55
                    },
                    {
                        "Name": "Stationnement moto (à partir de)",
                        "Number": 1,
                        "Price": 35
                    }
                ],
                "ServicesAndOptionsPrice": 165,
                "UnitPrice": 2795,
                "Deduction": 0,
                "OtherFees": 0,
                "FinalPrice": 2960
            }
        }
    }
}
{
    "timestamp": "2026-05-05 18:44:33",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1050_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-05 18:44:33",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "826_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-05 18:44:34",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1177_Le18Juillet-2",
        "requested": [
            "Prix"
        ],
        "allowed": [],
        "valid": [
            "Prix"
        ],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-05 18:44:34",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000VzzxaQAB",
        "VisitId": "a03bZ00000XhdfpQAB",
        "VisitMode": "create",
        "LeadConversion": {
            "leadId": "00QbZ00000GDhPJUA1",
            "http": 200,
            "payload": {
                "convertedStatus": "Qualified",
                "doNotCreateOpportunity": false,
                "opportunityName": "Chocolat Cafe",
                "ownerId": "005OF000001ng5aYAA",
                "contactId": "003bZ00000XhRQBQA3",
                "accountId": "001bZ00000NsWQiQAN"
            },
            "res": {
                "errors": [
                    "ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []"
                ],
                "success": false
            }
        },
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1050_Le18Juillet-2",
                "id": "a01bZ00000NsB30QAF",
                "http": 201
            },
            {
                "ok": true,
                "unit": "826_Le18Juillet-1",
                "id": "a01bZ00000NsZDIQA3",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1177_Le18Juillet-2",
                "id": "a01bZ00000NsSX6QAN",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 13:55:44",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-05-06 13:55:44",
    "message": "✅ Nouveau token obtenu et sauvegardé."
}
{
    "timestamp": "2026-05-06 13:55:47",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 465.463134765625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:47",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 13:55:47",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 13:55:47",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 13:55:47",
    "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-05-06 13:55:47",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 13:55:47",
    "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 ('Cloud.strife@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Cloud.strife@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Cloud.strife@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucun Contact trouvé",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Cloud.strife@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "Cloud.strife@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-06 13:55:48",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "Cloud.strife@trudel.ca",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-05-06 13:55:49",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001bZ00000NvSokQAF",
        "payload": {
            "Name": "Cloud Strife",
            "Phone": null,
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:49",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Cloud.strife@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:49",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "Cloud.strife@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-06 13:55:49",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "Cloud.strife@trudel.ca",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-05-06 13:55:52",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003bZ00000XkpDZQAZ",
        "accountId": "001bZ00000NvSokQAF",
        "payload": {
            "FirstName": "Cloud",
            "LastName": "Strife",
            "Email": "Cloud.strife@trudel.ca",
            "Phone": null,
            "AccountId": "001bZ00000NvSokQAF",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:52",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001bZ00000NvSokQAF",
        "contactIds": [
            "003bZ00000XkpDZQAZ"
        ]
    }
}
{
    "timestamp": "2026-05-06 13:55:52",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Cloud Strife",
            "StageName": "Qualification",
            "CloseDate": "2026-06-05",
            "AccountId": "001bZ00000NvSokQAF",
            "Description": "",
            "Contact__c": "003bZ00000XkpDZQAZ",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003bZ00000XkpDZQAZ"
    }
}
{
    "timestamp": "2026-05-06 13:55:52",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003bZ00000XkpDZQAZ",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02ibZ000003J10IQAS",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02ibZ000003J10IQAS'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-06 13:55:52",
    "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 = '003bZ00000XkpDZQAZ'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02ibZ000003J10IQAS'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 13:55:53",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:53",
    "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 = '003bZ00000XkpDZQAZ'\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-05-06 13:55:53",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:53",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003bZ00000XkpDZQAZ"
    }
}
{
    "timestamp": "2026-05-06 13:55:53",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-06 13:55:53",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Cloud Strife",
            "StageName": "Qualification",
            "CloseDate": "2026-06-05",
            "AccountId": "001bZ00000NvSokQAF",
            "Description": "",
            "Contact__c": "003bZ00000XkpDZQAZ",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:55",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006bZ00000W481QQAR",
            "success": true,
            "errors": []
        },
        "oppId": "006bZ00000W481QQAR"
    }
}
{
    "timestamp": "2026-05-06 13:55:55",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W481QQAR",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003bZ00000XkpDZQAZ",
            "Meeting_Date_Time__c": "2026-05-06T13:55:55Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 466
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:57",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03bZ00000XlFDVQA3",
        "savedOppId": "006bZ00000W481QQAR",
        "expectedOppId": "006bZ00000W481QQAR"
    }
}
{
    "timestamp": "2026-05-06 13:55:57",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03bZ00000XlFDVQA3",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03bZ00000XlFDVQA3",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:55:57",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1253_Le18Juillet-2",
            "351_Le18Juillet-2",
            "1130_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-06 13:55:58",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 13:55:58",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 13:55:58",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1253_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 13:55:59",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "351_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 13:56:00",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1130_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 13:56:00",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W481QQAR",
        "VisitId": "a03bZ00000XlFDVQA3",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1253_Le18Juillet-2",
                "id": "a01bZ00000NvS5aQAF",
                "http": 201
            },
            {
                "ok": true,
                "unit": "351_Le18Juillet-2",
                "id": "a01bZ00000NvTKzQAN",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1130_Le18Juillet-1",
                "id": "a01bZ00000NvTMbQAN",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 13:56:04",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 465.463134765625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "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-05-06 13:56:06",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "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 ('Cloud.strife@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Cloud.strife@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Cloud.strife@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003bZ00000XkpDZQAZ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003bZ00000XkpDZQAZ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "foundGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 13:56:06",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006bZ00000W481QQAR"
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "payload": {
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS"
        }
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W481QQAR",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Meeting_Date_Time__c": "2026-05-06T13:56:07Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 466
        }
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "ℹ️ upsert_visit - Visit__c existante aujourd'hui — réutilisation",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "visitId": "a03bZ00000XlFDVQA3"
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "update",
        "visitId": "a03bZ00000XlFDVQA3",
        "visitHttp": 200,
        "visitRes": {
            "id": "a03bZ00000XlFDVQA3",
            "updated": true
        }
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1253_Le18Juillet-2",
            "351_Le18Juillet-2",
            "1130_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 13:56:07",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1253_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 13:56:08",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "351_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 13:56:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1130_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 13:56:09",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W481QQAR",
        "VisitId": "a03bZ00000XlFDVQA3",
        "VisitMode": "update",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1253_Le18Juillet-2",
                "id": "a01bZ00000NvNnVQAV",
                "http": 201
            },
            {
                "ok": true,
                "unit": "351_Le18Juillet-2",
                "id": "a01bZ00000NvTODQA3",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1130_Le18Juillet-1",
                "id": "a01bZ00000NvK6iQAF",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 14:14:15",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-06 14:14:20",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 465.463134765625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 14:14:20",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "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-05-06 14:14:21",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "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 ('Cloud.strife@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Cloud.strife@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Cloud.strife@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003bZ00000XkpDZQAZ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003bZ00000XkpDZQAZ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "foundGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:14:21",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006bZ00000W481QQAR"
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "payload": {
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS"
        }
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W481QQAR",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Meeting_Date_Time__c": "2026-05-06T14:14:22Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 8
        }
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "ℹ️ upsert_visit - Visit__c existante aujourd'hui — réutilisation",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "visitId": "a03bZ00000XlFDVQA3"
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "update",
        "visitId": "a03bZ00000XlFDVQA3",
        "visitHttp": 200,
        "visitRes": {
            "id": "a03bZ00000XlFDVQA3",
            "updated": true
        }
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1253_Le18Juillet-2",
            "351_Le18Juillet-2",
            "1130_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 14:14:22",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 14:14:23",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1253_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:14:23",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "351_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:14:24",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1130_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:14:24",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W481QQAR",
        "VisitId": "a03bZ00000XlFDVQA3",
        "VisitMode": "update",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1253_Le18Juillet-2",
                "id": "a01bZ00000NvOehQAF",
                "http": 201
            },
            {
                "ok": true,
                "unit": "351_Le18Juillet-2",
                "id": "a01bZ00000NvL91QAF",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1130_Le18Juillet-1",
                "id": "a01bZ00000NvVppQAF",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 14:15:04",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 465.463134765625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "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-05-06 14:15:07",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "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 ('Cloud.strife@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Cloud.strife@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Cloud.strife@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 14:15:07",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003bZ00000XkpDZQAZ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003bZ00000XkpDZQAZ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 14:15:08",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "foundGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:15:08",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:15:08",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006bZ00000W481QQAR"
    }
}
{
    "timestamp": "2026-05-06 14:15:08",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006bZ00000W481QQAR",
        "payload": {
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS"
        }
    }
}
{
    "timestamp": "2026-05-06 14:15:08",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Cloud",
                "LastName": "Strife",
                "Email": "Cloud.strife@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 14:15:08",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W481QQAR",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Meeting_Date_Time__c": "2026-05-06T14:15:08Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 8
        }
    }
}
{
    "timestamp": "2026-05-06 14:15:09",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03bZ00000Xl9ckQAB",
        "savedOppId": "006bZ00000W481QQAR",
        "expectedOppId": "006bZ00000W481QQAR"
    }
}
{
    "timestamp": "2026-05-06 14:15:09",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03bZ00000Xl9ckQAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03bZ00000Xl9ckQAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:15:09",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1253_Le18Juillet-2",
            "351_Le18Juillet-2",
            "1130_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-06 14:15:09",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 14:15:09",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 14:15:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1253_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:15:10",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "351_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:15:11",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1130_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:15:11",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W481QQAR",
        "VisitId": "a03bZ00000Xl9ckQAB",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1253_Le18Juillet-2",
                "id": "a01bZ00000NvPStQAN",
                "http": 201
            },
            {
                "ok": true,
                "unit": "351_Le18Juillet-2",
                "id": "a01bZ00000NvPG3QAN",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1130_Le18Juillet-1",
                "id": "a01bZ00000NvVcwQAF",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 14:35:33",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-06 14:35:35",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Lara",
                "LastName": "Croft",
                "Email": "Lara.croft@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 24.82140350341796875,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:35",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "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-05-06 14:35:36",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "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 ('Lara.croft@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Lara.croft@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Lara.croft@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucun Contact trouvé",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Lara",
                "LastName": "Croft",
                "Email": "Lara.croft@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Lara.croft@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "Lara.croft@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-06 14:35:36",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "Lara.croft@trudel.ca",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-05-06 14:35:37",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001bZ00000NvQiUQAV",
        "payload": {
            "Name": "Lara Croft",
            "Phone": null,
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:37",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Lara.croft@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:37",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "Lara.croft@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-06 14:35:37",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "Lara.croft@trudel.ca",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-05-06 14:35:38",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003bZ00000XkzlTQAR",
        "accountId": "001bZ00000NvQiUQAV",
        "payload": {
            "FirstName": "Lara",
            "LastName": "Croft",
            "Email": "Lara.croft@trudel.ca",
            "Phone": null,
            "AccountId": "001bZ00000NvQiUQAV",
            "OwnerId": "005OF000001ng5aYAA",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:38",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001bZ00000NvQiUQAV",
        "contactIds": [
            "003bZ00000XkzlTQAR"
        ]
    }
}
{
    "timestamp": "2026-05-06 14:35:38",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Lara Croft",
            "StageName": "Qualification",
            "CloseDate": "2026-06-05",
            "AccountId": "001bZ00000NvQiUQAV",
            "Description": "",
            "Contact__c": "003bZ00000XkzlTQAR",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003bZ00000XkzlTQAR"
    }
}
{
    "timestamp": "2026-05-06 14:35:38",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003bZ00000XkzlTQAR",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02ibZ000003J10IQAS",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02ibZ000003J10IQAS'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-06 14:35:38",
    "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 = '003bZ00000XkzlTQAR'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02ibZ000003J10IQAS'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 14:35:39",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:39",
    "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 = '003bZ00000XkzlTQAR'\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-05-06 14:35:39",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:39",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003bZ00000XkzlTQAR"
    }
}
{
    "timestamp": "2026-05-06 14:35:39",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-06 14:35:39",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Lara Croft",
            "StageName": "Qualification",
            "CloseDate": "2026-06-05",
            "AccountId": "001bZ00000NvQiUQAV",
            "Description": "",
            "Contact__c": "003bZ00000XkzlTQAR",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:40",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006bZ00000W4GtNQAV",
            "success": true,
            "errors": []
        },
        "oppId": "006bZ00000W4GtNQAV"
    }
}
{
    "timestamp": "2026-05-06 14:35:40",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W4GtNQAV",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003bZ00000XkzlTQAR",
            "Meeting_Date_Time__c": "2026-05-06T14:35:40Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 1
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03bZ00000XlRY1QAN",
        "savedOppId": "006bZ00000W4GtNQAV",
        "expectedOppId": "006bZ00000W4GtNQAV"
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03bZ00000XlRY1QAN",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03bZ00000XlRY1QAN",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1050_Le18Juillet-2",
            "1430_Le18Juillet-1",
            "824_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1050_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:35:41",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1430_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:35:42",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "824_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 14:35:42",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W4GtNQAV",
        "VisitId": "a03bZ00000XlRY1QAN",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1050_Le18Juillet-2",
                "id": "a01bZ00000Nv1vDQAR",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1430_Le18Juillet-1",
                "id": "a01bZ00000NvEHOQA3",
                "http": 201
            },
            {
                "ok": true,
                "unit": "824_Le18Juillet-1",
                "id": "a01bZ00000NvH5VQAV",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 15:04:01",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-06 15:04:03",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Ezio",
                "LastName": "Auditore",
                "Email": "ezio.auditore@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 24.280704498291015625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:03",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "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-05-06 15:04:04",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "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 ('ezio.auditore@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "ezio.auditore@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('ezio.auditore@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003bZ00000XlIrKQAV",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003bZ00000XlIrKQAV'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "existingGroupId": null,
        "incomingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Ezio",
                "LastName": "Auditore",
                "Email": "ezio.auditore@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 15:04:04",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "ezio.auditore@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XlIrKQAV"
                    },
                    "Id": "003bZ00000XlIrKQAV",
                    "AccountId": "001bZ00000NvXTSQA3",
                    "Email": "ezio.auditore@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Ezio",
                    "LastName": "Auditore"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "ezio.auditore@trudel.ca",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XlIrKQAV"
            },
            "Id": "003bZ00000XlIrKQAV",
            "AccountId": "001bZ00000NvXTSQA3",
            "Email": "ezio.auditore@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Ezio",
            "LastName": "Auditore"
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001bZ00000NvXTSQA3"
    }
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "ezio.auditore@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XlIrKQAV"
                    },
                    "Id": "003bZ00000XlIrKQAV",
                    "AccountId": "001bZ00000NvXTSQA3",
                    "Email": "ezio.auditore@trudel.ca",
                    "Phone": null,
                    "MobilePhone": null,
                    "FirstName": "Ezio",
                    "LastName": "Auditore"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "ezio.auditore@trudel.ca",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003bZ00000XlIrKQAV"
            },
            "Id": "003bZ00000XlIrKQAV",
            "AccountId": "001bZ00000NvXTSQA3",
            "Email": "ezio.auditore@trudel.ca",
            "Phone": null,
            "MobilePhone": null,
            "FirstName": "Ezio",
            "LastName": "Auditore"
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003bZ00000XlIrKQAV",
        "accountId": "001bZ00000NvXTSQA3"
    }
}
{
    "timestamp": "2026-05-06 15:04:05",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001bZ00000NvXTSQA3",
        "contactIds": [
            "003bZ00000XlIrKQAV"
        ]
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Ezio Auditore",
            "StageName": "Qualification",
            "CloseDate": "2026-06-05",
            "AccountId": "001bZ00000NvXTSQA3",
            "Description": "",
            "Contact__c": "003bZ00000XlIrKQAV",
            "OwnerId": "005OF000001ng5aYAA",
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003bZ00000XlIrKQAV"
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003bZ00000XlIrKQAV",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02ibZ000003J10IQAS",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02ibZ000003J10IQAS'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "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 = '003bZ00000XlIrKQAV'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02ibZ000003J10IQAS'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "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 = '003bZ00000XlIrKQAV'\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-05-06 15:04:06",
    "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\/00KbZ00000ArCJpUAN"
                    },
                    "OpportunityId": "006bZ00000W4HpRQAV",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006bZ00000W4HpRQAV"
                        },
                        "Id": "006bZ00000W4HpRQAV",
                        "Name": "Auditore-",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-05-06T14:57:43.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KbZ00000ArCJpUAN"
            },
            "OpportunityId": "006bZ00000W4HpRQAV",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006bZ00000W4HpRQAV"
                },
                "Id": "006bZ00000W4HpRQAV",
                "Name": "Auditore-",
                "StageName": "Qualification",
                "CreatedDate": "2026-05-06T14:57:43.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006bZ00000W4HpRQAV"
    }
}
{
    "timestamp": "2026-05-06 15:04:06",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "contactId": "003bZ00000XlIrKQAV",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-06 15:04:07",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "payload": {
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS"
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:07",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W4HpRQAV",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Contact_1__c": "003bZ00000XlIrKQAV",
            "Meeting_Date_Time__c": "2026-05-06T15:04:07Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 1
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:08",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03bZ00000XkynoQAB",
        "savedOppId": "006bZ00000W4HpRQAV",
        "expectedOppId": "006bZ00000W4HpRQAV"
    }
}
{
    "timestamp": "2026-05-06 15:04:08",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03bZ00000XkynoQAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03bZ00000XkynoQAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-06 15:04:08",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "950_Le18Juillet-2",
            "1230_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-06 15:04:08",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 15:04:08",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 15:04:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "950_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 15:04:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1230_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 15:04:10",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W4HpRQAV",
        "VisitId": "a03bZ00000XkynoQAB",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "950_Le18Juillet-2",
                "id": "a01bZ00000NvOYHQA3",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1230_Le18Juillet-1",
                "id": "a01bZ00000NvYHTQA3",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 15:08:12",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Thomas",
            "LastName": "Raymond",
            "Email": "thomas.raymond@trudel.ca",
            "Job": "Architecte de Solutions "
        },
        "Clients": [
            {
                "FirstName": "Ezio",
                "LastName": "Auditore",
                "Email": "Ezio.auditore@trudel.ca",
                "Phone": "",
                "Post": ""
            },
            {
                "FirstName": "Mila",
                "LastName": "Kunis",
                "Email": "Mila.kunis@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.06",
            "VisitTime": 75.6001739501953125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02ibZ000003J3lHQAS",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "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-05-06 15:08:15",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000001ng5aYAA"
    }
}
{
    "timestamp": "2026-05-06 15:08: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 ('Ezio.auditore@trudel.ca','Mila.kunis@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Ezio.auditore@trudel.ca",
            "Mila.kunis@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-06 15:08:15",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Ezio.auditore@trudel.ca','Mila.kunis@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003bZ00000XlIrKQAV",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003bZ00000XlIrKQAV'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "foundGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "buildingGroupId": "02ibZ000003J10IQAS"
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006bZ00000W4HpRQAV"
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006bZ00000W4HpRQAV",
        "payload": {
            "Residential_Building__c": "02ibZ000003J3lHQAS",
            "Building_Group__c": "02ibZ000003J10IQAS"
        }
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Ezio",
                "LastName": "Auditore",
                "Email": "Ezio.auditore@trudel.ca",
                "Phone": "",
                "Post": ""
            },
            {
                "FirstName": "Mila",
                "LastName": "Kunis",
                "Email": "Mila.kunis@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-06 15:08:16",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006bZ00000W4HpRQAV",
            "Assign_to__c": "005OF000001ng5aYAA",
            "Meeting_Date_Time__c": "2026-05-06T15:08:16Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 2
        }
    }
}
{
    "timestamp": "2026-05-06 15:08:17",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03bZ00000Xl4GWQAZ",
        "savedOppId": "006bZ00000W4HpRQAV",
        "expectedOppId": "006bZ00000W4HpRQAV"
    }
}
{
    "timestamp": "2026-05-06 15:08:17",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03bZ00000Xl4GWQAZ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03bZ00000Xl4GWQAZ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-06 15:08:17",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "250_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-06 15:08:17",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-06 15:08:17",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-06 15:08:18",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "250_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-06 15:08:18",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006bZ00000W4HpRQAV",
        "VisitId": "a03bZ00000Xl4GWQAZ",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "250_Le18Juillet-2",
                "id": "a01bZ00000NvPlJQAV",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-07 12:23:01",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-07 12:23:03",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Alexia",
            "LastName": "Berthaud",
            "Email": "Alexia.berthaud@trudel.ca",
            "Job": "Conseillère à la location"
        },
        "Clients": [
            {
                "FirstName": "Elon",
                "LastName": "Musk",
                "Email": "Elon.musk@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.07",
            "VisitTime": 477.73382568359375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:03",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-07 12:23:03",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3lYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le21Mars-1"
    }
}
{
    "timestamp": "2026-05-07 12:23:03",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le21Mars-1",
        "residentialBuildingAssetId": "02iOF000004UB3lYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Alexia.berthaud@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": null
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "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 ('Elon.musk@trudel.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "Elon.musk@trudel.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('Elon.musk@trudel.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucun Contact trouvé",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Elon",
                "LastName": "Musk",
                "Email": "Elon.musk@trudel.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Elon.musk@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "Elon.musk@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-07 12:23:04",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "Elon.musk@trudel.ca",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-05-07 12:23:05",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001OF00000ZwAVyYAN",
        "payload": {
            "Name": "Elon Musk",
            "Phone": null,
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:05",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "Elon.musk@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:05",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "Elon.musk@trudel.ca",
        "phone": null
    }
}
{
    "timestamp": "2026-05-07 12:23:05",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "Elon.musk@trudel.ca",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003OF00000WQVH3YAP",
        "accountId": "001OF00000ZwAVyYAN",
        "payload": {
            "FirstName": "Elon",
            "LastName": "Musk",
            "Email": "Elon.musk@trudel.ca",
            "Phone": null,
            "AccountId": "001OF00000ZwAVyYAN",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000ZwAVyYAN",
        "contactIds": [
            "003OF00000WQVH3YAP"
        ]
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Elon Musk",
            "StageName": "Qualification",
            "CloseDate": "2026-06-06",
            "AccountId": "001OF00000ZwAVyYAN",
            "Description": "",
            "Contact__c": "003OF00000WQVH3YAP",
            "Residential_Building__c": "02iOF000004UB3lYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000WQVH3YAP"
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000WQVH3YAP",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "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 = '003OF00000WQVH3YAP'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:06",
    "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 = '003OF00000WQVH3YAP'\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-05-07 12:23:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003OF00000WQVH3YAP"
    }
}
{
    "timestamp": "2026-05-07 12:23:07",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-07 12:23:07",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Elon Musk",
            "StageName": "Qualification",
            "CloseDate": "2026-06-06",
            "AccountId": "001OF00000ZwAVyYAN",
            "Description": "",
            "Contact__c": "003OF00000WQVH3YAP",
            "Residential_Building__c": "02iOF000004UB3lYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:07",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006OF00000aneh7YAA",
            "success": true,
            "errors": []
        },
        "oppId": "006OF00000aneh7YAA"
    }
}
{
    "timestamp": "2026-05-07 12:23:08",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000aneh7YAA",
            "Contact_1__c": "003OF00000WQVH3YAP",
            "Meeting_Date_Time__c": "2026-05-07T12:23:08Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 8
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000WQVIfYAP",
        "savedOppId": "006OF00000aneh7YAA",
        "expectedOppId": "006OF00000aneh7YAA"
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000WQVIfYAP",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000WQVIfYAP",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "802_Le21Mars-1",
            "1302_Le21Mars-1"
        ]
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "802_Le21Mars-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-07 12:23:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1302_Le21Mars-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-07 12:23:10",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000aneh7YAA",
        "VisitId": "a03OF00000WQVIfYAP",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "802_Le21Mars-1",
                "id": "a01OF00000ZwGGNYA3",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1302_Le21Mars-1",
                "id": "a01OF00000ZwOAfYAN",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-07 15:54:28",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "francine",
                "LastName": "laberge",
                "Email": "franlab@videotron.ca",
                "Phone": "4185547666",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.07",
            "VisitTime": 2684.72802734375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "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 ('franlab@videotron.ca') OR Phone IN ('4185547666'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "franlab@videotron.ca"
        ],
        "phones": [
            "4185547666"
        ]
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('franlab@videotron.ca') OR Phone IN ('4185547666'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000WQp6BYAT",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000WQp6BYAT'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000aoCneYAE",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000aoCneYAE",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-07 15:54:30",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000aoCneYAE"
    }
}
{
    "timestamp": "2026-05-07 15:54:31",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000aoCneYAE",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-07 15:54:31",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "francine",
                "LastName": "laberge",
                "Email": "franlab@videotron.ca",
                "Phone": "4185547666",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-07 15:54:31",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000aoCneYAE",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-05-07T15:54:31Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 45
        }
    }
}
{
    "timestamp": "2026-05-07 15:54:31",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000WQglzYAD",
        "savedOppId": "006OF00000aoCneYAE",
        "expectedOppId": "006OF00000aoCneYAE"
    }
}
{
    "timestamp": "2026-05-07 15:54:31",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000WQglzYAD",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000WQglzYAD",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-07 15:54:31",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "277_Le18Juillet-2",
            "276_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-07 15:54:32",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-07 15:54:32",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-07 15:54:32",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "277_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-07 15:54:32",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "276_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-07 15:54:33",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000aoCneYAE",
        "VisitId": "a03OF00000WQglzYAD",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "277_Le18Juillet-2",
                "id": "a01OF00000Zx01RYAR",
                "http": 201
            },
            {
                "ok": true,
                "unit": "276_Le18Juillet-2",
                "id": "a01OF00000ZwnU3YAJ",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-07 19:21:20",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Jean-Jacques",
                "LastName": "Hudon",
                "Email": "jjhudon@videotron.ca",
                "Phone": "4189149914",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.07",
            "VisitTime": 2009.1351318359375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "",
        "residentialBuildingAssetId": null,
        "buildingGroupId": null
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "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 ('jjhudon@videotron.ca') OR Phone IN ('4189149914'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "jjhudon@videotron.ca"
        ],
        "phones": [
            "4189149914"
        ]
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('jjhudon@videotron.ca') OR Phone IN ('4189149914'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 19:21:22",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000AW773YAD",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000AW773YAD'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 19:21:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR vide, fallback Contact__c",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via Contact__c",
    "context": {
        "contactId": "003OF00000AW773YAD",
        "soql": "SELECT Id, Building_Group__c\r\n                 FROM Opportunity\r\n                 WHERE Contact__c = '003OF00000AW773YAD'\r\n                 AND IsClosed = false\r\n                 AND CreatedDate = LAST_N_DAYS:365\r\n                 ORDER BY CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-07 19:21:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucune Opportunity trouvée",
    "context": {
        "contactId": "003OF00000AW773YAD"
    }
}
{
    "timestamp": "2026-05-07 19:21:23",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Jean-Jacques",
                "LastName": "Hudon",
                "Email": "jjhudon@videotron.ca",
                "Phone": "4189149914",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-07 19:21:23",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "jjhudon@videotron.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000AW773YAD"
                    },
                    "Id": "003OF00000AW773YAD",
                    "AccountId": "001OF00000BsNxNYAV",
                    "Email": "jjhudon@videotron.ca",
                    "Phone": null,
                    "MobilePhone": "4189149914",
                    "FirstName": "Jean-Jacques",
                    "LastName": "Hudon"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "jjhudon@videotron.ca",
        "phone": "4189149914",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000AW773YAD"
            },
            "Id": "003OF00000AW773YAD",
            "AccountId": "001OF00000BsNxNYAV",
            "Email": "jjhudon@videotron.ca",
            "Phone": null,
            "MobilePhone": "4189149914",
            "FirstName": "Jean-Jacques",
            "LastName": "Hudon"
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000BsNxNYAV"
    }
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "jjhudon@videotron.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000AW773YAD"
                    },
                    "Id": "003OF00000AW773YAD",
                    "AccountId": "001OF00000BsNxNYAV",
                    "Email": "jjhudon@videotron.ca",
                    "Phone": null,
                    "MobilePhone": "4189149914",
                    "FirstName": "Jean-Jacques",
                    "LastName": "Hudon"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "jjhudon@videotron.ca",
        "phone": "4189149914",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000AW773YAD"
            },
            "Id": "003OF00000AW773YAD",
            "AccountId": "001OF00000BsNxNYAV",
            "Email": "jjhudon@videotron.ca",
            "Phone": null,
            "MobilePhone": "4189149914",
            "FirstName": "Jean-Jacques",
            "LastName": "Hudon"
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000AW773YAD",
        "accountId": "001OF00000BsNxNYAV"
    }
}
{
    "timestamp": "2026-05-07 19:21:24",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000BsNxNYAV",
        "contactIds": [
            "003OF00000AW773YAD"
        ]
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Jean-Jacques Hudon",
            "StageName": "Qualification",
            "CloseDate": "2026-06-06",
            "AccountId": "001OF00000BsNxNYAV",
            "Description": "",
            "Contact__c": "003OF00000AW773YAD",
            "OwnerId": "005OF000004npwjYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000AW773YAD"
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000AW773YAD",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "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 = '003OF00000AW773YAD'\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-05-07 19:21:25",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003OF00000AW773YAD"
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Jean-Jacques Hudon",
            "StageName": "Qualification",
            "CloseDate": "2026-06-06",
            "AccountId": "001OF00000BsNxNYAV",
            "Description": "",
            "Contact__c": "003OF00000AW773YAD",
            "OwnerId": "005OF000004npwjYAA",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:25",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006OF00000aojTWYAY",
            "success": true,
            "errors": []
        },
        "oppId": "006OF00000aojTWYAY"
    }
}
{
    "timestamp": "2026-05-07 19:21:26",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000aojTWYAY",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000AW773YAD",
            "Meeting_Date_Time__c": "2026-05-07T19:21:26Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 34
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:27",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000WRYeIYAX",
        "savedOppId": "006OF00000aojTWYAY",
        "expectedOppId": "006OF00000aojTWYAY"
    }
}
{
    "timestamp": "2026-05-07 19:21:27",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000WRYeIYAX",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000WRYeIYAX",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-07 19:21:27",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": []
    }
}
{
    "timestamp": "2026-05-07 19:21:27",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-07 19:21:27",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-07 19:21:27",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000aojTWYAY",
        "VisitId": "a03OF00000WRYeIYAX",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": []
    }
}
{
    "timestamp": "2026-05-09 17:55:21",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "guy",
                "LastName": "carrier",
                "Email": "lisell.guygc@gmail.com",
                "Phone": "5814433681",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.05.09",
            "VisitTime": 2957.88525390625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "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 ('lisell.guygc@gmail.com') OR Phone IN ('5814433681'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "lisell.guygc@gmail.com"
        ],
        "phones": [
            "5814433681"
        ]
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('lisell.guygc@gmail.com') OR Phone IN ('5814433681'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000WVyNGYA1",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000WVyNGYA1'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000auuFjYAI",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000auuFjYAI",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "guy",
                "LastName": "carrier",
                "Email": "lisell.guygc@gmail.com",
                "Phone": "5814433681",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-09 17:55:23",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "lisell.guygc@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000WVyNGYA1"
                    },
                    "Id": "003OF00000WVyNGYA1",
                    "AccountId": "001OF00000a2EoZYAU",
                    "Email": "lisell.guygc@gmail.com",
                    "Phone": null,
                    "MobilePhone": "581-443-3681",
                    "FirstName": "Guy",
                    "LastName": "Carrier"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "lisell.guygc@gmail.com",
        "phone": "5814433681",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000WVyNGYA1"
            },
            "Id": "003OF00000WVyNGYA1",
            "AccountId": "001OF00000a2EoZYAU",
            "Email": "lisell.guygc@gmail.com",
            "Phone": null,
            "MobilePhone": "581-443-3681",
            "FirstName": "Guy",
            "LastName": "Carrier"
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000a2EoZYAU"
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "lisell.guygc@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000WVyNGYA1"
                    },
                    "Id": "003OF00000WVyNGYA1",
                    "AccountId": "001OF00000a2EoZYAU",
                    "Email": "lisell.guygc@gmail.com",
                    "Phone": null,
                    "MobilePhone": "581-443-3681",
                    "FirstName": "Guy",
                    "LastName": "Carrier"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "lisell.guygc@gmail.com",
        "phone": "5814433681",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000WVyNGYA1"
            },
            "Id": "003OF00000WVyNGYA1",
            "AccountId": "001OF00000a2EoZYAU",
            "Email": "lisell.guygc@gmail.com",
            "Phone": null,
            "MobilePhone": "581-443-3681",
            "FirstName": "Guy",
            "LastName": "Carrier"
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000WVyNGYA1",
        "accountId": "001OF00000a2EoZYAU"
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000a2EoZYAU",
        "contactIds": [
            "003OF00000WVyNGYA1"
        ]
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "guy carrier",
            "StageName": "Qualification",
            "CloseDate": "2026-06-08",
            "AccountId": "001OF00000a2EoZYAU",
            "Description": "",
            "Contact__c": "003OF00000WVyNGYA1",
            "OwnerId": "005OF000004npwjYAA",
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000WVyNGYA1"
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000WVyNGYA1",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "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 = '003OF00000WVyNGYA1'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "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 = '003OF00000WVyNGYA1'\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-05-09 17:55:24",
    "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\/00KOF00000QODWb2AP"
                    },
                    "OpportunityId": "006OF00000auuFjYAI",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000auuFjYAI"
                        },
                        "Id": "006OF00000auuFjYAI",
                        "Name": "Guy Carrier",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-05-09T16:54:00.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000auuFjYAI",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000QODWb2AP"
            },
            "OpportunityId": "006OF00000auuFjYAI",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000auuFjYAI"
                },
                "Id": "006OF00000auuFjYAI",
                "Name": "Guy Carrier",
                "StageName": "Qualification",
                "CreatedDate": "2026-05-09T16:54:00.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000auuFjYAI"
    }
}
{
    "timestamp": "2026-05-09 17:55:24",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000auuFjYAI",
        "contactId": "003OF00000WVyNGYA1",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-09 17:55:25",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000auuFjYAI",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:25",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000auuFjYAI",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000WVyNGYA1",
            "Meeting_Date_Time__c": "2026-05-09T17:55:25Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 50
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:27",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000WVuzcYAD",
        "savedOppId": "006OF00000auuFjYAI",
        "expectedOppId": "006OF00000auuFjYAI"
    }
}
{
    "timestamp": "2026-05-09 17:55:27",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000WVuzcYAD",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000WVuzcYAD",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-09 17:55:27",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1453_Le18Juillet-2",
            "1071_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-09 17:55:27",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-09 17:55:27",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-09 17:55:27",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1453_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-09 17:55:28",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1071_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-09 17:55:28",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000auuFjYAI",
        "VisitId": "a03OF00000WVuzcYAD",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1453_Le18Juillet-2",
                "id": "a01OF00000a29ljYAA",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1071_Le18Juillet-2",
                "id": "a01OF00000a2CObYAM",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-10 18:05:55",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-10 18:05:57",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "michel",
                "LastName": "busque",
                "Email": "michel.busque@videotron.ca",
                "Phone": "5819858668",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.05.10",
            "VisitTime": 3806.47705078125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:57",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-10 18:05:57",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-05-10 18:05:57",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "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 ('michel.busque@videotron.ca') OR Phone IN ('5819858668'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "michel.busque@videotron.ca"
        ],
        "phones": [
            "5819858668"
        ]
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('michel.busque@videotron.ca') OR Phone IN ('5819858668'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000RdW5LYAV",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000RdW5LYAV'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000VitmvYAB",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000VitmvYAB",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "michel",
                "LastName": "busque",
                "Email": "michel.busque@videotron.ca",
                "Phone": "5819858668",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "michel.busque@videotron.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RdW5LYAV"
                    },
                    "Id": "003OF00000RdW5LYAV",
                    "AccountId": "001OF00000UVWKAYA5",
                    "Email": "michel.busque@videotron.ca",
                    "Phone": null,
                    "MobilePhone": "5819858668",
                    "FirstName": "Michel",
                    "LastName": "Busque"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "michel.busque@videotron.ca",
        "phone": "5819858668",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RdW5LYAV"
            },
            "Id": "003OF00000RdW5LYAV",
            "AccountId": "001OF00000UVWKAYA5",
            "Email": "michel.busque@videotron.ca",
            "Phone": null,
            "MobilePhone": "5819858668",
            "FirstName": "Michel",
            "LastName": "Busque"
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:58",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000UVWKAYA5"
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "michel.busque@videotron.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RdW5LYAV"
                    },
                    "Id": "003OF00000RdW5LYAV",
                    "AccountId": "001OF00000UVWKAYA5",
                    "Email": "michel.busque@videotron.ca",
                    "Phone": null,
                    "MobilePhone": "5819858668",
                    "FirstName": "Michel",
                    "LastName": "Busque"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "michel.busque@videotron.ca",
        "phone": "5819858668",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RdW5LYAV"
            },
            "Id": "003OF00000RdW5LYAV",
            "AccountId": "001OF00000UVWKAYA5",
            "Email": "michel.busque@videotron.ca",
            "Phone": null,
            "MobilePhone": "5819858668",
            "FirstName": "Michel",
            "LastName": "Busque"
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000RdW5LYAV",
        "accountId": "001OF00000UVWKAYA5"
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000UVWKAYA5",
        "contactIds": [
            "003OF00000RdW5LYAV"
        ]
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "michel busque",
            "StageName": "Qualification",
            "CloseDate": "2026-06-09",
            "AccountId": "001OF00000UVWKAYA5",
            "Description": "",
            "Contact__c": "003OF00000RdW5LYAV",
            "OwnerId": "005OF000004npwjYAA",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000RdW5LYAV"
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000RdW5LYAV",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "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 = '003OF00000RdW5LYAV'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "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 = '003OF00000RdW5LYAV'\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-05-10 18:05:59",
    "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\/00KOF00000MgxdJ2AR"
                    },
                    "OpportunityId": "006OF00000VitmvYAB",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000VitmvYAB"
                        },
                        "Id": "006OF00000VitmvYAB",
                        "Name": "Michel Busque",
                        "StageName": "Qualification",
                        "CreatedDate": "2025-12-23T16:20:26.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000VitmvYAB",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000MgxdJ2AR"
            },
            "OpportunityId": "006OF00000VitmvYAB",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000VitmvYAB"
                },
                "Id": "006OF00000VitmvYAB",
                "Name": "Michel Busque",
                "StageName": "Qualification",
                "CreatedDate": "2025-12-23T16:20:26.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000VitmvYAB"
    }
}
{
    "timestamp": "2026-05-10 18:05:59",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000VitmvYAB",
        "contactId": "003OF00000RdW5LYAV",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-10 18:06:00",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000VitmvYAB",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-10 18:06:00",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000VitmvYAB",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000RdW5LYAV",
            "Meeting_Date_Time__c": "2026-05-10T18:06:00Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 64
        }
    }
}
{
    "timestamp": "2026-05-10 18:06:01",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000WXIgWYAX",
        "savedOppId": "006OF00000VitmvYAB",
        "expectedOppId": "006OF00000VitmvYAB"
    }
}
{
    "timestamp": "2026-05-10 18:06:01",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000WXIgWYAX",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000WXIgWYAX",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-10 18:06:01",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1507_Le18Juillet-1",
            "1509_Le18Juillet-1",
            "1407_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-10 18:06:01",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-10 18:06:01",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-10 18:06:01",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1507_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-10 18:06:02",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1509_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-10 18:06:02",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1407_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-10 18:06:03",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000VitmvYAB",
        "VisitId": "a03OF00000WXIgWYAX",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1507_Le18Juillet-1",
                "id": "a01OF00000a3eQvYAI",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1509_Le18Juillet-1",
                "id": "a01OF00000a3gxHYAQ",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1407_Le18Juillet-1",
                "id": "a01OF00000a3jQTYAY",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-22 17:55:16",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Sara",
                "LastName": "Benlarbi",
                "Email": "sarajesenia@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.05.22",
            "VisitTime": 1330.310546875,
            "Pet": "",
            "UnitsSeeked": [
                "4.5"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "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 ('sarajesenia@hotmail.com'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "sarajesenia@hotmail.com"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-22 17:55:18",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('sarajesenia@hotmail.com'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000X0hwQYAR",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000X0hwQYAR'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000bRTv4YAG",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000bRTv4YAG",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Sara",
                "LastName": "Benlarbi",
                "Email": "sarajesenia@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "sarajesenia@hotmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X0hwQYAR"
                    },
                    "Id": "003OF00000X0hwQYAR",
                    "AccountId": "001OF00000aaZtnYAE",
                    "Email": "sarajesenia@hotmail.com",
                    "Phone": null,
                    "MobilePhone": "4182625107",
                    "FirstName": "Sara",
                    "LastName": "Benlarbin"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "sarajesenia@hotmail.com",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X0hwQYAR"
            },
            "Id": "003OF00000X0hwQYAR",
            "AccountId": "001OF00000aaZtnYAE",
            "Email": "sarajesenia@hotmail.com",
            "Phone": null,
            "MobilePhone": "4182625107",
            "FirstName": "Sara",
            "LastName": "Benlarbin"
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000aaZtnYAE"
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "sarajesenia@hotmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X0hwQYAR"
                    },
                    "Id": "003OF00000X0hwQYAR",
                    "AccountId": "001OF00000aaZtnYAE",
                    "Email": "sarajesenia@hotmail.com",
                    "Phone": null,
                    "MobilePhone": "4182625107",
                    "FirstName": "Sara",
                    "LastName": "Benlarbin"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "sarajesenia@hotmail.com",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X0hwQYAR"
            },
            "Id": "003OF00000X0hwQYAR",
            "AccountId": "001OF00000aaZtnYAE",
            "Email": "sarajesenia@hotmail.com",
            "Phone": null,
            "MobilePhone": "4182625107",
            "FirstName": "Sara",
            "LastName": "Benlarbin"
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000X0hwQYAR",
        "accountId": "001OF00000aaZtnYAE"
    }
}
{
    "timestamp": "2026-05-22 17:55:19",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000aaZtnYAE",
        "contactIds": [
            "003OF00000X0hwQYAR"
        ]
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Sara Benlarbi",
            "StageName": "Qualification",
            "CloseDate": "2026-06-21",
            "AccountId": "001OF00000aaZtnYAE",
            "Description": "",
            "Contact__c": "003OF00000X0hwQYAR",
            "OwnerId": "005OF000002YlL7YAK",
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000X0hwQYAR"
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000X0hwQYAR",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-22 17:55: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 = '003OF00000X0hwQYAR'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-22 17:55: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 = '003OF00000X0hwQYAR'\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-05-22 17:55: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\/00KOF00000QlVJ82AN"
                    },
                    "OpportunityId": "006OF00000bRTv4YAG",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000bRTv4YAG"
                        },
                        "Id": "006OF00000bRTv4YAG",
                        "Name": "Sara Benlarbin",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-05-22T17:25:42.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000bRTv4YAG",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000QlVJ82AN"
            },
            "OpportunityId": "006OF00000bRTv4YAG",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000bRTv4YAG"
                },
                "Id": "006OF00000bRTv4YAG",
                "Name": "Sara Benlarbin",
                "StageName": "Qualification",
                "CreatedDate": "2026-05-22T17:25:42.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000bRTv4YAG"
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000bRTv4YAG",
        "contactId": "003OF00000X0hwQYAR",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-22 17:55:20",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000bRTv4YAG",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:21",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bRTv4YAG",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Contact_1__c": "003OF00000X0hwQYAR",
            "Meeting_Date_Time__c": "2026-05-22T17:55:21Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 23
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:21",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000X0pnVYAR",
        "savedOppId": "006OF00000bRTv4YAG",
        "expectedOppId": "006OF00000bRTv4YAG"
    }
}
{
    "timestamp": "2026-05-22 17:55:21",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000X0pnVYAR",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000X0pnVYAR",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-22 17:55:21",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1362_Le18Juillet-2",
            "256_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-22 17:55:21",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-22 17:55:21",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-22 17:55:22",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1362_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-22 17:55:22",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "256_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-22 17:55:22",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bRTv4YAG",
        "VisitId": "a03OF00000X0pnVYAR",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1362_Le18Juillet-2",
                "id": "a01OF00000aahHtYAI",
                "http": 201
            },
            {
                "ok": true,
                "unit": "256_Le18Juillet-2",
                "id": "a01OF00000aanS5YAI",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-22 18:35:29",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "louise",
                "LastName": "simard",
                "Email": "louisesimard93@hotmail.com",
                "Phone": "5813095657",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.05.22",
            "VisitTime": 2723.251708984375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "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 ('louisesimard93@hotmail.com') OR Phone IN ('5813095657'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "louisesimard93@hotmail.com"
        ],
        "phones": [
            "5813095657"
        ]
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('louisesimard93@hotmail.com') OR Phone IN ('5813095657'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000X0iXWYAZ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000X0iXWYAZ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000bRGMlYAO",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000bRGMlYAO",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-22 18:35:31",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000bRGMlYAO"
    }
}
{
    "timestamp": "2026-05-22 18:35:32",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000bRGMlYAO",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-22 18:35:32",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "louise",
                "LastName": "simard",
                "Email": "louisesimard93@hotmail.com",
                "Phone": "5813095657",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-22 18:35:32",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bRGMlYAO",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-05-22T18:35:32Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 46
        }
    }
}
{
    "timestamp": "2026-05-22 18:35:32",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000X0dUcYAJ",
        "savedOppId": "006OF00000bRGMlYAO",
        "expectedOppId": "006OF00000bRGMlYAO"
    }
}
{
    "timestamp": "2026-05-22 18:35:32",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000X0dUcYAJ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000X0dUcYAJ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-22 18:35:32",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "369_Le18Juillet-2",
            "663_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-22 18:35:33",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-22 18:35:33",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-22 18:35:33",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "369_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-22 18:35:33",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "663_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-22 18:35:34",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bRGMlYAO",
        "VisitId": "a03OF00000X0dUcYAJ",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "369_Le18Juillet-2",
                "id": "a01OF00000aawojYAA",
                "http": 201
            },
            {
                "ok": true,
                "unit": "663_Le18Juillet-2",
                "id": "a01OF00000aadEJYAY",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-25 16:00:20",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "marlene",
                "LastName": "desrochers",
                "Email": "marlene.desrochers@live.ca",
                "Phone": "4188023132",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.25",
            "VisitTime": 4911.72802734375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "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 ('marlene.desrochers@live.ca') OR Phone IN ('4188023132'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "marlene.desrochers@live.ca"
        ],
        "phones": [
            "4188023132"
        ]
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('marlene.desrochers@live.ca') OR Phone IN ('4188023132'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-25 16:00:22",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000X5rThYAJ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000X5rThYAJ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-25 16:00:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000bWyYPYA0",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-25 16:00:23",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000bWyYPYA0",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-25 16:00:23",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000bWyYPYA0"
    }
}
{
    "timestamp": "2026-05-25 16:00:23",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000bWyYPYA0",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-25 16:00:23",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "marlene",
                "LastName": "desrochers",
                "Email": "marlene.desrochers@live.ca",
                "Phone": "4188023132",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-25 16:00:23",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bWyYPYA0",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-05-25T16:00:23Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 82
        }
    }
}
{
    "timestamp": "2026-05-25 16:00:24",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000X65GYYAZ",
        "savedOppId": "006OF00000bWyYPYA0",
        "expectedOppId": "006OF00000bWyYPYA0"
    }
}
{
    "timestamp": "2026-05-25 16:00:24",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000X65GYYAZ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000X65GYYAZ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-25 16:00:24",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1058_Le18Juillet-2",
            "863_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-05-25 16:00:24",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-25 16:00:24",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-25 16:00:24",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1058_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-25 16:00:25",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "863_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-25 16:00:26",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bWyYPYA0",
        "VisitId": "a03OF00000X65GYYAZ",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1058_Le18Juillet-2",
                "id": "a01OF00000agcCHYAY",
                "http": 201
            },
            {
                "ok": true,
                "unit": "863_Le18Juillet-2",
                "id": "a01OF00000agfGYYAY",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-26 18:24:34",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "PIERRE",
                "LastName": "tHÉRIAULT",
                "Email": "pijoal@icloud.com",
                "Phone": "4509909695",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.05.26",
            "VisitTime": 3581.91064453125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "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 ('pijoal@icloud.com') OR Phone IN ('4509909695'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "pijoal@icloud.com"
        ],
        "phones": [
            "4509909695"
        ]
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('pijoal@icloud.com') OR Phone IN ('4509909695'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000X97KFYAZ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000X97KFYAZ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000baIkJYAU",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000baIkJYAU",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "PIERRE",
                "LastName": "tHÉRIAULT",
                "Email": "pijoal@icloud.com",
                "Phone": "4509909695",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-26 18:24:36",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "pijoal@icloud.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X97KFYAZ"
                    },
                    "Id": "003OF00000X97KFYAZ",
                    "AccountId": "001OF00000ajx2UYAQ",
                    "Email": "pijoal@icloud.com",
                    "Phone": null,
                    "MobilePhone": "4509909695",
                    "FirstName": "Pierre",
                    "LastName": "Theriault"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "pijoal@icloud.com",
        "phone": "4509909695",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X97KFYAZ"
            },
            "Id": "003OF00000X97KFYAZ",
            "AccountId": "001OF00000ajx2UYAQ",
            "Email": "pijoal@icloud.com",
            "Phone": null,
            "MobilePhone": "4509909695",
            "FirstName": "Pierre",
            "LastName": "Theriault"
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000ajx2UYAQ"
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "pijoal@icloud.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X97KFYAZ"
                    },
                    "Id": "003OF00000X97KFYAZ",
                    "AccountId": "001OF00000ajx2UYAQ",
                    "Email": "pijoal@icloud.com",
                    "Phone": null,
                    "MobilePhone": "4509909695",
                    "FirstName": "Pierre",
                    "LastName": "Theriault"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "pijoal@icloud.com",
        "phone": "4509909695",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000X97KFYAZ"
            },
            "Id": "003OF00000X97KFYAZ",
            "AccountId": "001OF00000ajx2UYAQ",
            "Email": "pijoal@icloud.com",
            "Phone": null,
            "MobilePhone": "4509909695",
            "FirstName": "Pierre",
            "LastName": "Theriault"
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000X97KFYAZ",
        "accountId": "001OF00000ajx2UYAQ"
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000ajx2UYAQ",
        "contactIds": [
            "003OF00000X97KFYAZ"
        ]
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "PIERRE tHÉRIAULT",
            "StageName": "Qualification",
            "CloseDate": "2026-06-25",
            "AccountId": "001OF00000ajx2UYAQ",
            "Description": "",
            "Contact__c": "003OF00000X97KFYAZ",
            "OwnerId": "005OF000004npwjYAA",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000X97KFYAZ"
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000X97KFYAZ",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-26 18:24:37",
    "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 = '003OF00000X97KFYAZ'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "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 = '003OF00000X97KFYAZ'\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-05-26 18:24:38",
    "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\/00KOF00000Qqu5a2AB"
                    },
                    "OpportunityId": "006OF00000baIkJYAU",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000baIkJYAU"
                        },
                        "Id": "006OF00000baIkJYAU",
                        "Name": "Pierre Thériault-",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-05-26T18:00:07.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000baIkJYAU",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000Qqu5a2AB"
            },
            "OpportunityId": "006OF00000baIkJYAU",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000baIkJYAU"
                },
                "Id": "006OF00000baIkJYAU",
                "Name": "Pierre Thériault-",
                "StageName": "Qualification",
                "CreatedDate": "2026-05-26T18:00:07.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000baIkJYAU"
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000baIkJYAU",
        "contactId": "003OF00000X97KFYAZ",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000baIkJYAU",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:38",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000baIkJYAU",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000X97KFYAZ",
            "Meeting_Date_Time__c": "2026-05-26T18:24:38Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 60
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:39",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000X9D35YAF",
        "savedOppId": "006OF00000baIkJYAU",
        "expectedOppId": "006OF00000baIkJYAU"
    }
}
{
    "timestamp": "2026-05-26 18:24:39",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000X9D35YAF",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000X9D35YAF",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-26 18:24:39",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1424_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-26 18:24:39",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-26 18:24:39",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-26 18:24:40",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1424_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-26 18:24:40",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000baIkJYAU",
        "VisitId": "a03OF00000X9D35YAF",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1424_Le18Juillet-1",
                "id": "a01OF00000akGD8YAM",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-28 14:37:02",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-28 14:37:04",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Mario",
                "LastName": "Cormier",
                "Email": "mariocormier69@gmail.com",
                "Phone": "5819843448",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.28",
            "VisitTime": 1840.841552734375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:04",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-28 14:37:04",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-05-28 14:37:04",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-28 14:37:04",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:04",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-05-28 14:37:04",
    "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 ('mariocormier69@gmail.com') OR Phone IN ('5819843448'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "mariocormier69@gmail.com"
        ],
        "phones": [
            "5819843448"
        ]
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('mariocormier69@gmail.com') OR Phone IN ('5819843448'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000B7HLxYAN",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000B7HLxYAN'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR vide, fallback Contact__c",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via Contact__c",
    "context": {
        "contactId": "003OF00000B7HLxYAN",
        "soql": "SELECT Id, Building_Group__c\r\n                 FROM Opportunity\r\n                 WHERE Contact__c = '003OF00000B7HLxYAN'\r\n                 AND IsClosed = false\r\n                 AND CreatedDate = LAST_N_DAYS:365\r\n                 ORDER BY CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucune Opportunity trouvée",
    "context": {
        "contactId": "003OF00000B7HLxYAN"
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Mario",
                "LastName": "Cormier",
                "Email": "mariocormier69@gmail.com",
                "Phone": "5819843448",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-28 14:37:05",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "mariocormier69@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000B7HLxYAN"
                    },
                    "Id": "003OF00000B7HLxYAN",
                    "AccountId": "001OF00000CWcRRYA1",
                    "Email": "mariocormier69@gmail.com",
                    "Phone": null,
                    "MobilePhone": "5819843448",
                    "FirstName": "Mario",
                    "LastName": "Cormier"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "mariocormier69@gmail.com",
        "phone": "5819843448",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000B7HLxYAN"
            },
            "Id": "003OF00000B7HLxYAN",
            "AccountId": "001OF00000CWcRRYA1",
            "Email": "mariocormier69@gmail.com",
            "Phone": null,
            "MobilePhone": "5819843448",
            "FirstName": "Mario",
            "LastName": "Cormier"
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000CWcRRYA1"
    }
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "mariocormier69@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000B7HLxYAN"
                    },
                    "Id": "003OF00000B7HLxYAN",
                    "AccountId": "001OF00000CWcRRYA1",
                    "Email": "mariocormier69@gmail.com",
                    "Phone": null,
                    "MobilePhone": "5819843448",
                    "FirstName": "Mario",
                    "LastName": "Cormier"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "mariocormier69@gmail.com",
        "phone": "5819843448",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000B7HLxYAN"
            },
            "Id": "003OF00000B7HLxYAN",
            "AccountId": "001OF00000CWcRRYA1",
            "Email": "mariocormier69@gmail.com",
            "Phone": null,
            "MobilePhone": "5819843448",
            "FirstName": "Mario",
            "LastName": "Cormier"
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000B7HLxYAN",
        "accountId": "001OF00000CWcRRYA1"
    }
}
{
    "timestamp": "2026-05-28 14:37:06",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000CWcRRYA1",
        "contactIds": [
            "003OF00000B7HLxYAN"
        ]
    }
}
{
    "timestamp": "2026-05-28 14:37:07",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Mario Cormier",
            "StageName": "Qualification",
            "CloseDate": "2026-06-27",
            "AccountId": "001OF00000CWcRRYA1",
            "Description": "",
            "Contact__c": "003OF00000B7HLxYAN",
            "OwnerId": "005OF000002YlL7YAK",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000B7HLxYAN"
    }
}
{
    "timestamp": "2026-05-28 14:37:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000B7HLxYAN",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-28 14:37: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 = '003OF00000B7HLxYAN'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-28 14:37:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-28 14:37: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 = '003OF00000B7HLxYAN'\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-05-28 14:37:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:07",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003OF00000B7HLxYAN"
    }
}
{
    "timestamp": "2026-05-28 14:37:07",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-05-28 14:37:07",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Mario Cormier",
            "StageName": "Qualification",
            "CloseDate": "2026-06-27",
            "AccountId": "001OF00000CWcRRYA1",
            "Description": "",
            "Contact__c": "003OF00000B7HLxYAN",
            "OwnerId": "005OF000002YlL7YAK",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:08",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006OF00000bg1wsYAA",
            "success": true,
            "errors": []
        },
        "oppId": "006OF00000bg1wsYAA"
    }
}
{
    "timestamp": "2026-05-28 14:37:09",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bg1wsYAA",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Contact_1__c": "003OF00000B7HLxYAN",
            "Meeting_Date_Time__c": "2026-05-28T14:37:09Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 31
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:09",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XEkfuYAD",
        "savedOppId": "006OF00000bg1wsYAA",
        "expectedOppId": "006OF00000bg1wsYAA"
    }
}
{
    "timestamp": "2026-05-28 14:37:09",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XEkfuYAD",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XEkfuYAD",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-28 14:37:09",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "826_Le18Juillet-1",
            "828_Le18Juillet-1",
            "228_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-28 14:37:09",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-28 14:37:09",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-28 14:37:10",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "826_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-28 14:37:10",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "828_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-28 14:37:11",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "228_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-28 14:37:11",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bg1wsYAA",
        "VisitId": "a03OF00000XEkfuYAD",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "826_Le18Juillet-1",
                "id": "a01OF00000aqTUEYA2",
                "http": 201
            },
            {
                "ok": true,
                "unit": "828_Le18Juillet-1",
                "id": "a01OF00000aq7yNYAQ",
                "http": 201
            },
            {
                "ok": true,
                "unit": "228_Le18Juillet-1",
                "id": "a01OF00000aq0qSYAQ",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-28 15:59:03",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-28 15:59:05",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Andrée",
                "LastName": "Hardy",
                "Email": "miss1950@videotron.ca",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.28",
            "VisitTime": 875.8779296875,
            "Pet": "",
            "UnitsSeeked": [
                "3.5 avec bureau",
                "4.5"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-28 15:59:05",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-28 15:59:05",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "",
        "residentialBuildingAssetId": null,
        "buildingGroupId": null
    }
}
{
    "timestamp": "2026-05-28 15:59:05",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-28 15:59:05",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-05-28 15:59: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 ('miss1950@videotron.ca'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "miss1950@videotron.ca"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('miss1950@videotron.ca'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XF4ujYAD",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XF4ujYAD'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000bgStpYAE",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000bgStpYAE"
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Andrée",
                "LastName": "Hardy",
                "Email": "miss1950@videotron.ca",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-28 15:59:06",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bgStpYAE",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Meeting_Date_Time__c": "2026-05-28T15:59:06Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 15
        }
    }
}
{
    "timestamp": "2026-05-28 15:59:07",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XF8WvYAL",
        "savedOppId": "006OF00000bgStpYAE",
        "expectedOppId": "006OF00000bgStpYAE"
    }
}
{
    "timestamp": "2026-05-28 15:59:07",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XF8WvYAL",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XF8WvYAL",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-28 15:59:07",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": []
    }
}
{
    "timestamp": "2026-05-28 15:59:07",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-28 15:59:07",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-28 15:59:07",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bgStpYAE",
        "VisitId": "a03OF00000XF8WvYAL",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": []
    }
}
{
    "timestamp": "2026-05-30 17:44:11",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "jacques",
                "LastName": "martel",
                "Email": "j.jmartel@outlook.com",
                "Phone": "4188429722",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.30",
            "VisitTime": 2642.69873046875,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "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 ('j.jmartel@outlook.com') OR Phone IN ('4188429722'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "j.jmartel@outlook.com"
        ],
        "phones": [
            "4188429722"
        ]
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-30 17:44:13",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('j.jmartel@outlook.com') OR Phone IN ('4188429722'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000TZn1xYAD",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000TZn1xYAD'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000XiI9VYAV",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000XiI9VYAV",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "jacques",
                "LastName": "martel",
                "Email": "j.jmartel@outlook.com",
                "Phone": "4188429722",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "j.jmartel@outlook.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000TZn1xYAD"
                    },
                    "Id": "003OF00000TZn1xYAD",
                    "AccountId": "001OF00000WjwwfYAB",
                    "Email": "j.jmartel@outlook.com",
                    "Phone": null,
                    "MobilePhone": "4188429722",
                    "FirstName": "Jacques",
                    "LastName": "Martel"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "j.jmartel@outlook.com",
        "phone": "4188429722",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000TZn1xYAD"
            },
            "Id": "003OF00000TZn1xYAD",
            "AccountId": "001OF00000WjwwfYAB",
            "Email": "j.jmartel@outlook.com",
            "Phone": null,
            "MobilePhone": "4188429722",
            "FirstName": "Jacques",
            "LastName": "Martel"
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000WjwwfYAB"
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "j.jmartel@outlook.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000TZn1xYAD"
                    },
                    "Id": "003OF00000TZn1xYAD",
                    "AccountId": "001OF00000WjwwfYAB",
                    "Email": "j.jmartel@outlook.com",
                    "Phone": null,
                    "MobilePhone": "4188429722",
                    "FirstName": "Jacques",
                    "LastName": "Martel"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "j.jmartel@outlook.com",
        "phone": "4188429722",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000TZn1xYAD"
            },
            "Id": "003OF00000TZn1xYAD",
            "AccountId": "001OF00000WjwwfYAB",
            "Email": "j.jmartel@outlook.com",
            "Phone": null,
            "MobilePhone": "4188429722",
            "FirstName": "Jacques",
            "LastName": "Martel"
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000TZn1xYAD",
        "accountId": "001OF00000WjwwfYAB"
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000WjwwfYAB",
        "contactIds": [
            "003OF00000TZn1xYAD"
        ]
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "jacques martel",
            "StageName": "Qualification",
            "CloseDate": "2026-06-29",
            "AccountId": "001OF00000WjwwfYAB",
            "Description": "",
            "Contact__c": "003OF00000TZn1xYAD",
            "OwnerId": "005OF000004npwjYAA",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000TZn1xYAD"
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000TZn1xYAD",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-30 17:44:14",
    "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 = '003OF00000TZn1xYAD'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "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 = '003OF00000TZn1xYAD'\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-05-30 17:44:15",
    "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\/00KOF00000O3Uq92AF"
                    },
                    "OpportunityId": "006OF00000XiI9VYAV",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000XiI9VYAV"
                        },
                        "Id": "006OF00000XiI9VYAV",
                        "Name": "Jacques Martel",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-02-19T19:52:17.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000XiI9VYAV",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000O3Uq92AF"
            },
            "OpportunityId": "006OF00000XiI9VYAV",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000XiI9VYAV"
                },
                "Id": "006OF00000XiI9VYAV",
                "Name": "Jacques Martel",
                "StageName": "Qualification",
                "CreatedDate": "2026-02-19T19:52:17.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000XiI9VYAV"
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000XiI9VYAV",
        "contactId": "003OF00000TZn1xYAD",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000XiI9VYAV",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:15",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000XiI9VYAV",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000TZn1xYAD",
            "Meeting_Date_Time__c": "2026-05-30T17:44:15Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 45
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:16",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XL4LmYAL",
        "savedOppId": "006OF00000XiI9VYAV",
        "expectedOppId": "006OF00000XiI9VYAV"
    }
}
{
    "timestamp": "2026-05-30 17:44:16",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XL4LmYAL",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XL4LmYAL",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-30 17:44:16",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1109_Le18Juillet-1",
            "1118_Le18Juillet-1",
            "529_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-30 17:44:16",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-30 17:44:16",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-30 17:44:17",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1109_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-30 17:44:17",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1118_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-30 17:44:18",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "529_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-30 17:44:18",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000XiI9VYAV",
        "VisitId": "a03OF00000XL4LmYAL",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1109_Le18Juillet-1",
                "id": "a01OF00000axjsQYAQ",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1118_Le18Juillet-1",
                "id": "a01OF00000axjPPYAY",
                "http": 201
            },
            {
                "ok": true,
                "unit": "529_Le18Juillet-1",
                "id": "a01OF00000axle7YAA",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-30 19:48:58",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "remi",
                "LastName": "lavoie",
                "Email": "remilavoie.fxsb@gmail.com",
                "Phone": "5819990548",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.30",
            "VisitTime": 1197.731689453125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "",
        "residentialBuildingAssetId": null,
        "buildingGroupId": null
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "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 ('remilavoie.fxsb@gmail.com') OR Phone IN ('5819990548'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "remilavoie.fxsb@gmail.com"
        ],
        "phones": [
            "5819990548"
        ]
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('remilavoie.fxsb@gmail.com') OR Phone IN ('5819990548'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XL6fLYAT",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XL6fLYAT'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000bmyhLYAQ",
        "foundGroupId": "02iOF000004UAz5YAG"
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000bmyhLYAQ"
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "remi",
                "LastName": "lavoie",
                "Email": "remilavoie.fxsb@gmail.com",
                "Phone": "5819990548",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-30 19:49:01",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bmyhLYAQ",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-05-30T19:49:01Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 20
        }
    }
}
{
    "timestamp": "2026-05-30 19:49:02",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XLK8nYAH",
        "savedOppId": "006OF00000bmyhLYAQ",
        "expectedOppId": "006OF00000bmyhLYAQ"
    }
}
{
    "timestamp": "2026-05-30 19:49:02",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XLK8nYAH",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XLK8nYAH",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-30 19:49:02",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": []
    }
}
{
    "timestamp": "2026-05-30 19:49:02",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-30 19:49:02",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-30 19:49:02",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bmyhLYAQ",
        "VisitId": "a03OF00000XLK8nYAH",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": []
    }
}
{
    "timestamp": "2026-05-31 15:28:29",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "denis",
                "LastName": "cimon",
                "Email": "deniscimon@hotmail.ca",
                "Phone": "4184353235",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.31",
            "VisitTime": 3418.99462890625,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "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 ('deniscimon@hotmail.ca') OR Phone IN ('4184353235'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "deniscimon@hotmail.ca"
        ],
        "phones": [
            "4184353235"
        ]
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-31 15:28:31",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('deniscimon@hotmail.ca') OR Phone IN ('4184353235'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000TIJbQYAX",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000TIJbQYAX'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000XQhESYA1",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000XQhESYA1",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000XQhESYA1"
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000XQhESYA1",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "denis",
                "LastName": "cimon",
                "Email": "deniscimon@hotmail.ca",
                "Phone": "4184353235",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-31 15:28:32",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000XQhESYA1",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-05-31T15:28:32Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 57
        }
    }
}
{
    "timestamp": "2026-05-31 15:28:33",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XMUECYA5",
        "savedOppId": "006OF00000XQhESYA1",
        "expectedOppId": "006OF00000XQhESYA1"
    }
}
{
    "timestamp": "2026-05-31 15:28:33",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XMUECYA5",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XMUECYA5",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-31 15:28:33",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1430_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-31 15:28:33",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-31 15:28:33",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-31 15:28:33",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1430_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-31 15:28:34",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000XQhESYA1",
        "VisitId": "a03OF00000XMUECYA5",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1430_Le18Juillet-1",
                "id": "a01OF00000az2ORYAY",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-05-31 17:49:37",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-05-31 17:49:39",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "francine",
                "LastName": "frigault",
                "Email": "ffrigault@videotron.ca",
                "Phone": "4186619422",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.05.31",
            "VisitTime": 2408.5107421875,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:39",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "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 ('ffrigault@videotron.ca') OR Phone IN ('4186619422'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "ffrigault@videotron.ca"
        ],
        "phones": [
            "4186619422"
        ]
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('ffrigault@videotron.ca') OR Phone IN ('4186619422'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XMWawYAH",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XMWawYAH'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000boUaIYAU",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000boUaIYAU",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "francine",
                "LastName": "frigault",
                "Email": "ffrigault@videotron.ca",
                "Phone": "4186619422",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-05-31 17:49:40",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "ffrigault@videotron.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000XMWawYAH"
                    },
                    "Id": "003OF00000XMWawYAH",
                    "AccountId": "001OF00000azLUEYA2",
                    "Email": "ffrigault@videotron.ca",
                    "Phone": null,
                    "MobilePhone": "4186619422",
                    "FirstName": "Francine",
                    "LastName": "Frigault"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "ffrigault@videotron.ca",
        "phone": "4186619422",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000XMWawYAH"
            },
            "Id": "003OF00000XMWawYAH",
            "AccountId": "001OF00000azLUEYA2",
            "Email": "ffrigault@videotron.ca",
            "Phone": null,
            "MobilePhone": "4186619422",
            "FirstName": "Francine",
            "LastName": "Frigault"
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000azLUEYA2"
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "ffrigault@videotron.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000XMWawYAH"
                    },
                    "Id": "003OF00000XMWawYAH",
                    "AccountId": "001OF00000azLUEYA2",
                    "Email": "ffrigault@videotron.ca",
                    "Phone": null,
                    "MobilePhone": "4186619422",
                    "FirstName": "Francine",
                    "LastName": "Frigault"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "ffrigault@videotron.ca",
        "phone": "4186619422",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000XMWawYAH"
            },
            "Id": "003OF00000XMWawYAH",
            "AccountId": "001OF00000azLUEYA2",
            "Email": "ffrigault@videotron.ca",
            "Phone": null,
            "MobilePhone": "4186619422",
            "FirstName": "Francine",
            "LastName": "Frigault"
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000XMWawYAH",
        "accountId": "001OF00000azLUEYA2"
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000azLUEYA2",
        "contactIds": [
            "003OF00000XMWawYAH"
        ]
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "francine frigault",
            "StageName": "Qualification",
            "CloseDate": "2026-06-30",
            "AccountId": "001OF00000azLUEYA2",
            "Description": "",
            "Contact__c": "003OF00000XMWawYAH",
            "OwnerId": "005OF000004npwjYAA",
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000XMWawYAH"
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000XMWawYAH",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "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 = '003OF00000XMWawYAH'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:41",
    "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 = '003OF00000XMWawYAH'\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-05-31 17:49:42",
    "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\/00KOF00000R20UD2AZ"
                    },
                    "OpportunityId": "006OF00000boUaIYAU",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000boUaIYAU"
                        },
                        "Id": "006OF00000boUaIYAU",
                        "Name": "Francine Frigault",
                        "StageName": "Qualification",
                        "CreatedDate": "2026-05-31T17:05:21.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:42",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000boUaIYAU",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000R20UD2AZ"
            },
            "OpportunityId": "006OF00000boUaIYAU",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000boUaIYAU"
                },
                "Id": "006OF00000boUaIYAU",
                "Name": "Francine Frigault",
                "StageName": "Qualification",
                "CreatedDate": "2026-05-31T17:05:21.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:42",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000boUaIYAU"
    }
}
{
    "timestamp": "2026-05-31 17:49:42",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000boUaIYAU",
        "contactId": "003OF00000XMWawYAH",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-05-31 17:49:42",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000boUaIYAU",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:42",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000boUaIYAU",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000XMWawYAH",
            "Meeting_Date_Time__c": "2026-05-31T17:49:42Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 41
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:43",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XMRBWYA5",
        "savedOppId": "006OF00000boUaIYAU",
        "expectedOppId": "006OF00000boUaIYAU"
    }
}
{
    "timestamp": "2026-05-31 17:49:43",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XMRBWYA5",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XMRBWYA5",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-05-31 17:49:43",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "663_Le18Juillet-2",
            "355_Le18Juillet-2",
            "253_Le18Juillet-2",
            "1058_Le18Juillet-2",
            "1118_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-05-31 17:49:43",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-05-31 17:49:43",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-05-31 17:49:43",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "663_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-31 17:49:44",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "355_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-31 17:49:45",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "253_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-31 17:49:45",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1058_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-31 17:49:46",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1118_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-05-31 17:49:46",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000boUaIYAU",
        "VisitId": "a03OF00000XMRBWYA5",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "663_Le18Juillet-2",
                "id": "a01OF00000azJ95YAE",
                "http": 201
            },
            {
                "ok": true,
                "unit": "355_Le18Juillet-2",
                "id": "a01OF00000azRMsYAM",
                "http": 201
            },
            {
                "ok": true,
                "unit": "253_Le18Juillet-2",
                "id": "a01OF00000azOX1YAM",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1058_Le18Juillet-2",
                "id": "a01OF00000ayuiYYAQ",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1118_Le18Juillet-1",
                "id": "a01OF00000azPG9YAM",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-01 16:48:29",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Nicole",
                "LastName": "Benoit",
                "Email": "nicole.benoit001@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.01",
            "VisitTime": 1088.736328125,
            "Pet": "",
            "UnitsSeeked": [
                "3.5",
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "",
        "residentialBuildingAssetId": null,
        "buildingGroupId": null
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "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 ('nicole.benoit001@hotmail.com'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "nicole.benoit001@hotmail.com"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('nicole.benoit001@hotmail.com'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucun Contact trouvé",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Nicole",
                "LastName": "Benoit",
                "Email": "nicole.benoit001@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-01 16:48:31",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "nicole.benoit001@hotmail.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "nicole.benoit001@hotmail.com",
        "phone": null
    }
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "nicole.benoit001@hotmail.com",
        "phone": "",
        "existingPrimaryContact": null
    }
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG upsert_contacts_with_shared_family_account - family account created",
    "context": {
        "accountId": "001OF00000b2ciDYAQ",
        "payload": {
            "Name": "Nicole Benoit",
            "Phone": null,
            "OwnerId": "005OF000002YlL7YAK",
            "RecordTypeId": "0128a000000NQfvAAG"
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "nicole.benoit001@hotmail.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG sf_find_contact_by_email_or_phone - no contact found",
    "context": {
        "email": "nicole.benoit001@hotmail.com",
        "phone": null
    }
}
{
    "timestamp": "2026-06-01 16:48:32",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "nicole.benoit001@hotmail.com",
        "phone": "",
        "existingContact": null
    }
}
{
    "timestamp": "2026-06-01 16:48:33",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact created",
    "context": {
        "contactId": "003OF00000XP3FpYAL",
        "accountId": "001OF00000b2ciDYAQ",
        "payload": {
            "FirstName": "Nicole",
            "LastName": "Benoit",
            "Email": "nicole.benoit001@hotmail.com",
            "Phone": null,
            "AccountId": "001OF00000b2ciDYAQ",
            "OwnerId": "005OF000002YlL7YAK",
            "RecordTypeId": "0128a000001CI9rAAG"
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:33",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000b2ciDYAQ",
        "contactIds": [
            "003OF00000XP3FpYAL"
        ]
    }
}
{
    "timestamp": "2026-06-01 16:48:34",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Nicole Benoit",
            "StageName": "Qualification",
            "CloseDate": "2026-07-01",
            "AccountId": "001OF00000b2ciDYAQ",
            "Description": "",
            "Contact__c": "003OF00000XP3FpYAL",
            "OwnerId": "005OF000002YlL7YAK",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000XP3FpYAL"
    }
}
{
    "timestamp": "2026-06-01 16:48:34",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000XP3FpYAL",
        "buildingsPicklist": null,
        "buildingGroupAccountId": null,
        "days": 180,
        "whereVariants": [
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-06-01 16:48:34",
    "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 = '003OF00000XP3FpYAL'\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-06-01 16:48:34",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:34",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003OF00000XP3FpYAL"
    }
}
{
    "timestamp": "2026-06-01 16:48:34",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-06-01 16:48:34",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Nicole Benoit",
            "StageName": "Qualification",
            "CloseDate": "2026-07-01",
            "AccountId": "001OF00000b2ciDYAQ",
            "Description": "",
            "Contact__c": "003OF00000XP3FpYAL",
            "OwnerId": "005OF000002YlL7YAK",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:35",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006OF00000bqyAtYAI",
            "success": true,
            "errors": []
        },
        "oppId": "006OF00000bqyAtYAI"
    }
}
{
    "timestamp": "2026-06-01 16:48:35",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000bqyAtYAI",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Contact_1__c": "003OF00000XP3FpYAL",
            "Meeting_Date_Time__c": "2026-06-01T16:48:35Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 19
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:36",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XOmi3YAD",
        "savedOppId": "006OF00000bqyAtYAI",
        "expectedOppId": "006OF00000bqyAtYAI"
    }
}
{
    "timestamp": "2026-06-01 16:48:36",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XOmi3YAD",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XOmi3YAD",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-01 16:48:36",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": []
    }
}
{
    "timestamp": "2026-06-01 16:48:36",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-01 16:48:36",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-01 16:48:36",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000bqyAtYAI",
        "VisitId": "a03OF00000XOmi3YAD",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": []
    }
}
{
    "timestamp": "2026-06-02 19:41:06",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:41:08",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:41:08",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:41:22",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:41:24",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:41:24",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:41:39",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:41:41",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:41:41",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:41:59",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:42:01",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:42:01",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:42:20",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:42:22",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:42:22",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:42:51",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:42:53",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:42:53",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:43:32",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:43:33",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:43:33",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:44:22",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:44:23",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:44:23",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:45:16",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:45:18",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:45:18",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:46:34",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:46:37",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:46:37",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:48:23",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:48:25",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:48:25",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:49:46",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:49:48",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:49:48",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:50:16",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:50:17",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:50:17",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:52:28",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:52:29",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:52:29",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-02 19:53:42",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-02 19:53:44",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.02",
            "VisitTime": 2176.28125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-02 19:53:44",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-05 14:44:08",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-05 14:44:10",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Démo",
            "LastName": " ",
            "Email": "immersioninternal@gmail.com",
            "Job": " "
        },
        "Clients": [
            {
                "FirstName": "florence",
                "LastName": "Letarte",
                "Email": "letarte.florence@videotron.ca",
                "Phone": "5813095827",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.05",
            "VisitTime": 2294.26220703125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-05 14:44:10",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-05 14:44:10",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-05 14:44:10",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 14:44:10",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "immersioninternal@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:44:10",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": null
    }
}
{
    "timestamp": "2026-06-05 14:44: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 ('letarte.florence@videotron.ca') OR Phone IN ('5813095827'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "letarte.florence@videotron.ca"
        ],
        "phones": [
            "5813095827"
        ]
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('letarte.florence@videotron.ca') OR Phone IN ('5813095827'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XasobYAB",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XasobYAB'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000c3UACYA2",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000c3UACYA2",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000c3UACYA2"
    }
}
{
    "timestamp": "2026-06-05 14:44:11",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000c3UACYA2",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "florence",
                "LastName": "Letarte",
                "Email": "letarte.florence@videotron.ca",
                "Phone": "5813095827",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c3UACYA2",
            "Meeting_Date_Time__c": "2026-06-05T14:44:12Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 39
        }
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000Xb402YAB",
        "savedOppId": "006OF00000c3UACYA2",
        "expectedOppId": "006OF00000c3UACYA2"
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000Xb402YAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000Xb402YAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "353_Le18Juillet-2",
            "355_Le18Juillet-2",
            "1320_Le21Mars-1"
        ]
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-05 14:44:12",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-05 14:44:13",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "353_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 14:44:14",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "355_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 14:44:14",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1320_Le21Mars-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 14:44:15",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c3UACYA2",
        "VisitId": "a03OF00000Xb402YAB",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "353_Le18Juillet-2",
                "id": "a01OF00000bGgPRYA0",
                "http": 201
            },
            {
                "ok": true,
                "unit": "355_Le18Juillet-2",
                "id": "a01OF00000bGuCEYA0",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1320_Le21Mars-1",
                "id": "a01OF00000bGwVlYAK",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 14:48:51",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-05 14:48:53",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Nicole",
                "LastName": "Pomerleau",
                "Email": "nicpom74@gmail.com",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.05",
            "VisitTime": 2678.980224609375,
            "Pet": "",
            "UnitsSeeked": [
                "3.5 avec bureau",
                "4.5"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:53",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "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 ('nicpom74@gmail.com'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "nicpom74@gmail.com"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('nicpom74@gmail.com'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000ORhUXYA1",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000ORhUXYA1'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR vide, fallback Contact__c",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via Contact__c",
    "context": {
        "contactId": "003OF00000ORhUXYA1",
        "soql": "SELECT Id, Building_Group__c\r\n                 FROM Opportunity\r\n                 WHERE Contact__c = '003OF00000ORhUXYA1'\r\n                 AND IsClosed = false\r\n                 AND CreatedDate = LAST_N_DAYS:365\r\n                 ORDER BY CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - Contact__c trouvée",
    "context": {
        "oppId": "006OF00000Rcj32YAB",
        "foundGroupId": null
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "ℹ️ Groupe d'immeuble différent — nouveau doublon autorisé",
    "context": {
        "oppId": "006OF00000Rcj32YAB",
        "existingGroupId": null,
        "incomingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Nicole",
                "LastName": "Pomerleau",
                "Email": "nicpom74@gmail.com",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 14:48:54",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "nicpom74@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000ORhUXYA1"
                    },
                    "Id": "003OF00000ORhUXYA1",
                    "AccountId": "001OF00000QnyldYAB",
                    "Email": "nicpom74@gmail.com",
                    "Phone": null,
                    "MobilePhone": "5142353831",
                    "FirstName": "Nicole",
                    "LastName": "Pomerleau"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "nicpom74@gmail.com",
        "phone": "",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000ORhUXYA1"
            },
            "Id": "003OF00000ORhUXYA1",
            "AccountId": "001OF00000QnyldYAB",
            "Email": "nicpom74@gmail.com",
            "Phone": null,
            "MobilePhone": "5142353831",
            "FirstName": "Nicole",
            "LastName": "Pomerleau"
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000QnyldYAB"
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "nicpom74@gmail.com",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000ORhUXYA1"
                    },
                    "Id": "003OF00000ORhUXYA1",
                    "AccountId": "001OF00000QnyldYAB",
                    "Email": "nicpom74@gmail.com",
                    "Phone": null,
                    "MobilePhone": "5142353831",
                    "FirstName": "Nicole",
                    "LastName": "Pomerleau"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "nicpom74@gmail.com",
        "phone": "",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000ORhUXYA1"
            },
            "Id": "003OF00000ORhUXYA1",
            "AccountId": "001OF00000QnyldYAB",
            "Email": "nicpom74@gmail.com",
            "Phone": null,
            "MobilePhone": "5142353831",
            "FirstName": "Nicole",
            "LastName": "Pomerleau"
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000ORhUXYA1",
        "accountId": "001OF00000QnyldYAB"
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000QnyldYAB",
        "contactIds": [
            "003OF00000ORhUXYA1"
        ]
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "Nicole Pomerleau",
            "StageName": "Qualification",
            "CloseDate": "2026-07-05",
            "AccountId": "001OF00000QnyldYAB",
            "Description": "",
            "Contact__c": "003OF00000ORhUXYA1",
            "OwnerId": "005OF000002YlL7YAK",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000ORhUXYA1"
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000ORhUXYA1",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-06-05 14:48: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 = '003OF00000ORhUXYA1'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 14:48:55",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:48: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 = '003OF00000ORhUXYA1'\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-06-05 14:48:56",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - résultat",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:56",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - aucune opp existante trouvée",
    "context": {
        "contactId": "003OF00000ORhUXYA1"
    }
}
{
    "timestamp": "2026-06-05 14:48:56",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": null
    }
}
{
    "timestamp": "2026-06-05 14:48:56",
    "message": "DEBUG create_all - aucune opp existante, création Opportunity",
    "context": {
        "oppPayload": {
            "Name": "Nicole Pomerleau",
            "StageName": "Qualification",
            "CloseDate": "2026-07-05",
            "AccountId": "001OF00000QnyldYAB",
            "Description": "",
            "Contact__c": "003OF00000ORhUXYA1",
            "OwnerId": "005OF000002YlL7YAK",
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:57",
    "message": "DEBUG create_all - réponse création Opportunity",
    "context": {
        "http": 201,
        "resp": {
            "id": "006OF00000c3npVYAQ",
            "success": true,
            "errors": []
        },
        "oppId": "006OF00000c3npVYAQ"
    }
}
{
    "timestamp": "2026-06-05 14:48:57",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c3npVYAQ",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Contact_1__c": "003OF00000ORhUXYA1",
            "Meeting_Date_Time__c": "2026-06-05T14:48:57Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 45
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:58",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000Xb5FRYAZ",
        "savedOppId": "006OF00000c3npVYAQ",
        "expectedOppId": "006OF00000c3npVYAQ"
    }
}
{
    "timestamp": "2026-06-05 14:48:58",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000Xb5FRYAZ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000Xb5FRYAZ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-05 14:48:58",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "804_Le18Juillet-1",
            "828_Le18Juillet-1",
            "502_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-05 14:48:58",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-05 14:48:58",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-05 14:48:58",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "804_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 14:48:59",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "828_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 14:48:59",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "502_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 14:49:00",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c3npVYAQ",
        "VisitId": "a03OF00000Xb5FRYAZ",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "804_Le18Juillet-1",
                "id": "a01OF00000bGnQtYAK",
                "http": 201
            },
            {
                "ok": true,
                "unit": "828_Le18Juillet-1",
                "id": "a01OF00000bGlwxYAC",
                "http": 201
            },
            {
                "ok": true,
                "unit": "502_Le18Juillet-1",
                "id": "a01OF00000bGSnqYAG",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 17:23:02",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-05 17:23:04",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "sylvie",
                "LastName": "coulombe",
                "Email": "sy2coulombe@hotmail.ca",
                "Phone": "4182648817",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.05",
            "VisitTime": 1819.832763671875,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-05 17:23:04",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-05 17:23:04",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-06-05 17:23:04",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 17:23:04",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-05 17:23:04",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-05 17:23:04",
    "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 ('sy2coulombe@hotmail.ca') OR Phone IN ('4182648817'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "sy2coulombe@hotmail.ca"
        ],
        "phones": [
            "4182648817"
        ]
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('sy2coulombe@hotmail.ca') OR Phone IN ('4182648817'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XbC42YAF",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XbC42YAF'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000c49ObYAI",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000c49ObYAI",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 17:23:05",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000c49ObYAI"
    }
}
{
    "timestamp": "2026-06-05 17:23:06",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000c49ObYAI",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-05 17:23:06",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "sylvie",
                "LastName": "coulombe",
                "Email": "sy2coulombe@hotmail.ca",
                "Phone": "4182648817",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 17:23:06",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c49ObYAI",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-06-05T17:23:06Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 31
        }
    }
}
{
    "timestamp": "2026-06-05 17:23:06",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XbKROYA3",
        "savedOppId": "006OF00000c49ObYAI",
        "expectedOppId": "006OF00000c49ObYAI"
    }
}
{
    "timestamp": "2026-06-05 17:23:06",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XbKROYA3",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XbKROYA3",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-05 17:23:06",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "603_Le18Juillet-1",
            "506_Le18Juillet-1",
            "1126_Le18Juillet-1",
            "512_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-05 17:23:07",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-05 17:23:07",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-05 17:23:07",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "603_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 17:23:07",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "506_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 17:23:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1126_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 17:23:09",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "512_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 17:23:09",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c49ObYAI",
        "VisitId": "a03OF00000XbKROYA3",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "603_Le18Juillet-1",
                "id": "a01OF00000bHK6iYAG",
                "http": 201
            },
            {
                "ok": true,
                "unit": "506_Le18Juillet-1",
                "id": "a01OF00000bGPWdYAO",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1126_Le18Juillet-1",
                "id": "a01OF00000bHS4DYAW",
                "http": 201
            },
            {
                "ok": true,
                "unit": "512_Le18Juillet-1",
                "id": "a01OF00000bHGG0YAO",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 19:16:41",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-05 19:16:43",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Francine",
                "LastName": "Laforce",
                "Email": "mfgalipeau@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.05",
            "VisitTime": 2570.939208984375,
            "Pet": "",
            "UnitsSeeked": [
                "3.5 avec bureau",
                "4.5"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-05 19:16:43",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-05 19:16:43",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-06-05 19:16:43",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 19:16:43",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-05 19:16:43",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-06-05 19:16:43",
    "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 ('mfgalipeau@hotmail.com'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "mfgalipeau@hotmail.com"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('mfgalipeau@hotmail.com'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XbYisYAF",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XbYisYAF'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000c4V7OYAU",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000c4V7OYAU",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000c4V7OYAU"
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000c4V7OYAU",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Francine",
                "LastName": "Laforce",
                "Email": "mfgalipeau@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-05 19:16:44",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c4V7OYAU",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Meeting_Date_Time__c": "2026-06-05T19:16:44Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 43
        }
    }
}
{
    "timestamp": "2026-06-05 19:16:45",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XbrQYYAZ",
        "savedOppId": "006OF00000c4V7OYAU",
        "expectedOppId": "006OF00000c4V7OYAU"
    }
}
{
    "timestamp": "2026-06-05 19:16:45",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XbrQYYAZ",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XbrQYYAZ",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-05 19:16:45",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "505_Le18Juillet-1",
            "1106_Le18Juillet-1",
            "522_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-05 19:16:45",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-05 19:16:45",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-05 19:16:46",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "505_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 19:16:46",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1106_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 19:16:47",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "522_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-05 19:16:47",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c4V7OYAU",
        "VisitId": "a03OF00000XbrQYYAZ",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "505_Le18Juillet-1",
                "id": "a01OF00000bHWvuYAG",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1106_Le18Juillet-1",
                "id": "a01OF00000bHd2tYAC",
                "http": 201
            },
            {
                "ok": true,
                "unit": "522_Le18Juillet-1",
                "id": "a01OF00000bHpnCYAS",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-06 15:43:53",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Talita",
                "LastName": "Dias",
                "Email": "talitafkdias@gmail.com",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 2,
        "GeneralInfo": {
            "Date": "2026.06.06",
            "VisitTime": 4099.68408203125,
            "Pet": "",
            "UnitsSeeked": [
                "3.5 avec bureau"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "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 ('talitafkdias@gmail.com'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "talitafkdias@gmail.com"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-06 15:43:55",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('talitafkdias@gmail.com'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XdSpVYAV",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XdSpVYAV'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000c6RUIYA2",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000c6RUIYA2",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000c6RUIYA2"
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000c6RUIYA2",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Talita",
                "LastName": "Dias",
                "Email": "talitafkdias@gmail.com",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-06 15:43:56",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c6RUIYA2",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Meeting_Date_Time__c": "2026-06-06T15:43:56Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 69
        }
    }
}
{
    "timestamp": "2026-06-06 15:43:57",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XdfzZYAR",
        "savedOppId": "006OF00000c6RUIYA2",
        "expectedOppId": "006OF00000c6RUIYA2"
    }
}
{
    "timestamp": "2026-06-06 15:43:57",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XdfzZYAR",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XdfzZYAR",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-06 15:43:57",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "355_Le18Juillet-2",
            "1320_Le21Mars-1"
        ]
    }
}
{
    "timestamp": "2026-06-06 15:43:57",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-06 15:43:57",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-06 15:43:57",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "355_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-06 15:43:58",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1320_Le21Mars-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-06 15:43:58",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c6RUIYA2",
        "VisitId": "a03OF00000XdfzZYAR",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "355_Le18Juillet-2",
                "id": "a01OF00000bJtQBYA0",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1320_Le21Mars-1",
                "id": "a01OF00000bJxTkYAK",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-07 19:33:56",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Loïc ",
            "LastName": "Hamika",
            "Email": "loic.hamika@trudel.ca",
            "Job": "Conseiller à la location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "Martin",
                "LastName": "Robitaille",
                "Email": "martinrobit@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.07",
            "VisitTime": 1680.6512451171875,
            "Pet": "",
            "UnitsSeeked": [
                "3.5 avec bureau",
                "4.5"
            ],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "loic.hamika@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000002YlL7YAK"
                    },
                    "Id": "005OF000002YlL7YAK"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000002YlL7YAK"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "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 ('martinrobit@hotmail.com'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "martinrobit@hotmail.com"
        ],
        "phones": []
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('martinrobit@hotmail.com'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XfAwdYAF",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XfAwdYAF'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000c86LpYAI",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000c86LpYAI",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-07 19:33:58",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000c86LpYAI"
    }
}
{
    "timestamp": "2026-06-07 19:33:59",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000c86LpYAI",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-07 19:33:59",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "Martin",
                "LastName": "Robitaille",
                "Email": "martinrobit@hotmail.com",
                "Phone": "",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-07 19:33:59",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c86LpYAI",
            "Assign_to__c": "005OF000002YlL7YAK",
            "Meeting_Date_Time__c": "2026-06-07T19:33:59Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 29
        }
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000Xf9dvYAB",
        "savedOppId": "006OF00000c86LpYAI",
        "expectedOppId": "006OF00000c86LpYAI"
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000Xf9dvYAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000Xf9dvYAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "528_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "528_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-07 19:34:00",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c86LpYAI",
        "VisitId": "a03OF00000Xf9dvYAB",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "528_Le18Juillet-1",
                "id": "a01OF00000bLhMaYAK",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-09 14:49:05",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-09 14:49:07",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "daniel",
                "LastName": "lelievre",
                "Email": "gdelelievre@outlook.com",
                "Phone": "4186662785",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.09",
            "VisitTime": 2885.39501953125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:07",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-09 14:49: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 ('gdelelievre@outlook.com') OR Phone IN ('4186662785'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "gdelelievre@outlook.com"
        ],
        "phones": [
            "4186662785"
        ]
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('gdelelievre@outlook.com') OR Phone IN ('4186662785'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - aucun Contact trouvé",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "daniel",
                "LastName": "lelievre",
                "Email": "gdelelievre@outlook.com",
                "Phone": "4186662785",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-09 14:49:08",
    "message": "DEBUG create_all - entrée dans le flow classique",
    "context": []
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "gdelelievre@outlook.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by phone",
    "context": {
        "phone_raw": "4186662785",
        "phone_sanitized": "4186662785",
        "phone_last10": "4186662785",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RP6FZYA1"
                    },
                    "Id": "003OF00000RP6FZYA1",
                    "AccountId": "001OF00000UEJj6YAH",
                    "Email": "gdlelievre@outlook.com",
                    "Phone": null,
                    "MobilePhone": "4186662785",
                    "FirstName": "Daniel",
                    "LastName": "Lelièvre"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG upsert_contacts_with_shared_family_account - primary contact lookup",
    "context": {
        "email": "gdelelievre@outlook.com",
        "phone": "4186662785",
        "existingPrimaryContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RP6FZYA1"
            },
            "Id": "003OF00000RP6FZYA1",
            "AccountId": "001OF00000UEJj6YAH",
            "Email": "gdlelievre@outlook.com",
            "Phone": null,
            "MobilePhone": "4186662785",
            "FirstName": "Daniel",
            "LastName": "Lelièvre"
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing family account reused",
    "context": {
        "accountId": "001OF00000UEJj6YAH"
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by email",
    "context": {
        "email": "gdelelievre@outlook.com",
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG sf_find_contact_by_email_or_phone - search by phone",
    "context": {
        "phone_raw": "4186662785",
        "phone_sanitized": "4186662785",
        "phone_last10": "4186662785",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "Contact",
                        "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RP6FZYA1"
                    },
                    "Id": "003OF00000RP6FZYA1",
                    "AccountId": "001OF00000UEJj6YAH",
                    "Email": "gdlelievre@outlook.com",
                    "Phone": null,
                    "MobilePhone": "4186662785",
                    "FirstName": "Daniel",
                    "LastName": "Lelièvre"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG upsert_contacts_with_shared_family_account - contact lookup",
    "context": {
        "email": "gdelelievre@outlook.com",
        "phone": "4186662785",
        "existingContact": {
            "attributes": {
                "type": "Contact",
                "url": "\/services\/data\/v62.0\/sobjects\/Contact\/003OF00000RP6FZYA1"
            },
            "Id": "003OF00000RP6FZYA1",
            "AccountId": "001OF00000UEJj6YAH",
            "Email": "gdlelievre@outlook.com",
            "Phone": null,
            "MobilePhone": "4186662785",
            "FirstName": "Daniel",
            "LastName": "Lelièvre"
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG upsert_contacts_with_shared_family_account - existing contact reused",
    "context": {
        "contactId": "003OF00000RP6FZYA1",
        "accountId": "001OF00000UEJj6YAH"
    }
}
{
    "timestamp": "2026-06-09 14:49:09",
    "message": "DEBUG create_all - résultat upsert family account\/contact",
    "context": {
        "accountMainId": "001OF00000UEJj6YAH",
        "contactIds": [
            "003OF00000RP6FZYA1"
        ]
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "message": "DEBUG create_all - oppPayload avant recherche d'opp existante",
    "context": {
        "oppPayload": {
            "Name": "daniel lelievre",
            "StageName": "Qualification",
            "CloseDate": "2026-07-09",
            "AccountId": "001OF00000UEJj6YAH",
            "Description": "",
            "Contact__c": "003OF00000RP6FZYA1",
            "OwnerId": "005OF000004npwjYAA",
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG",
            "RecordTypeId": "0128a000001CIA1AAO"
        },
        "contactMainId": "003OF00000RP6FZYA1"
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - paramètres",
    "context": {
        "contactId": "003OF00000RP6FZYA1",
        "buildingsPicklist": null,
        "buildingGroupAccountId": "02iOF000004UAyvYAG",
        "days": 180,
        "whereVariants": [
            "Opportunity.Building_Group__c = '02iOF000004UAyvYAG'",
            "Id != null"
        ]
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "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 = '003OF00000RP6FZYA1'\r\n                 AND Opportunity.IsClosed = false\r\n                 AND Opportunity.CreatedDate = LAST_N_DAYS:180\r\n                 AND Opportunity.Building_Group__c = '02iOF000004UAyvYAG'\r\n                 ORDER BY Opportunity.CreatedDate DESC\r\n                 LIMIT 1"
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "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\/00KOF00000MWUvx2AH"
                    },
                    "OpportunityId": "006OF00000VOP3UYAX",
                    "Opportunity": {
                        "attributes": {
                            "type": "Opportunity",
                            "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000VOP3UYAX"
                        },
                        "Id": "006OF00000VOP3UYAX",
                        "Name": "Daniel Lelièvre",
                        "StageName": "On Hold",
                        "CreatedDate": "2025-12-16T19:30:15.000+0000"
                    }
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "message": "DEBUG find_existing_open_opportunity_for_contact_and_building - opp existante retenue",
    "context": {
        "oppId": "006OF00000VOP3UYAX",
        "record": {
            "attributes": {
                "type": "OpportunityContactRole",
                "url": "\/services\/data\/v62.0\/sobjects\/OpportunityContactRole\/00KOF00000MWUvx2AH"
            },
            "OpportunityId": "006OF00000VOP3UYAX",
            "Opportunity": {
                "attributes": {
                    "type": "Opportunity",
                    "url": "\/services\/data\/v62.0\/sobjects\/Opportunity\/006OF00000VOP3UYAX"
                },
                "Id": "006OF00000VOP3UYAX",
                "Name": "Daniel Lelièvre",
                "StageName": "On Hold",
                "CreatedDate": "2025-12-16T19:30:15.000+0000"
            }
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "message": "DEBUG create_all - existingOppId",
    "context": {
        "existingOppId": "006OF00000VOP3UYAX"
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "message": "✅ Existing Opportunity found (avoid duplicate)",
    "context": {
        "oppId": "006OF00000VOP3UYAX",
        "contactId": "003OF00000RP6FZYA1",
        "Buildings__c": null
    }
}
{
    "timestamp": "2026-06-09 14:49:10",
    "message": "✅ Opp existante — bâtiment et groupe mis à jour",
    "context": {
        "oppId": "006OF00000VOP3UYAX",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:11",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000VOP3UYAX",
            "Assign_to__c": "005OF000004npwjYAA",
            "Contact_1__c": "003OF00000RP6FZYA1",
            "Meeting_Date_Time__c": "2026-06-09T14:49:11Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 49
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:11",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XjssTYAR",
        "savedOppId": "006OF00000VOP3UYAX",
        "expectedOppId": "006OF00000VOP3UYAX"
    }
}
{
    "timestamp": "2026-06-09 14:49:11",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XjssTYAR",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XjssTYAR",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-09 14:49:11",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "256_Le18Juillet-2",
            "1106_Le18Juillet-1",
            "1109_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-09 14:49:12",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-09 14:49:12",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-09 14:49:12",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "256_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-09 14:49:13",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1106_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-09 14:49:13",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1109_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-09 14:49:14",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000VOP3UYAX",
        "VisitId": "a03OF00000XjssTYAR",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "256_Le18Juillet-2",
                "id": "a01OF00000bR1ijYAC",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1106_Le18Juillet-1",
                "id": "a01OF00000bQyXzYAK",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1109_Le18Juillet-1",
                "id": "a01OF00000bR8XFYA0",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-09 19:45:40",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-09 19:45:42",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "diane",
                "LastName": "tremblay",
                "Email": "francodiane1471@gmail.com",
                "Phone": "4184545429",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.09",
            "VisitTime": 2022.128662109375,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-09 19:45:42",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-09 19:45:42",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-1"
    }
}
{
    "timestamp": "2026-06-09 19:45:42",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-1",
        "residentialBuildingAssetId": "02iOF000004UB3oYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-09 19:45:42",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-09 19:45:42",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-09 19:45:42",
    "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 ('francodiane1471@gmail.com') OR Phone IN ('4184545429'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "francodiane1471@gmail.com"
        ],
        "phones": [
            "4184545429"
        ]
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('francodiane1471@gmail.com') OR Phone IN ('4184545429'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XdivqYAB",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XdivqYAB'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000c6j1NYAQ",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000c6j1NYAQ",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000c6j1NYAQ"
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000c6j1NYAQ",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3oYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "diane",
                "LastName": "tremblay",
                "Email": "francodiane1471@gmail.com",
                "Phone": "4184545429",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-09 19:45:43",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000c6j1NYAQ",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-06-09T19:45:43Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 34
        }
    }
}
{
    "timestamp": "2026-06-09 19:45:44",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XkfupYAB",
        "savedOppId": "006OF00000c6j1NYAQ",
        "expectedOppId": "006OF00000c6j1NYAQ"
    }
}
{
    "timestamp": "2026-06-09 19:45:44",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XkfupYAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XkfupYAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-09 19:45:44",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "530_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-09 19:45:44",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-09 19:45:44",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-09 19:45:45",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "530_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-09 19:45:45",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000c6j1NYAQ",
        "VisitId": "a03OF00000XkfupYAB",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "530_Le18Juillet-1",
                "id": "a01OF00000bSBcjYAG",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:37",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-11 15:52:37",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "carmen",
                "LastName": "Joseph",
                "Email": "carmen.joseph18@gmail.com",
                "Phone": "5819997618",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.11",
            "VisitTime": 2857.27392578125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "carmen",
                "LastName": "Joseph",
                "Email": "carmen.joseph18@gmail.com",
                "Phone": "5819997618",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.11",
            "VisitTime": 2857.27392578125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "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 ('carmen.joseph18@gmail.com') OR Phone IN ('5819997618'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "carmen.joseph18@gmail.com"
        ],
        "phones": [
            "5819997618"
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('carmen.joseph18@gmail.com') OR Phone IN ('5819997618'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "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 ('carmen.joseph18@gmail.com') OR Phone IN ('5819997618'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "carmen.joseph18@gmail.com"
        ],
        "phones": [
            "5819997618"
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XqiqIYAR",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XqiqIYAR'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-11 15:52:39",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('carmen.joseph18@gmail.com') OR Phone IN ('5819997618'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000cJKegYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XqiqIYAR",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XqiqIYAR'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000cJKegYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "carmen",
                "LastName": "Joseph",
                "Email": "carmen.joseph18@gmail.com",
                "Phone": "5819997618",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000cJKegYAG",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-06-11T15:52:40Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 48
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "carmen",
                "LastName": "Joseph",
                "Email": "carmen.joseph18@gmail.com",
                "Phone": "5819997618",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:40",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000cJKegYAG",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-06-11T15:52:40Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 48
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XquvzYAB",
        "savedOppId": "006OF00000cJKegYAG",
        "expectedOppId": "006OF00000cJKegYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XquvzYAB",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XquvzYAB",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1462_Le18Juillet-2",
            "1358_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000Xr8fZYAR",
        "savedOppId": "006OF00000cJKegYAG",
        "expectedOppId": "006OF00000cJKegYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000Xr8fZYAR",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000Xr8fZYAR",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1462_Le18Juillet-2",
            "1358_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1462_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-11 15:52:41",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1462_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-11 15:52:42",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1358_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-11 15:52:42",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1358_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-11 15:52:42",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000cJKegYAG",
        "VisitId": "a03OF00000XquvzYAB",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1462_Le18Juillet-2",
                "id": "a01OF00000bYyxMYAS",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1358_Le18Juillet-2",
                "id": "a01OF00000bZCfJYAW",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:42",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000cJKegYAG",
        "VisitId": "a03OF00000Xr8fZYAR",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1462_Le18Juillet-2",
                "id": "a01OF00000bYthXYAS",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1358_Le18Juillet-2",
                "id": "a01OF00000bZ1K7YAK",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "carmen",
                "LastName": "Joseph",
                "Email": "carmen.joseph18@gmail.com",
                "Phone": "5819997618",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.11",
            "VisitTime": 2857.27392578125,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "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 ('carmen.joseph18@gmail.com') OR Phone IN ('5819997618'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "carmen.joseph18@gmail.com"
        ],
        "phones": [
            "5819997618"
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('carmen.joseph18@gmail.com') OR Phone IN ('5819997618'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000XqiqIYAR",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000XqiqIYAR'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000cJKegYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000cJKegYAG",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "carmen",
                "LastName": "Joseph",
                "Email": "carmen.joseph18@gmail.com",
                "Phone": "5819997618",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:43",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000cJKegYAG",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-06-11T15:52:43Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 48
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:44",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000Xr5rOYAR",
        "savedOppId": "006OF00000cJKegYAG",
        "expectedOppId": "006OF00000cJKegYAG"
    }
}
{
    "timestamp": "2026-06-11 15:52:44",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000Xr5rOYAR",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000Xr5rOYAR",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-11 15:52:44",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1462_Le18Juillet-2",
            "1358_Le18Juillet-2"
        ]
    }
}
{
    "timestamp": "2026-06-11 15:52:44",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-11 15:52:44",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-11 15:52:45",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1462_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-11 15:52:45",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1358_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-11 15:52:45",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000cJKegYAG",
        "VisitId": "a03OF00000Xr5rOYAR",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1462_Le18Juillet-2",
                "id": "a01OF00000bZ5kMYAS",
                "http": 201
            },
            {
                "ok": true,
                "unit": "1358_Le18Juillet-2",
                "id": "a01OF00000bYvY2YAK",
                "http": 201
            }
        ]
    }
}
{
    "timestamp": "2026-06-12 16:01:21",
    "message": "♻️ Token valide (cache)"
}
{
    "timestamp": "2026-06-12 16:01:22",
    "message": "DEBUG create_all - payload reçu",
    "context": {
        "Agent": {
            "FirstName": "Mathilde",
            "LastName": "Geffroy",
            "Email": "Mathilde.geffroy@trudel.ca",
            "Job": "Conseillère location résidentielle"
        },
        "Clients": [
            {
                "FirstName": "gilles",
                "LastName": "lapointe",
                "Email": "g.lap@videotron.ca",
                "Phone": "4182657648",
                "Post": ""
            }
        ],
        "Projects_count": 1,
        "GeneralInfo": {
            "Date": "2026.06.12",
            "VisitTime": 3031.678466796875,
            "Pet": "",
            "UnitsSeeked": [],
            "Comment": ""
        }
    }
}
{
    "timestamp": "2026-06-12 16:01:22",
    "message": "DEBUG create_all - meetingDateTimeIso calculé",
    "context": {
        "MeetingDateTime_input": null,
        "meetingDateTimeIso": null
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "✅ lookup_asset_by_building_name - trouvé (exact)",
    "context": {
        "assetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG",
        "building": "Le18Juillet-2"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG create_all - bâtiment résolu",
    "context": {
        "residentialBuildingName": "Le18Juillet-2",
        "residentialBuildingAssetId": "02iOF000004UB3nYAG",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG create_all - recherche ownerId via email agent",
    "context": {
        "agentEmail": "Mathilde.geffroy@trudel.ca",
        "http": 200,
        "res": {
            "totalSize": 1,
            "done": true,
            "records": [
                {
                    "attributes": {
                        "type": "User",
                        "url": "\/services\/data\/v62.0\/sobjects\/User\/005OF000004npwjYAA"
                    },
                    "Id": "005OF000004npwjYAA"
                }
            ]
        }
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG create_all - ownerId retenu",
    "context": {
        "ownerId": "005OF000004npwjYAA"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "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 ('g.lap@videotron.ca') OR Phone IN ('4182657648'))\r\n             ORDER BY CreatedDate DESC\r\n             LIMIT 1",
        "emails": [
            "g.lap@videotron.ca"
        ],
        "phones": [
            "4182657648"
        ]
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG find_existing_lead_for_clients - résultat requête Lead",
    "context": {
        "http": 200,
        "res": {
            "totalSize": 0,
            "done": true,
            "records": []
        }
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG find_existing_lead_for_clients - lead retenu",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG create_all - lead après recherche",
    "context": {
        "lead": null
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche Contact",
    "context": {
        "soql": "SELECT Id FROM Contact\r\n                    WHERE (Email IN ('g.lap@videotron.ca') OR Phone IN ('4182657648'))\r\n                    ORDER BY CreatedDate DESC LIMIT 1"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - recherche via OCR",
    "context": {
        "contactId": "003OF00000Xu5LYYAZ",
        "soql": "SELECT OpportunityId, Opportunity.Building_Group__c\r\n                FROM OpportunityContactRole\r\n                WHERE ContactId = '003OF00000Xu5LYYAZ'\r\n                AND Opportunity.IsClosed = false\r\n                AND Opportunity.CreatedDate = LAST_N_DAYS:365\r\n                ORDER BY Opportunity.CreatedDate DESC\r\n                LIMIT 1"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "DEBUG find_existing_opportunity_by_client_email_or_phone - OCR trouvée",
    "context": {
        "oppId": "006OF00000cMYYEYA4",
        "foundGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "✅ Groupe d'immeuble identique — Opportunity réutilisée",
    "context": {
        "oppId": "006OF00000cMYYEYA4",
        "buildingGroupId": "02iOF000004UAyvYAG"
    }
}
{
    "timestamp": "2026-06-12 16:01:23",
    "message": "✅ Dédup Opportunity trouvée par email\/téléphone — réutilisation",
    "context": {
        "oppId": "006OF00000cMYYEYA4"
    }
}
{
    "timestamp": "2026-06-12 16:01:24",
    "message": "✅ Opportunity mise à jour avec bâtiment\/groupe",
    "context": {
        "oppId": "006OF00000cMYYEYA4",
        "payload": {
            "Residential_Building__c": "02iOF000004UB3nYAG",
            "Building_Group__c": "02iOF000004UAyvYAG"
        }
    }
}
{
    "timestamp": "2026-06-12 16:01:24",
    "message": "DEBUG create_all - aucun lead trouvé, passage direct au flow classique",
    "context": {
        "clients": [
            {
                "FirstName": "gilles",
                "LastName": "lapointe",
                "Email": "g.lap@videotron.ca",
                "Phone": "4182657648",
                "Post": ""
            }
        ]
    }
}
{
    "timestamp": "2026-06-12 16:01:24",
    "message": "DEBUG create_all - visitPayload final",
    "context": {
        "visitPayload": {
            "Opportunity__c": "006OF00000cMYYEYA4",
            "Assign_to__c": "005OF000004npwjYAA",
            "Meeting_Date_Time__c": "2026-06-12T16:01:24Z",
            "Meeting_Notes__c": "",
            "Visit_Duration__c": 51
        }
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG upsert_visit - vérification Opportunity__c après création",
    "context": {
        "visitId": "a03OF00000XuOHaYAN",
        "savedOppId": "006OF00000cMYYEYA4",
        "expectedOppId": "006OF00000cMYYEYA4"
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG create_all - résultat upsert Visit__c",
    "context": {
        "okVisit": true,
        "visitMode": "create",
        "visitId": "a03OF00000XuOHaYAN",
        "visitHttp": 201,
        "visitRes": {
            "id": "a03OF00000XuOHaYAN",
            "success": true,
            "errors": []
        }
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG create_all - visitedUnits source finale",
    "context": {
        "visitedUnits": [
            "1058_Le18Juillet-2",
            "505_Le18Juillet-1"
        ]
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG create_all - defaultVURecordTypeId",
    "context": {
        "defaultVURecordTypeId": "0128a000000tkjXAAQ"
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG create_all - estimatesByUnit",
    "context": {
        "estimatesByUnit": []
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "1058_Le18Juillet-2",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-12 16:01:25",
    "message": "DEBUG create_visited_units_for_visit - Positive_Aspects analysis",
    "context": {
        "unit": "505_Le18Juillet-1",
        "requested": [],
        "allowed": [],
        "valid": [],
        "invalid": []
    }
}
{
    "timestamp": "2026-06-12 16:01:26",
    "message": "✅ create_all executed",
    "context": {
        "OpportunityId": "006OF00000cMYYEYA4",
        "VisitId": "a03OF00000XuOHaYAN",
        "VisitMode": "create",
        "LeadConversion": null,
        "VisitedUnits": [
            {
                "ok": true,
                "unit": "1058_Le18Juillet-2",
                "id": "a01OF00000bcNMUYA2",
                "http": 201
            },
            {
                "ok": true,
                "unit": "505_Le18Juillet-1",
                "id": "a01OF00000bcTBlYAM",
                "http": 201
            }
        ]
    }
}
