Fix: Risolto double-mapping negli External ID Relationships per Salesforce

- Implementata funzionalità completa External ID Relationships nell'interfaccia di mapping
- Corretto bug double-mapping: i campi sorgente usati per External ID non vengono più inclusi nei mapping normali
- Risolto errore MALFORMED_ID causato dall'invio duplicato di campi come proprietà dirette e nested objects
- Implementata logica corretta per relationship names: oggetti standard usano il nome diretto, custom objects usano suffisso __r
- Aggiunta UI a 3 colonne (Object, External ID Field, Source Field) per configurazione External ID Relationships
- Migrazione database per supporto External ID Relationships nei profili
- Aggiornato ProfileSaver.razor.cs per salvare/caricare External ID Relationships
- Aggiornato ScheduledProfileExecutionService.cs per gestire External ID nelle esecuzioni schedulate
- Formato JSON output corretto: { 'Account': { 'CardCode__c': 'V50000' } }

Documentazione: EXTERNAL_ID_RELATIONSHIPS_IMPLEMENTATION.md
This commit is contained in:
2026-02-15 18:44:15 +01:00
parent ed5316fbdf
commit 483eb7b407
16 changed files with 1923 additions and 21 deletions
+117 -1
View File
@@ -974,6 +974,119 @@
</div>
</div>
<!-- Sezione External ID Relationships (Salesforce) -->
@if (selectedRestEntity != null && currentRestDiscovery != null && IsSalesforceClient())
{
<div class="mt-4">
<div class="card">
<div class="card-header">
<h6 class="mb-0">
<i class="fas fa-link"></i> External ID Relationships (Salesforce)
</h6>
</div>
<div class="card-body">
<div class="alert alert-info">
<i class="fas fa-info-circle"></i>
<strong>Relating Records by External ID</strong><br>
<small>
Crea relazioni tra oggetti usando ID esterni invece degli ID interni di Salesforce.<br>
Esempio: Collega Opportunity ad Account usando <code>Account.CardCode__c = "C60000"</code>
</small>
</div>
<!-- Form per aggiungere nuova relazione -->
<div class="row mb-3">
<div class="col-md-3">
<label class="form-label">Oggetto Correlato:</label>
<select class="form-select" @bind="selectedRelationshipObject" @bind:after="OnRelationshipObjectSelected">
<option value="">-- Seleziona Oggetto --</option>
@foreach (var entity in availableRelationshipObjects.OrderBy(e => e.Name))
{
<option value="@entity.Name">@entity.Name</option>
}
</select>
<small class="text-muted">Es: Account, Contact</small>
</div>
<div class="col-md-3">
<label class="form-label">External ID Field:</label>
<select class="form-select" @bind="selectedExternalIdField" disabled="@string.IsNullOrEmpty(selectedRelationshipObject)">
<option value="">-- Seleziona Campo --</option>
@foreach (var field in GetExternalIdFieldsForSelectedObject())
{
<option value="@field">@field</option>
}
</select>
<small class="text-muted">Es: Country__c, CardCode__c</small>
</div>
<div class="col-md-3">
<label class="form-label">Campo Sorgente:</label>
<select class="form-select" @bind="selectedRelationshipSourceField">
<option value="">-- Seleziona Campo --</option>
@foreach (var field in GetSourceFieldsForRelationship())
{
<option value="@field">@field</option>
}
</select>
<small class="text-muted">Valore da usare per la relazione</small>
</div>
<div class="col-md-3 d-flex align-items-end">
<button class="btn btn-primary w-100" @onclick="AddExternalIdRelationship"
disabled="@(string.IsNullOrEmpty(selectedRelationshipObject) || string.IsNullOrEmpty(selectedExternalIdField) || string.IsNullOrEmpty(selectedRelationshipSourceField))">
<i class="fas fa-plus"></i> Aggiungi Relazione
</button>
</div>
</div>
<!-- Tabella relazioni configurate -->
@if (externalIdRelationships.Any())
{
<div class="mt-3">
<h6>Relazioni Configurate (@externalIdRelationships.Count)</h6>
<div class="table-responsive">
<table class="table table-sm table-striped">
<thead>
<tr>
<th>Oggetto Correlato</th>
<th>External ID Field</th>
<th>Campo Sorgente</th>
<th>Formato JSON Output</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
@foreach (var rel in externalIdRelationships)
{
<tr>
<td><strong>@rel.RelatedObjectName</strong></td>
<td><code>@rel.ExternalIdField</code></td>
<td><span class="badge bg-info">@rel.SourceField</span></td>
<td><small class="text-muted">@($"\"{rel.RelationshipName}\": {{ \"{rel.ExternalIdField}\": \"value\" }}")</small></td>
<td>
<button class="btn btn-sm btn-danger" @onclick="@(() => RemoveExternalIdRelationship(rel))">
<i class="fas fa-trash"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
else
{
<div class="alert alert-secondary">
<i class="fas fa-info-circle"></i> Nessuna relazione External ID configurata. Aggiungine una se necessario.
</div>
}
</div>
</div>
</div>
}
<!-- Sezione Mappature Correnti --> @if (fieldMappings.Any())
{
<div class="mt-4">
@@ -1153,6 +1266,8 @@
</div>
</div>
}
<div class="mt-3">
<div class="d-flex justify-content-between align-items-center">
@@ -1198,7 +1313,8 @@
DestinationCredentialId="@(GetCurrentDestinationCredentialIdAsync().Result)"
DestinationCredentialName="@selectedRestCredential"
DestinationEndpoint="@selectedRestEntity?.Name"
FieldMappings="@GetCurrentFieldMappings()"
FieldMappings="@GetCurrentFieldMappings()"
ExternalIdRelationships="@externalIdRelationships"
SourceKeyField="@sourceKeyField"
UseRecordAssociations="@useRecordAssociations"
OnProfileSaved="@OnProfileSaved" />