• Bhakti Gujarathi 6
  • NEWBIE
  • 5 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi All,

I am getting the System.StringException: Unrecognized base64 character: in Test Class.

I have written the below Apex Code to update the Course Registration Details.
 global static String updateCourseRegistration(){
   RestRequest req = RestContext.request;
        RestResponse res = Restcontext.response;
        String Endpoint=req.requestURI;
        
        string enrCourseComDate=endpoint.substring(endpoint.lastIndexOf('/')+1);
        String enrCourseComDateUTF= EncodingUtil.urlDecode(enrCourseComDate,'UTF-8');
        enrCourseComDateUTF= EncodingUtil.urlDecode(enrCourseComDateUTF,'UTF-8');
        Blob decodedB64 = EncodingUtil.base64Decode(enrCourseComDateUTF);
        Blob decryptedBlob = Crypto.decrypt('AES256', blob.valueof(cryptoKey),blob.valueof(IV), decodedB64);
        string CourseComDate=decryptedBlob.toString();
         if(courseComDate.length()==8){
            endpoint=endpoint.removeEnd('/'+enrCourseComDate);
            String encEnCourseId= endpoint.substring(endpoint.lastIndexOf('/')+1);
            encEnCourseId= EncodingUtil.urlDecode(encEnCourseId,'UTF-8');
            encEnCourseId= EncodingUtil.urlDecode(encEnCourseId,'UTF-8');
            Blob decodedB641 = EncodingUtil.base64Decode(encEnCourseId);
            Blob decryptedBlob1 = Crypto.decrypt('AES256', blob.valueof(cryptoKey),blob.valueof(IV), decodedB641);
            string enCourseId=decryptedBlob1.toString();
            if(enCourseId.length()==5){
                List<Course_Registration__c> cr=[select id,name,Course_Instance_LMS_Mode__c,LMS1_Enrcourse_ID__c,Registration_Date__c,Course_completion_Date__c from Course_Registration__c where
                                                    LMS1_Enrcourse_ID__c=:enCourseId];
                if(cr.size()>0){                                    
                    if(cr[0].Course_Instance_LMS_Mode__c!='Blended')
                        cr[0].LMS_Status__c='Completed';
                    else
                        cr[0].LMS_Status__c='Blended course completed';
                    update cr;
                  return '2000-Successful';
                }

Test Class:

@isTest
private class TestUpdateCourseCompletionStatusService 
{
    public static testmethod void testupdate() {
     LMSCredentials__c lmsc = new LMSCredentials__c ();
    lmsc.Prod_CryptoKey__c = 'prod crypto';
    lmsc.Test_CryptoKey__c = 'test crypto';
    lmsc.Prod_IV__c = 'prod iv';
    lmsc.Test_IV__c = 'test iv';
    insert lmsc;
    Course_Registration__c coursereg = new Course_Registration__c();
    coursereg.Name__c = 'testcourse';
    coursereg.ID_Number__c = '1234';
    coursereg.LMS_Status__c ='Completed';
    insert coursereg;
   System.RestContext.request = new RestRequest();
     RestContext.request.requestURI = '/UpdateCourseCompletionStatus/*';
     RestContext.request.addHeader('decodedB641 ', '12345');
     UpdateCourseCompletionStatusService.updateCourseRegistration();
}
}

I am getting the error as "System.StringException: Unrecognized base64 character: " and stack trace as Class.System.EncodingUtil.base64Decode: line 5, column 1
Class.UpdateCourseCompletionStatusService.updateCourseRegistration: line 28, column 1
Class.TestUpdateCourseCompletionStatusService.testupdate: line 30, column 1.

Thanks in Advance.
I have this scenario, where I need to disable the lookup field on vf page on click of a command button. I am able to disable the input field but not the lookup icon. It is still working. I want it to be  displayed on page but in disabled mode.