From 5f21d35e9a689780e0e7fee989c05a975cef8bf7 Mon Sep 17 00:00:00 2001 From: Jeff Martin Date: Sat, 23 Jun 2018 13:45:27 -0400 Subject: [PATCH] Fixed issue where some foreign keys in User table are not valid and must be excluded --- SalesforceSQLSchemaGenerator/MainWindow.xaml.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SalesforceSQLSchemaGenerator/MainWindow.xaml.cs b/SalesforceSQLSchemaGenerator/MainWindow.xaml.cs index f642179..c39dbe7 100644 --- a/SalesforceSQLSchemaGenerator/MainWindow.xaml.cs +++ b/SalesforceSQLSchemaGenerator/MainWindow.xaml.cs @@ -90,7 +90,7 @@ public Visibility SaveScriptVisibility { } } - private string[] AllowedNullableFieldNames = new string[] { + private string[] AllowedNonNullableFieldNames = new string[] { "Id", "CreatedById", "CreatedDate", @@ -101,7 +101,10 @@ public Visibility SaveScriptVisibility { "Name", "OwnerId" }; - + private string[] DisallowedUserForeignKeys = new string[] { + "CreatedById", + "LastModifiedById", + }; public Thickness DefaultMargin { get; set; } private Dictionary GeneratedSqlScript = new Dictionary(); @@ -442,11 +445,11 @@ public Dictionary GenerateSqlScript() { } if ((f.referenceTo != null && f.referenceTo.Length == 1) || string.Equals(f.name, "id", StringComparison.InvariantCultureIgnoreCase)) { sb.Append(" COLLATE SQL_Latin1_General_CP1_CS_AS"); - if (f.referenceTo != null && f.referenceTo.Length == 1) { + if (f.referenceTo != null && f.referenceTo.Length == 1 && !(t.name.Equals("User", StringComparison.InvariantCultureIgnoreCase) && DisallowedUserForeignKeys.Contains(f.name, StringComparer.InvariantCultureIgnoreCase))) { foreignKeys.Add(new ForeignKeyEntry(t.name, f.name, f.referenceTo[0], "Id")); //hardcode foreign key to id of ref table } } - if (!f.nillable && AllowedNullableFieldNames.Contains(f.name, StringComparer.InvariantCultureIgnoreCase)) { + if (!f.nillable && AllowedNonNullableFieldNames.Contains(f.name, StringComparer.InvariantCultureIgnoreCase)) { sb.Append(" NOT NULL"); } sb.AppendLine();