{
    "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-06-02 19:28:46",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:28:47",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:28:47",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:31:07",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:31:07",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:31:07",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:32:43",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:32:43",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:32:43",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:42:29",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:42:29",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:42:29",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:49:34",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:49:34",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:49:34",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:49:34",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:49:34",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:49:34",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:49:35",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:49:35",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:49:35",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:59:32",
    "message": "🔄 Refresh token"
}
{
    "timestamp": "2026-06-02 19:59:33",
    "message": "❌ OAuth refresh échoué — le refresh_token est peut-être révoqué (reset de mot de passe?). Réponse: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
{
    "timestamp": "2026-06-02 19:59:33",
    "message": "ERROR: OAuth error: {\"error\":\"unsupported_grant_type\",\"error_description\":\"grant type not supported\"}"
}
