You need to sign in to do that
Don't have an account?

Remediate CRUD and FLS violations in Apex
My code is given below. It displays error to me:
Error: Compile Error: Method does not exist or incorrect signature: [Schema.DescribeFieldResult].isCreatable() at line 44 column 25
Error: Compile Error: Method does not exist or incorrect signature: [Schema.DescribeFieldResult].isCreatable() at line 44 column 25
public with sharing class CRUD_FLS_Create_Challenge{ public Id newUser {get;set;} public List<Personnel__c> getUnReg() { unregisteredUsers = new List<Personnel__c>(); List<Jouster__c> currentParticipants = [ select Participant_Name__r.Name from Jouster__c ]; List<Personnel__c> currentPersonnel = [ select Id, Name, Favorite_Color__c, Castle__r.Name from Personnel__c limit 15]; Boolean reg; System.debug(currentParticipants); System.debug(currentPersonnel); for( Personnel__c p : currentPersonnel) { reg = false; for(Jouster__c j : currentParticipants) { if(j.Participant_Name__r.Name == p.Name) { reg = true; break; } } if(reg == false) unregisteredUsers.add(p); } System.debug(unregisteredUsers); return unregisteredUsers; } public Jouster__c newParticipant {get;set;} public List<Personnel__c> unregisteredUsers; public void register(){ System.debug(newUser); Personnel__c p = [select Name, Favorite_Color__c, Castle__r.Name from Personnel__c where Id =: newUser]; if (!Schema.sObjectType.Jouster__c.fields.Participant_Name__c.isCreatable()) { if (!Schema.sObjectType.Jouster__c.fields.Color__c.isCreatable()) { if(!Schema.sObjectType.Jouster__c.fields.Favorite_Color__c.isCreatable()) { if(!Schema.sObjectType.Jouster__c.fields.Castle__c.isCreatable()) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Insufficient Access')); } } } } if([select id from Jouster__c where Participant_Name__r.Name =: p.Name] != null) insert new Jouster__c(Participant_Name__c=newUser, Color__c=p.Favorite_Color__c, Castle__c=p.Castle__c); else ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Jouster already entered in Tournament')); } public string[] getPermSets(){ String[] permSetArray = new List<string>(); PermSetArray.add('User with Read ONLY Access to the Jousters object'); // description of the needed permission set return permSetArray; } }
You are using isCreatable(), but I believe the correct spelling of the method is isCreateable().
I hope this helps!
All Answers
Challenge Not yet complete... here's what's wrong:
The code does not appear to be preventing unauthorized users from registering new jousting participants for the tournament. Make sure you're checking create access for each of the inserted fields.
Your kingdom is holding a tournament, and it's up to you to make sure that only authorized jousters can register to participate. Choose the CRUD/FLS & Sharing app in your Kingdom Management Developer Edition org, navigate to the CRUD & FLS Fix Challenge tab, and click the Apex Controller link. Then add the appropriate checks to the Apex code.
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 CRUD & FLS Fix Challenge tab of the CRUD/FLS & Sharing app
Find the register function
Add checks to the code to prevent unauthorized users from registering new jousting participants for the tournament
You are using isCreatable(), but I believe the correct spelling of the method is isCreateable().
I hope this helps!
Thank you for your answer. I passed this challenge.
Regards,
Alap Mistry
Can you please write the completed solution for this challenge? I am not able to complete it. :(
Thanks,
Pamy
Alap Misry