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

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


static void testDeleteApiSettingsN(){

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


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 .