Part 28 - Entity and EntityReference Using Plugin in Dynamic 365 CRM
===> Lets understand Entity and EntityReference in simple way using below example.
1. Think of a Classroom:
In This Example:
2. Entity = Actual Student Details
===> A student has:
===> Entity stores all the actual student information.
3. EntityReference = Just the Student ID
===> The teacher doesn’t carry all student details.
===> Instead, they use the Student ID to find the record.
Student ID: 12345
===> EntityReference is like saying: "This Student ID belongs to John."
4. Why Do We Use Entity and EntityReference
===> Entity is used when we need all the student details.
Example: The teacher wants to see a student’s name, age, and marks
===> EntityReference is used when we just need to refer to a student using their ID.
Example: The teacher writes marks using the Student ID without seeing all the details.
5. Lets see How It Works in CRM Plugins:
Scenario:
===> A plugin runs when a new Order is created in CRM.
===> The plugin automatically creates an Invoice.
1. Entity:
Recommended by LinkedIn
2. EntityReference:
Order Created in CRM
Invoice Created in CRM
Here’s how the plugin works using both Entity and EntityReference:
Explanation:
===> The plugin reads all the Order data using Entity.
===> It doesn’t load all the customer details.
===> It just uses the Customer ID using EntityReference.
===> Using both the Order data and the Customer ID, the plugin creates an Invoice in CRM.
6. When to Use EntityReference:
.===> When Linking Records Using Relationships
===> When You Only Need a Reference Without Retrieving the Full Record
===> When Performing Updates on Lookup Fields
===> When Executing Requests That Require References
7. When NOT to Use EntityReference
Conclusion: