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
Deborah OrthDeborah Orth 

Secure Secret Storage - Apex class is not implementing a CRUD/FLS check on the Name field of the Encrypt_DecryptC__c object

I've added all these line of code in the Save() method to try to satisfy the "Modify the save() function to implement CRUD/FLS check on the Name field of the Encrypt_Decrypt__c object." requirement but nothing seems to pass it's check.  Anyone else run into this or have any ideas?

        if (!Schema.sObjectType.EnCrypt_Decrypt__c.fields.Name.isCreateable()) { 
            return NULL; 
        }
        if (!Schema.sObjectType.EnCrypt_Decrypt__c.fields.Name.isUpdateable()) { 
            return NULL; 
        }        
        if (!Schema.sObjectType.EnCrypt_Decrypt__c.fields.Name.isAccessible()) { 
            return NULL; 
        }        

Thanks,
Deb
Best Answer chosen by Deborah Orth
Deborah OrthDeborah Orth
I figured it out, the object name is EnCrypt_DecryptC__c for the challenge, not EnCrypt_Decrypt__c which is used for the demo.

All Answers

Deborah OrthDeborah Orth
I figured it out, the object name is EnCrypt_DecryptC__c for the challenge, not EnCrypt_Decrypt__c which is used for the demo.
This was selected as the best answer
Charles ThompsonCharles Thompson
Thank you, Deborah.  You saved me from pulling more hair out!   Trailhead needs to point that little detail out.
Ajay ChakradharAjay Chakradhar
Click the Apex link in the Apex encryption challenge tab of the Secret Storage app. Make sure you switch to Salesforce Classic. The Secret Storage app isn't available in Lightning Experience.
Click the Apex Controller link at the bottom of the page to open the EncryptChallenge Apex class.
Modify the save() function to implement CRUD/FLS check on the Name field of the Encrypt_Decrypt__c object.
Modify the Save function to encrypt the lovers' messages. Use cryptoKey as the crypto key to encrypt data and implement AES256 as the encryption cipher in Crypto.encryptWithManagedIV() function.
Modify the DecryptData function to decrypt the lovers' messages. Modify the DecryptData function and use AES256 with cryptoKey as the crypto key to decrypt data. Decrypt the data using AES256 as the decryption cipher in Crypto.decryptWithManagedIV() function.

This Code works for me.
public class EncryptChallenge {
     public String paramValue{get;set;}
     public String pitemId{get;set;}    
     public String pitemName{get;set;}
     public Id recordId{get;set;}
     
     String testing;
     public List<EnCrypt_DecryptC__c> deals;
     public EnCrypt_DecryptC__c encrypt{get;set;}
     public List<EnCrypt_DecryptC__c> Messages {get;set;}
 
     Blob cryptoKey = Blob.valueOf([SELECT bkey__c FROM secretkey__mdt].bkey__c);
     
     
     public EncryptChallenge(ApexPages.StandardController controller) {
         if (Schema.sObjectType.EnCrypt_DecryptC__c.fields.Name.isAccessible()){
        getMessages();
          
         
    
        recordId = Apexpages.CurrentPage().getParameters().get('id');
        if(recordId !=null){
            encrypt = [SELECT Name From EnCrypt_DecryptC__c WHERE id=:recordId];
        }
        else{
            encrypt = new EnCrypt_DecryptC__c();
        }
         }
    }
     
     public PageReference DeleteMe(){
         if (!EnCrypt_DecryptC__c.sObjectType.getDescribe().isDeletable()){

        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, 'Insufficient access'));

        return null;
      }

         
        if(pitemId != ''){
            deals  = [select Id, Name from EnCrypt_DecryptC__c where id =:pitemId];
        }
   
     if(deals.size() > 0 ){ delete deals; }
       getMessages();
       return null; 
     }
    
   
       public PageReference DecryptMe(){
       try{     
            if(pitemName != NULL && pitemName != ''){
              Blob data = EncodingUtil.base64Decode(pitemName);
              Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey, data);
              String dryptData = decryptedData.toString();
              paramValue = dryptData;
           }
           else {
               System.debug('PitemName was NULL ');
           }
           paramValue = pitemName;
          }
          catch (Exception e){
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL,'Handling an error!');
                    ApexPages.addMessage(myMsg);
                }
       return null;    
    }
    
    
    public List<EnCrypt_DecryptC__c> getMessages() {
         if (!Schema.sObjectType.EnCrypt_DecryptC__c.fields.Name.isAccessible()){

                    return NULL;

        }
        Messages =  [select Id, Name from EnCrypt_DecryptC__c ORDER BY LastModifiedDate DESC NULLS FIRST];
        return Messages;
    }
    
    
    
    
     public PageReference Save(){
       if(!Schema.sObjectType.EnCrypt_DecryptC__c.fields.Name.isCreateable()){
           return NULL;
       }
       try{
           if(pitemName != NULL && pitemName != '')
           {
           if(encrypt.Name.length() < 80) 
            {
            Blob data = Blob.valueOf(encrypt.Name);
            Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data );
            String b64Data = EncodingUtil.base64Encode(encryptedData);
            encrypt.name = b64Data;
            insert encrypt;
            encrypt.id = null;
            getMessages();
            }
           }
       }
       catch (Exception e){
           ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'String empty or handling an error!');
           ApexPages.addMessage(myMsg);
       }
       return null;
       }

     
}

 
Eric KintzerEric Kintzer
(as of this date) I found that the EncryptChallenge class in the Kingdom Management DE referenced SObject Encrypt_DecryptC__c; I did a global replace on that SObject to Encrypt_Decrypt__c and then challenge then passes. Clearly Trailhead is confused abot which sobject to use for the challenge versus the verification
Alexandr MotsarAlexandr Motsar
Worked for me either. Just deleted C from DecryptC. Funny thing is that challenge is passed with Encrypt_Decrypt__c, 
but app doesn't work with that object. Encription decription happens only with Encrypt_DecryptC__c for Apex encryption challenge tab(((.