These keys are a crucial part of a PL-400 Microsoft Power Platform Developer exam. These keys are an integral part of customizing and extending the function of the platform to suit different businesses or usage scenarios.
Understanding Alternate Keys
Before diving into how to create and use alternate keys, it is crucial to understand what they are. In Power Platform, alternate keys are unique identifiers for records. While each record has a standard GUID as its primary key, there are scenarios where a different unique identifier might be practical, such as an email address, a user ID, or a product code.
Creating an Alternate Key
To create an alternate key, follow these steps:
- Navigate to Power Apps > Data > Tables.
- Choose the table for which you want to create an alternate key.
- Select ‘Keys’ under the ‘Table properties’ and then click on ‘Add Key’.
- Specify the display name and name.
- Then, select the field (or combination of fields) you want to use as the alternate key.
- Click on ‘Save’ to create the alternate key.
Once created, Power Platform will validate that the chosen field(s) have unique values for all existing records.
Using an Alternate Key
You can use alternate keys in several ways:
- To retrieve records: Classic application programming interfaces (APIs) use GUIDs to retrieve records. However, with alternate keys, APIs can retrieve records with the specified unique values, adding flexibility to the way data is accessed.
- To upsert records: Upsert is a combination of update and insert. When you want to insert a new record, but also update it if it already exists, you can use an upsert operation which uses alternate keys to determine if a record exists or not.
To illustrate, consider a scenario where we use the customer’s email as an alternate key. A customer record can be updated or inserted using the alternate key instead of the GUID. The JSON data in the REST API would look like this:
{
“name”: “John Doe”,
“email”: “johndoe@example.com”
}
This example doesn’t need the GUID and is potentially more intuitive to work with. Instead of searching for a customer’s GUID, which can be a long and unclear string, we directly use the email.
In a nutshell, alternate keys provide a more flexible and intuitive way to work with data in Microsoft Power Platform. Familiarity with creating and using them can be pivotal in succeeding in the PL-400 Microsoft Power Platform Developer exam. However, remember to also understand their limitations, such as a maximum of five alternate keys per table and a delay in key creation due to the validation process.
Reference: Microsoft Docs
Practice Test
True or False: Alternate Keys in Microsoft Power Platform are created to ensure data integrity.
- True
- False
Answer: True
Explanation: Alternate Keys are used in the Microsoft Power platform to ensure data integrity by preventing duplicate data, for example, user data in an organization or business.
Which of the following can be used as an Alternate Key in the Microsoft Power Platform Developer?
- a) Business phone
- b) Email
- c) Social Security Number
- d) None of the above
Answer: a, b, c
Explanation: A unique identifier which can be a business phone, email or a social security number can be used as an alternate key in the Microsoft Power Platform.
True or False: You can use Alternate Keys to find records faster than using the primary key?
- True
- False
Answer: False
Explanation: Using Alternate keys doesn’t necessarily make the search faster, they are used for ensuring data integrity and for integration with other systems.
True or False: A record can only have one Alternate Key.
- True
- False
Answer: False
Explanation: A record can potentially have multiple unique identifiers, allowing for multiple alternate keys.
Which of the following fields can NOT be included when creating an alternate key?
- a) Option Set
- b) Two Options
- c) Whole Number
- d) Decimal Number
Answer: a, b
Explanation: An alternate key can include any field type that supports uniqueness including but not limited to Decimal number, Whole number, but not Option Set and Two Options.
True or False: An alternate key can contain multiple columns.
- True
- False
Answer: True
Explanation: An alternate key can be composed of one or more entity columns.
Once an alternate key is created and activated, can it be deactivated?
- a) Yes
- b) No
Answer: a) Yes
Explanation: Once an alternate key has been activated, it can also be deactivated if needed.
True or False: The system automatically creates an index on an Alternate Key.
- True
- False
Answer: True
Explanation: The platform automatically creates an index on the Alternate Key to increase query performance.
Which of the following statements are true about the alternate keys?
- a) They allow you to uniquely identify an entity record
- b) They can only be defined by one attribute
- c) They can be used as a lookup into your system
- d) They take precedence over the primary key
Answer: a, c
Explanation: Alternate keys in Microsoft Power Platform allow you to uniquely identify an entity record. They can be made up of multiple attributes. They can be used for lookups into the system, but they do not take precedence over the primary key.
True or False: Alternate keys are automatically indexed.
- True
- False
Answer: True
Explanation: When an attribute is defined as an Alternate Key, the system automatically creates an index on that attribute.
Interview Questions
What is an alternate key in Microsoft Power Platform?
An alternate key is a data entity attribute in Microsoft Power Platform that uniquely identifies a record in the absence of a primary key.
Where are alternate keys primarily used?
Alternate keys are primarily used on the integration of data from other systems, where it provides a unique identifier for a record in the absence of a primary key.
Can you define more than one alternate key for an entity in the Power platform?
Yes, you can define more than one alternate key for an entity in the Power platform.
How many maximum fields can you have in an alternate key?
You can have a maximum of 5 fields in an alternate key.
What happens when you delete an alternate key?
When you delete an alternate key, the platform does not enforce its uniqueness anymore. Any dependent plug-ins or SDK message processing steps will also be deleted.
What will happen if a field is part of an alternate key and you change the field’s requirement level to Business Required?
If a field is part of an alternate key and you set the field’s requirement level to Business Required, you will get an error because fields that are part of alternate keys can’t be set to Business Required.
Can you define an alternate key on a custom entity?
Yes, an alternate key can be defined on both system and custom entities.
Can a calculated or rollup field be added to an alternate key?
No, a calculated or rollup field cannot be added to an alternate key.
What is the maximum length for a text field in an alternate key?
The maximum length for a text field in an alternate key is 900 characters.
Can you create an alternate key in Dynamics 365 without writing any code?
Yes, Dynamics 365 offers configuration-based methods to create alternate keys without the need for code.
Can you create an alternate key for an entity that has data in it?
Yes, but the process of creating the alternate key may take longer, as it needs to ensure the uniqueness of all existing data.
Why might the creation of an alternate key fail in Microsoft Power Platform?
The creation of an alternate key may fail if the existing data in the entity doesn’t conform to the uniqueness requirement.
Can you use an alternate key to retrieve a record?
Yes, you can use the Web API or Organization service to retrieve a record by its alternate key.
Is there any way to improve the performance of alternate keys in Dynamics 365?
Yes, performance can be improved by indexing the alternate key, but this should be done cautiously as it affects database performance.
What happens when you run an import job that includes a field designated as an alternate key?
When you run an import job that includes a field designated as an alternate key, the system will update the existing record if it finds a match with the alternate key, rather than creating a new record.