You need to sign in to do that
Don't have an account?
Priyesh Misquith 12
What does if and else part does.
Please explain this map logic
List<Contact> lstContact = [select id,firstName,LastName,accountId from contact where accountid in :stAccId ]; Map<String,List<Contact>> mapAccountWiseContact = new Map<String,List<Contact>>(); For(Contact cont : lstContact) { if(mapAccountWiseContact.containsKey(cont.accountId)) { List<Contact> lstCont = mapAccountWiseContact.get(cont.accountId); lstCont.add(cont); } else { List<Contact> lstCont = new List<Contact>(); lstCont.add(cont); mapAccountWiseContact.put(cont.accountId,lstCont); } }
What does if and else part does.
I have gone through the script. I have explained the code in the comments.
I have also added a line in the script as it was needed.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
All Answers
Here if is checking that the accountid of contact exists in the map or not.
If the map contains accountId of the contact,it will add the current contact in the loop to the corresponding list of contacts in the map. else if the map doesn't contain account id of contact it will put the accountid as well as contact list into the map
Hope this helps you
If this helps kindly mark it as solved so that it may help others in future.
Thanks and Regards
I have gone through the script. I have explained the code in the comments.
I have also added a line in the script as it was needed.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com