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
inbox outbox 7inbox outbox 7 

I need help with updating the code to a MAP as opposed to a LIST.

@isTest

private static void testIsAccessible() {
   Map<String, User> users = New Map<String, User>();
     List<Contact> wsContacts;
      System.runAs(users.get('William Shattner')) {
        wsContacts = [SELECT Name, Phone, MailingStreet FROM Contact];
        Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.Contact.fields.getMap();
        Map<String, Boolean> fieldToAccessibility = new Map<String, Boolean>();
        for (Contact contact : wsContacts) {
            Set<String> populatedFields = contact.getPopulatedFieldsAsMap().keySet();
            for (String fieldName : populatedFields) {
                Boolean isAccessible = fieldToAccessibility.get(fieldName);
                if (isAccessible == null) {
                    isAccessible = fieldMap.get(fieldName).getDescribe().isAccessible();                  fieldToAccessibility.put(fieldName,isAccessible);
                }
                if (!isAccessible) {
                    contact.put(fieldName, null);
                }
            }
        }
     }
     System.debug(wsContacts);

The code which needs to be corrected is in bold letters. 
I have trouble quering inside a map. 


Thank you
PriyaPriya (Salesforce Developers) 
Hi ,

Can you please try below
Map<Id, Contact> m = new Map<Id, Contact>([SELECT Name, Phone, MailingStreet FROM Contact]);
Hope this is helpful!

Regards,
Ranjan