• JAGJOT SINGH
  • NEWBIE
  • 40 Points
  • Member since 2017


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
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);
        }  
    }
}
I want to create a custom field that calculates the sum of all 'Amount' opportunity fields for same opportunity, so that I can bucket this field in my report. It seems that it cannot bucket if I just summarize the Amount field, so I'm assuming if I create a custom Amount Sum field, this would work.

So for one account, I have 3 same updated opportunities:

Bucket - Total Opportunities 3 or more : $500 - $1000
Org: John Smith
        Amount: $100
        Amount: $100
        Amount: $400
       >>New Sum Field: $600

How would I create this in apex class?
trigger

public class createoppojjb{

    public static void account(set<id> AcountID)
    {
      
 
  List<Opportunity> oppList = [Select id, Name, AccountId, Amount from Opportunity where AccountId IN : AcountID];
        
        Map<Id,List<Opportunity>> mapOpp = new Map<Id,List<Opportunity>>();
        
        for(Opportunity opp : oppList){
            if(mapOpp.containsKey(opp.AccountId)){
            
                List<Opportunity> oppAcountID = mapOpp.get(opp.AccountId);
                oppAcountID.add(opp);
                mapOpp.put(opp.AccountId,oppAcountID);
            }
            else{
                List<Opportunity> oppAcountID = new List<Opportunity>();
                oppAcountID.add(opp);
                mapOpp.put(opp.AccountId,oppAcountID);
            
            }
        
        }
        
        
        List<Opportunity> opp;
        Double Amount = 0;
        String Idd;
        
        for(Id oppId : mapOpp.keySet()){
            
            opp = mapOpp.get(oppId);
            System.debug(opp);
            
            for(Opportunity amt : opp){
                Amount += amt.Amount;
                System.debug(Amount);
            }
            
        }
        
        Boolean flag = true;
        List<Opportunity> names = new List<Opportunity>([Select Id, Name, Amount from Opportunity where Id IN : opp]);
        
        System.debug('names  '+names + ' ' + flag);
        
        for(Opportunity oppName : names){
            if(oppName.Name == 'Test'){
                System.debug(Amount);
            }
        }
        }
        }


class

trigger CreateOpp on Account (after update, after insert) {
  if((Trigger.IsAfter && Trigger.isUpdate)) {

  Set<Id> accID = new Set<Id>();
   for(Account acc:Trigger.New) {
            if(acc.Name != 'null') {
            accID.add(acc.id);
            }
        }
    if(accID.size()>0) {
            createoppojjb.Addaccopp(accID);
        }
   }     
}
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);
        }  
    }
}
I want to create a custom field that calculates the sum of all 'Amount' opportunity fields for same opportunity, so that I can bucket this field in my report. It seems that it cannot bucket if I just summarize the Amount field, so I'm assuming if I create a custom Amount Sum field, this would work.

So for one account, I have 3 same updated opportunities:

Bucket - Total Opportunities 3 or more : $500 - $1000
Org: John Smith
        Amount: $100
        Amount: $100
        Amount: $400
       >>New Sum Field: $600

How would I create this in apex class?
trigger

public class createoppojjb{

    public static void account(set<id> AcountID)
    {
      
 
  List<Opportunity> oppList = [Select id, Name, AccountId, Amount from Opportunity where AccountId IN : AcountID];
        
        Map<Id,List<Opportunity>> mapOpp = new Map<Id,List<Opportunity>>();
        
        for(Opportunity opp : oppList){
            if(mapOpp.containsKey(opp.AccountId)){
            
                List<Opportunity> oppAcountID = mapOpp.get(opp.AccountId);
                oppAcountID.add(opp);
                mapOpp.put(opp.AccountId,oppAcountID);
            }
            else{
                List<Opportunity> oppAcountID = new List<Opportunity>();
                oppAcountID.add(opp);
                mapOpp.put(opp.AccountId,oppAcountID);
            
            }
        
        }
        
        
        List<Opportunity> opp;
        Double Amount = 0;
        String Idd;
        
        for(Id oppId : mapOpp.keySet()){
            
            opp = mapOpp.get(oppId);
            System.debug(opp);
            
            for(Opportunity amt : opp){
                Amount += amt.Amount;
                System.debug(Amount);
            }
            
        }
        
        Boolean flag = true;
        List<Opportunity> names = new List<Opportunity>([Select Id, Name, Amount from Opportunity where Id IN : opp]);
        
        System.debug('names  '+names + ' ' + flag);
        
        for(Opportunity oppName : names){
            if(oppName.Name == 'Test'){
                System.debug(Amount);
            }
        }
        }
        }


class

trigger CreateOpp on Account (after update, after insert) {
  if((Trigger.IsAfter && Trigger.isUpdate)) {

  Set<Id> accID = new Set<Id>();
   for(Account acc:Trigger.New) {
            if(acc.Name != 'null') {
            accID.add(acc.id);
            }
        }
    if(accID.size()>0) {
            createoppojjb.Addaccopp(accID);
        }
   }     
}