function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Adarsh NandanAdarsh Nandan 

Actually I am getting Problem to use Map and Set

Actually I am Fresher I need some help When i use Map and  set  in apex and How can I use It . Please Send me the best Way to learn Map and Set and Also Confusion in AFter Delete and before Delete?
HARSHIL U PARIKHHARSHIL U PARIKH
How to use Map?
We use map when we need  collection of key-value pairs where each unique key maps to a single value.
e.g.,
Map<String, Integer> statesWithZip = New Map<String, Integer>();

statesWithZip.put('New Jersey', 123);
statesWithZip.put('Maryland', 412);
statesWithZip.put('California', 856);
statesWithZip.put('New York', 555);
// at this point map has 4 values in it. Now, let's say you need to know the zipcode of Maryland?

Integer marylandZip = statesWithZip.get('Maryland');
// This will give you marylandZipCode 
How to use List?
List is nothing but an order collection of data. It's an Array of one particular Data Type. But however, in salesforce you can have SObject as a Data Type as well.
e.g.,
List<Integer> numbers = New List<Integer>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(4);
// at this point list has 4 values in it. Now, let's say you want to get 3rd value from list 

Integer I = numbers.get(3);
// At this point I = 4 because list index starts with zero.
Remember: Lists can have duplicate values in it. You can surly add numbers.add(1); again and it's index would be 4.

What is After Delete inside an Apex Trigger?

let's say you are counting number of Conatct on Account. Now, you are deleting one Contact from Account's related list. At this point how would account know that it now one contact less? In other words if there are 5 conatcts per Account then you have a Roll-Up trigger which counts total number of Cons on Account with value of 5. If you delete 5th contact then how would Account record would update with 4 instead of 5 in Total_Contacts__c field? Because you are not touching Account object at all.

Above, is the scenario where you write After Delete inside your trigger parameters because you are telling trigger that RUN even if the record is deleted.
Samething goes for all other parameters events such as Before Insert, Before Update, After Delet, After UnDelete, ......etc..

Events tells the trigger when to run.

Hope it helps & if it solves the question then please mark it as best answer since it will help other users in community as well!