Our contact OWD is Private
When we convert an existing contact as a customer community plus user, he gets read only access to his own contact with the sharing reason 'Associated Portal User or Role '(created by salesforce behind the scenes). We found this by clicking share button for the contact.
When we run the below code in test class and try to check for contactshare records we dont see any records(the line before stop test.)
@istest
public static void testmethod1(){
test.startTest();
Set<String> customerUserTypes = new Set<String> {'PowerCustomerSuccess'};
Account acc = new Account (Name = 'newAcc1',recordtypeid = ISD_sObjectUtils.getRecordTypeIdByDeveloperName(Account.sObjectType, 'Business_Account'));
insert acc;
Contact con = new Contact (
AccountId = acc.id,
LastName = 'portalTestUser',
recordtypeid = ISD_sObjectUtils.getRecordTypeIdByDeveloperName(Contact.sObjectType, 'Business_User')
);
insert con;
Profile p = [select Id,name from Profile where UserType in :customerUserTypes limit 1];
User newUser = new User(
profileId = p.id,
username = '[email protected]',
email = '[email protected]',
emailencodingkey = 'UTF-8',
localesidkey = 'en_US',
languagelocalekey = 'en_US',
timezonesidkey = 'America/Los_Angeles',
alias='nuser',
lastname='lastname',
contactId = con.id
);
insert newUser;
system.debug('newUser' + newUser);
List<ContactShare> oTemp = [Select Id,ContactAccessLevel, UserOrGroupId from ContactShare where ContactId =:con.Id ];
system.debug('oTemp-->'+oTemp);
test.stopTest();
}
Questions:
- Are we missing anything in our test class code which is causing this behavior?
2.Is this the default behavior in test classes.