You need to sign in to do that
Don't have an account?
Lakshmi S
Map scenario in Salesforce
Hi Team,
What are the uses and how to reduce the code using map in Salesforce?
Give me some scenarios about Map (When & Where we have to use Map in Coding)?
Regards
Lakshmi
What are the uses and how to reduce the code using map in Salesforce?
Give me some scenarios about Map (When & Where we have to use Map in Coding)?
Regards
Lakshmi
Refer below salesforce guide to know about maps.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_maps.htm
And for the scenario i would suggest you refer below link which has the sample code to expalin.
http://www.sfdc99.com/2014/01/25/use-maps-navigate-across-lists/
Please mark it as solved if my reply was helpful. It will make it available for other as the proper solution.
Best Regards
Sandhya
Thanks for your reply.
Map is used when we need the key-value pair to achieve our requirements.
You can understand it with below examples:
To access elements in a map, use the Map methods provided by Apex. This example creates a map of integer keys and string values. It adds two entries, checks for the existence of the first key, retrieves the value for the second entry, and finally gets the set of all keys.
Unlike Java, Apex developers do not need to reference the algorithm that is used to implement a map in their declarations (for example, HashMap or TreeMap). Apex uses a hash structure for all maps.
The iteration order of map elements is deterministic. You can rely on the order being the same in each subsequent execution of the same code. However, we recommend to always access map elements by key.
A map key can hold the null value.
Adding a map entry with a key that matches an existing key in the map overwrites the existing entry with that key with the new entry.
Map keys of type String are case-sensitive. Two keys that differ only by the case are considered unique and have corresponding distinct Map entries. Subsequently, the Map methods, including put, get, containsKey, and remove treat these keys as distinct.
The uniqueness of map keys of user-defined types is determined by the equals and hashCode methods, which you provide in your classes.
The uniqueness of keys of all other non-primitive types, such as sObject keys, is determined by comparing the objects’ field values.
Hope this will help you to understand The Map :)
Thanks
Vinod
Thanks for your reply
Do you have any idea on pre-populating the field values while creating new record without any relation ship from those two objects ?
My scenario is create a button on event detail page, button name is New Opportunity. I want to attach that activity to newly creating opportunity.
Could u plz give me any idea on this scenario. (It will be work on both classic and lightning environment)
Regards
Lakshmi