+ Start a Discussion
JAGJOT SINGHJAGJOT SINGH 

help me about this error

Error: Compile Error: Variable does not exist: RestDocCallController at line 19 column 13 in ""apex class""
------------------CLASS----------------------

@RestResource(urlMapping='/DocAttachment/v1/*')

global with sharing class RestDocService {
    
    // Post method to decode the file and insert Attachment.
    @HttpPost
    global static String attachdoc(String encodedDoc){
        try {      
            RestRequest req = RestContext.request;
            Id callId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
            Blob pic ;//Blob variable to capture decoded image
            if(encodedDoc != null) {
                pic=EncodingUtil.base64Decode(encodedDoc);//Decode the base64 encoded image
            }
            Attachment attach = new Attachment (ParentId = callId,Body = pic,ContentType = 'text/plain',Name = 'Document Test');
            insert attach;
            return attach.Id;
        }catch(Exception e) {
            RestDocCallController.errorHandler(e);
            return null;
        }
    }



----------------------CONTROLLER---------------------

Error: Compile Error: Invalid type: Logger__c at line 112 column 32 ""Controller""

public class RestDocCallController {
    
    public Blob file{get;set;}
    public String accountId{get;set;}
    public String fileName{get;set;}
    public String result{get;set;}
    
    // Method called from Page
    public PageReference uploadDoc(){
        if(file != null && accountId != null){
            try {
                RestDocCallController restObj = new RestDocCallController();
                String result = restObj.restAuthSetting(accountId,file,fileName);
                if(result != null) {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
                    return null;
                } else {
                    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));    
                }
            }catch(Exception e) {
                errorHandler(e);
                ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
                return null;
            }
            return null;
        }
        return null;
    }
    
     // Get Authorized and Post call to service class with JSON Body
    
    public String restAuthSetting(String accId,Blob file_body,String fileName) {
        try {
            String loginUrl = Label.Login_Url;
            String consumerKey = Label.App_Cosumer_Key;
            String consumerSecretKey = Label.Consumer_Secret_Key;
            String userName = Label.Org_UserName;
            String password = Label.Org_Password;
            
            
            Map<String, Object> oauth = oauthLogin(loginUrl,consumerKey,consumerSecretKey,userName,password);
            
            System.debug('oauth'+oauth);
                    
            String accessToken = (String)oauth.get('access_token');
            String instanceUrl = (String)oauth.get('instance_url');
            
            System.debug('instanceUrl'+instanceUrl);
            
            
            HttpRequest req = new HttpRequest();
            
            String bodyEncoded = EncodingUtil.base64Encode(file_body);
            
            req.setMethod('POST');
            
            req.setEndpoint(instanceUrl+'/services/apexrest/DocAttachment/v1/'+accId);
            req.setHeader('Authorization', 'Bearer '+accessToken);
            req.setHeader('Content-Type', 'application/json');
            req.setBody('{"encodedDoc":"'+bodyEncoded+'","fileName":"'+fileName+'"}');
            req.setTimeout(120000);
    
            Http http = new Http();
      
            HTTPResponse res = http.send(req);
    
            System.debug('BODY: '+res.getBody());
            System.debug('STATUS:'+res.getStatus());
            System.debug('STATUS_CODE:'+res.getStatusCode());
            
            return res.getBody();
        } catch(Exception e) {
            errorHandler(e);
            return null;
        }
    }
    
    // Method to get authorized using Connected Apps Client ID and Consumer Id.
    
     private static Map<String, Object> oauthLogin(String loginUri, String clientId,
        String clientSecret, String username, String password) {
        
        try {
            HttpRequest req = new HttpRequest();
     
            req.setMethod('POST');
            req.setEndpoint(loginUri+'/services/oauth2/token');
            req.setBody('grant_type=password' +
                '&client_id=' + clientId +
                '&client_secret=' + clientSecret +
                '&username=' + EncodingUtil.urlEncode(username, 'UTF-8') +
                '&password=' + EncodingUtil.urlEncode(password, 'UTF-8'));
        
            Http http = new Http();
      
            HTTPResponse res = http.send(req);
    
            System.debug('BODY: '+res.getBody());
            System.debug('STATUS:'+res.getStatus());
            System.debug('STATUS_CODE:'+res.getStatusCode());
            
            return (Map<String, Object>)JSON.deserializeUntyped(res.getBody());
        }catch(Exception e) {
            errorHandler(e);
            return null;
        }
    }
    
     //Method used to log errors
    public static void errorHandler(Exception e) {
        
        Logger__c logger = new Logger__c();
        logger.Error_Line_Number__c = String.valueOf(e.getLineNumber());
        logger.Error_Body__c = e.getStackTraceString();
        logger.Error_Cause__c = e.getMessage();
        try {
            insert logger;
        }catch(Exception exp){
            System.debug(exp);
        }  
    }
}
Best Answer chosen by JAGJOT SINGH
LBKLBK
Looks like your Controller is not saved because it couldn't identify Logger__c.

Is that a custom object? Can you check if you have access on this object, while saving this APEX Controller?

Also, you have to make sure that this controller is saved before attempting to save RestDocService class file.

Hope this helps.

All Answers

LBKLBK
Looks like your Controller is not saved because it couldn't identify Logger__c.

Is that a custom object? Can you check if you have access on this object, while saving this APEX Controller?

Also, you have to make sure that this controller is saved before attempting to save RestDocService class file.

Hope this helps.
This was selected as the best answer
JAGJOT SINGHJAGJOT SINGH

Hello Sir,
@LBK

now its working


Thanks sir