[Feature] Salesforce: batch describe metadati, discovery parallela e fix scheduler External ID
- Salesforce Composite Batch API per describe SObject: le describe sono ora raggruppate in chunk da 25 e inviate come singole POST a /composite/batch, riducendo le chiamate API da N a ceil(N/25); per 200 SObject: da 201 a 9 chiamate. - Discovery entita' REST in parallelo: DiscoverEntitySummariesAsync e DiscoverEntitiesAsync avviate simultaneamente; la lista entita' diventa interattiva subito dopo le summaries, i dettagli completano in background con StateHasChanged() per aggiornare l'UI istantaneamente. - Fix scheduler - preservazione ExternalIdRelationshipsJson e DefaultValuesJson: in DataCoupler.razor.cs entrambi i blocchi di update profilo esistente (riattivazione profilo inattivo e sovrascrittura profilo attivo) omettevano questi campi nella copia, causandone l'azzeramento silenzioso ad ogni re-salvataggio. Ora entrambi i percorsi propagano correttamente i campi JSON. - Fix scheduler - esclusione campi sorgente External ID dal mapping normale: in ScheduledProfileExecutionService.TransformRecordForRest i campi sorgente usati nelle External ID Relationships venivano inclusi anche nel loop di field mapping standard, generando dati duplicati nell'entita' destinazione. Ora il comportamento e' allineato alla UI manuale (TransformRecordToRestEntity). - Aggiornata documentazione: README.md, AGENTS.md, copilot-instructions.md
This commit was merged in pull request #11.
This commit is contained in:
@@ -196,40 +196,126 @@ VALUES ('20260203000000_AddExternalIdRelationships', '9.0.0');
|
||||
|
||||
## 📊 Formato Dati Salesforce
|
||||
|
||||
### Esempio di Trasformazione
|
||||
### ⚠️ REGOLA IMPORTANTE: Formato Basato sull'Oggetto DESTINAZIONE
|
||||
|
||||
Il formato delle External ID Relationships dipende dal **tipo dell'oggetto DESTINAZIONE** (quello che stai creando/aggiornando), **NON** dal tipo dell'oggetto correlato:
|
||||
|
||||
#### **Se l'Oggetto DESTINAZIONE è CUSTOM** (es. `Sales_Quote__c`, `Custom_Order__c`):
|
||||
- ✅ Tutte le relazioni usano `__r`, sia per oggetti standard che custom
|
||||
- **Oggetto Standard**: `"Account__r": { "External_ID__c": "value" }`
|
||||
- **Oggetto Custom**: `"Custom_Company__r": { "External_ID__c": "value" }`
|
||||
|
||||
#### **Se l'Oggetto DESTINAZIONE è STANDARD** (es. `Opportunity`, `Contact`):
|
||||
- ✅ Solo oggetti custom correlati usano `__r`
|
||||
- **Oggetto Standard**: `"Account": { "External_ID__c": "value" }`
|
||||
- **Oggetto Custom**: `"Custom_Company__r": { "External_ID__c": "value" }`
|
||||
|
||||
### Esempi Pratici
|
||||
|
||||
#### Esempio 1: Destinazione CUSTOM → Relazione a Oggetto STANDARD
|
||||
|
||||
**Scenario**: Creo un record `Sales_Quote__c` collegato ad `Account` standard
|
||||
|
||||
**Configurazione:**
|
||||
- **Relationship Name**: `Account__r`
|
||||
- **Destination Object**: `Sales_Quote__c` (CUSTOM)
|
||||
- **Relationship Name**: `Account__r` ⚠️ **Usa __r anche se Account è standard!**
|
||||
- **Related Object**: `Account`
|
||||
- **External ID Field**: `Codice_ERP__c`
|
||||
- **Source Field**: `customerCode`
|
||||
|
||||
**Record Trasformato:**
|
||||
```json
|
||||
{
|
||||
"Name": "Quote 2024-001",
|
||||
"Quote_Code__c": "Q001",
|
||||
"Account__r": {
|
||||
"Codice_ERP__c": "C60000"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Esempio 2: Destinazione STANDARD → Relazione a Oggetto STANDARD
|
||||
|
||||
**Scenario**: Creo un record `Opportunity` collegato ad `Account`
|
||||
|
||||
**Configurazione:**
|
||||
- **Destination Object**: `Opportunity` (STANDARD)
|
||||
- **Relationship Name**: `Account` ⚠️ **NON usa __r**
|
||||
- **Related Object**: `Account`
|
||||
- **External ID Field**: `Country__c`
|
||||
- **Source Field**: `CountryCode` (dalla tabella sorgente)
|
||||
- **Source Field**: `CountryCode`
|
||||
|
||||
**Record Trasformato:**
|
||||
```json
|
||||
{
|
||||
"Name": "New Deal 2024",
|
||||
"StageName": "Prospecting",
|
||||
"Account": {
|
||||
"Country__c": "US"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Esempio 3: Destinazione CUSTOM → Relazione a Oggetto CUSTOM
|
||||
|
||||
**Configurazione:**
|
||||
- **Destination Object**: `Sales_Quote__c` (CUSTOM)
|
||||
- **Relationship Name**: `Custom_Territory__r`
|
||||
- **Related Object**: `Custom_Territory__c`
|
||||
- **External ID Field**: `Territory_Code__c`
|
||||
- **Source Field**: `territoryCode`
|
||||
|
||||
**Record Sorgente:**
|
||||
```json
|
||||
{
|
||||
"ProductName": "Widget A",
|
||||
"Price": 99.99,
|
||||
"CountryCode": "US"
|
||||
"quoteName": "Quote A",
|
||||
"territoryCode": "NORTH-WEST"
|
||||
}
|
||||
```
|
||||
|
||||
**Record Trasformato per Salesforce:**
|
||||
**Record Trasformato:**
|
||||
```json
|
||||
{
|
||||
"Name": "Widget A",
|
||||
"Price__c": 99.99,
|
||||
"Account__r": {
|
||||
"Country__c": "US"
|
||||
"Name": "Quote A",
|
||||
"Custom_Territory__r": {
|
||||
"Territory_Code__c": "NORTH-WEST"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Logica di Normalizzazione Automatica
|
||||
|
||||
Il sistema implementa il metodo `NormalizeRelationshipName()` che garantisce il formato corretto:
|
||||
|
||||
```csharp
|
||||
private string NormalizeRelationshipName(string relatedObjectName, bool isDestinationCustom)
|
||||
{
|
||||
if (isDestinationCustom)
|
||||
{
|
||||
// Destinazione CUSTOM: tutte le relazioni usano __r
|
||||
if (relatedObjectName.EndsWith("__c"))
|
||||
return relatedObjectName.Replace("__c", "__r"); // Custom_Obj__c → Custom_Obj__r
|
||||
else
|
||||
return relatedObjectName + "__r"; // Account → Account__r
|
||||
}
|
||||
else
|
||||
{
|
||||
// Destinazione STANDARD: solo oggetti custom usano __r
|
||||
if (relatedObjectName.EndsWith("__c"))
|
||||
return relatedObjectName.Replace("__c", "__r"); // Custom_Obj__c → Custom_Obj__r
|
||||
else
|
||||
return relatedObjectName; // Account → Account (no suffix)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Vantaggi External ID
|
||||
|
||||
1. **Nessun ID Salesforce Richiesto**: Non serve conoscere l'ID Salesforce dell'Account
|
||||
2. **Lookup Automatico**: Salesforce cerca automaticamente l'Account con `Country__c = "US"`
|
||||
3. **Upsert Intelligente**: Se non trova l'Account, può crearlo automaticamente (se configurato)
|
||||
2. **Lookup Automatico**: Salesforce cerca automaticamente l'oggetto correlato tramite External ID
|
||||
3. **Upsert Intelligente**: Se non trova l'oggetto, può crearlo automaticamente (se configurato)
|
||||
4. **Manutenzione Semplificata**: I codici esterni sono più stabili degli ID interni
|
||||
5. **Normalizzazione Automatica**: Il sistema corregge automaticamente i nomi quando carica profili salvati
|
||||
|
||||
## 🔄 Flusso Operativo
|
||||
|
||||
@@ -307,6 +393,14 @@ VALUES ('20260203000000_AddExternalIdRelationships', '9.0.0');
|
||||
- Solo dopo field mappings configurati (`fieldMappings.Any()`)
|
||||
- Migliora UX evitando confusione per altre API
|
||||
|
||||
5. **⭐ Normalizzazione Automatica RelationshipName (FIX CRITICO - 17 Feb 2026)**
|
||||
- **Problema Risolto**: Errore `"No such column 'Account' on sobject of type Sales_Quote__c"`
|
||||
- **Causa**: Il formato dipende dall'oggetto DESTINAZIONE, non dall'oggetto correlato
|
||||
- **Soluzione**: Metodo `NormalizeRelationshipName()` controlla tipo oggetto destinazione
|
||||
- **Funzionalità**: Corregge automaticamente i RelationshipName al caricamento profili
|
||||
- **Regola**: Se destinazione è custom → usa SEMPRE `__r` per tutte le relazioni
|
||||
- **Benefici**: Profili esistenti vengono corretti automaticamente senza intervento manuale
|
||||
|
||||
### Potenziali Estensioni Future
|
||||
|
||||
1. **Validazione Avanzata**: Verifica esistenza oggetto/campo su Salesforce prima di salvare
|
||||
@@ -319,6 +413,13 @@ VALUES ('20260203000000_AddExternalIdRelationships', '9.0.0');
|
||||
|
||||
### Errori Comuni
|
||||
|
||||
**⚠️ Errore: "No such column 'Account' on sobject of type Sales_Quote__c"**
|
||||
- **Causa**: RelationshipName incorretto per oggetto destinazione custom
|
||||
- **Spiegazione**: Quando l'oggetto DESTINAZIONE è custom (es. `Sales_Quote__c`), TUTTE le relazioni devono usare `__r`, anche per oggetti standard
|
||||
- **Soluzione AUTOMATICA**: ✅ Il sistema ora normalizza automaticamente i nomi delle relazioni
|
||||
- **Esempio**: Se destinazione è `Sales_Quote__c` e correlato è `Account` → usa `Account__r` (non `Account`)
|
||||
- **Fix Manuale**: Se usi profili vecchi, il sistema correggerà automaticamente al caricamento
|
||||
|
||||
**Errore: "External ID field not found"**
|
||||
- Causa: Campo External ID non esiste sull'oggetto Salesforce
|
||||
- Soluzione: Verificare che il campo sia configurato come External ID in Salesforce
|
||||
@@ -343,7 +444,8 @@ VALUES ('20260203000000_AddExternalIdRelationships', '9.0.0');
|
||||
|
||||
---
|
||||
|
||||
**Implementazione Completata**: 3 Febbraio 2026
|
||||
**Implementazione Iniziale**: 3 Febbraio 2026
|
||||
**Ultimo Aggiornamento**: 17 Febbraio 2026 - ⭐ **FIX CRITICO**: Normalizzazione automatica RelationshipName
|
||||
**Framework**: .NET 9.0
|
||||
**Pattern**: Repository + DTO + Service Layer
|
||||
**Database**: SQLite con Entity Framework Core
|
||||
|
||||
Reference in New Issue
Block a user