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
RIteshMRIteshM 

Testing Public Custom Settings for DML Exception

i have a custom setting that is Public and have to test for DMLException.i am doing one thing creating and inserting as one usere and calling the delete method as secong user which will not have access to This custom settings.i want to know is custom settings available for all profiles because its not throwing any exception my Apex function is 

 

  public PageReference deleteUserSettings(){

       try{        delete userSettings;       

  userSettings = new GlassUserApiSettings__c(setUpOwnerId = UserInfo.getUserId());

             }   

   catch (System.DMLException e){System.debug(e);} 

      return null;    }

 

and my test code is

 

@isTest(SeeAllData=true)
static void testDeleteApiSettingsN(){
MirrorTestUtil.setupSettings();

Profile p = [SELECT Id FROM Profile WHERE Name='Read Only'];
User u2 = new User(Alias = 'newUser', Email='newuser@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@orgtest.com');
MirrorSettingsController ctrl = new MirrorSettingsController();
System.runAs(u2) {
Test.startTest();
ctrl.deleteUserSettings();
Test.stopTest();
}
}

 

i tried it with Stasndard User as well but its deleting not throwing exception. can any one please tell how to make code coverage of this to DMLException .