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
Marcin GlazMarcin Glaz 

Identify and Prevent Sharing Violations how to pass this trailhead

This is my challenge:

Enforce sharing in Apex
Choose the CRUD/FLS & Sharing app in your Kingdom Management Developer Edition org, navigate to the Sharing Challenge tab, and click the Apex Controller link. Spot and fix any sharing violations.
For this module, you can’t use a standard Developer Edition org or Trailhead Playground. You must sign up for a super-special Kingdom Management DE org. Trust us...it’s worth it.
Click the Apex Controller link in the Sharing Challenge tab of the CRUD/FLS & Sharing app
Modify the class definition to prevent sharing violations

I am getting the error:

Challenge not yet complete in super-special Kingdom Management DE
You have not fixed all of the sharing violations. Don't forget about inner classes!

Please pose the code and guide what to do.
Thanks
AnudeepAnudeep (Salesforce Developers) 
Hi Marcin, 

I am seeing the same error with this challenge too

1. I see no inner classes in the CRUD_FLS_Challenge class to extend with sharing
2. Choosing the 'user with no CRUD nor FLS' dropdown when previewing the VF page is giving insufficnent privileges error 
3. I can't pass the challenge even when I give view all/ modify all to the demo user for the contacts and treasure object referenced in the page

There is a separate Trailhead team who can help with such issues. I recommend you reach out to them to resolve this

Anudeep


 
Marcin GlazMarcin Glaz
Hi @Anudeep,
Can you provide your code and the steps you have done?
Marcin GlazMarcin Glaz
Hi, can anyone share the full code to compare?
Marcin GlazMarcin Glaz
HI, can someone provide the full code for Identify and Prevent Sharing Violations?
Akhilesh M 30Akhilesh M 30
It's working finely :
public with sharing class Sharing_Challenge {

    public List<Coin_Purse__c> gold_normal_record {get; set;}
    public List<Coin_Purse__c> gold_async_record {get; set;}

    public void Sharing_Challenge() {
    
        Share_Challenge s_norm = new Share_Challenge(this);
        AsyncExecutionExample a_async = new AsyncExecutionExample(this);
        
        s_norm.s_chal_func();
        a_async.a_gold_search();
    }        
  
    
    public with sharing class AsyncExecutionExample implements Queueable {
        Sharing_Challenge s_chal;

        public AsyncExecutionExample(Sharing_Challenge s_chal) {
            this.s_chal = s_chal;
        }
        public PageReference a_gold_search(){ 
            if(Coin_Purse__c.sObjectType.getDescribe().isAccessible() && Schema.sObjectType.Coin_Purse__c.fields.Name.isAccessible() 
                                                                    && Schema.sObjectType.Coin_Purse__c.fields.Coin_location__c.isAccessible() 
                                                                    )
            {
                string query = 'SELECT Id,Name, Coin_location__c,Coin_Purse_Owner__r.Name FROM Coin_Purse__c';
                s_chal.gold_async_record = Database.query(query);
                return null;
            }
            else{
                return null;
            }
        }        
        public void execute(QueueableContext context){
            System.debug('==========>>>>>>>>Async sharing Violation example<<<<============');
   
        }
    }    
    
    public with sharing class Share_Challenge {
      Sharing_Challenge s_chal;
        public Share_Challenge(Sharing_Challenge s_chal) {
            this.s_chal = s_chal;
        }    
    
        public PageReference s_chal_func(){
            if(Coin_Purse__c.sObjectType.getDescribe().isAccessible() && Schema.sObjectType.Coin_Purse__c.fields.Name.isAccessible()  
                                                                        && Schema.sObjectType.Coin_Purse__c.fields.Coin_location__c.isAccessible() 
                                                                        )
            {
                string query = 'SELECT Id,Name,Gold_coins__c, Coin_location__c, Coin_Purse_Owner__r.Name FROM Coin_Purse__c';
                s_chal.gold_normal_record = Database.query(query);    
                return null;
            }else {
                return null;
            }
        }

    }

    public string[] getPermSets(){
            String[] permSetArray = new List<string>();
            PermSetArray.add('Simulate Farmer User'); // description of the needed permission set
            return permSetArray;
    }   
}
Thanks,
Akhilesh M
www.linkedin.com/in/akhilesh-m-dev