MS CRM Error: The Entity Relationship with SchemaName = '" was not found in the MetadataCache
Recently i was having this issue while opening any existing account record or creating a new account record in a CRM org.
Error message: The Entity Relationship with SchemaName = '" was not found in the MetadataCache
Log file
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #D985AF1CDetail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220970</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #D985AF1C</Message>
<Timestamp>2016-08-16T06:57:30.9208191Z</Timestamp>
<InnerFault>
<ErrorCode>-2147220918</ErrorCode>
<ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<Message>The Entity Relationship with SchemaName = 'new_account_new_orderproduct_CustomerName' was not found in the MetadataCache</Message>
<Timestamp>2016-08-16T06:57:30.9208191Z</Timestamp>
<InnerFault i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<TraceText i:nil="true" />
</OrganizationServiceFault>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Now what i had done is that on a custom entity order product, i had created a lookup of account entity. (Oh please don't ask why we created custom entity named order product..!)
Also on account record, i have attached a grid of all order products (custom entity) using that lookup of account i created on custom order product entity.
Now the issue start occurring when i deleted the lookup of customer entity from custom order product entity.
I forget that relationship formed from this lookup has been used in that grid on account form.
Now whenever i tried to open main crm form (existing account or a new one) system throw the above error.
It'll off-course throw this error because metadata on account form have the reference to such a relationship which doesn't exist any more..!
So to fix this what i did is, i removed the grid of custom order product entity from account entity which was referring a relationship which doesn't exist anymore.
So the thing we learn from this is that whenever we are deleting a lookup we should keep in mind that we are also deleting the relationship associated with it.
And if that relationship is used anywhere else, for this case in a grid, system will always create an issue.
Hope it would be helpful.
Feel free to comment and improve.