• Shatanik1
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I have written the following code and I am getting the error  "You have uncommitted work pending. Please commit or rollback before calling out". I am new to salesforce, so am unable to understand what the error is for. Kindly help

 

 

authSuccessBool=false;
        String token = ApexPages.currentPage().getParameters().get('oauth_token');
        System.debug('CompleteAuth Token===================================='+ApexPages.currentPage().getParameters().get('oauth_token'));
        if(token!=null)
        {
            String verifier = ApexPages.currentPage().getParameters().get('oauth_verifier');
            System.debug('CompleteAuth Verifier================================================='+ApexPages.currentPage().getParameters().get('oauth_verifier'));
            OAuth oa = new OAuth();
            authSuccess = oa.completeAuthorization(token,verifier);
              
            if(authSuccess!=null||authSuccess!=' ')
            {
                authSuccessBool=true;
            }
            this.message = oa.message;
        }
        else {
            message = 'Invalid request. Missing parameter oauth_token';
        }
        
        
         //--------------------------------------------------------
            Http h = new Http();
            HttpRequest req = new HttpRequest();
            HttpResponse  res = new HttpResponse();
            String endpoint='https://docs.google.com/feeds/download/documents/Export?id=1ok94msdl7FDfo51R9cCSVqdRY6yRVO16byfv-GpvDOs&exportFormat=html';
            req.setMethod('GET');
            req.setEndpoint(endpoint);
            res=h.send(req);
            System.debug('====================='+res.getBody());
         //--------------------------------------------------------
        
        return null;
    }

I have written the following code and I am getting the error  "You have uncommitted work pending. Please commit or rollback before calling out". I am new to salesforce, so am unable to understand what the error is for. Kindly help

 

 

authSuccessBool=false;
        String token = ApexPages.currentPage().getParameters().get('oauth_token');
        System.debug('CompleteAuth Token===================================='+ApexPages.currentPage().getParameters().get('oauth_token'));
        if(token!=null)
        {
            String verifier = ApexPages.currentPage().getParameters().get('oauth_verifier');
            System.debug('CompleteAuth Verifier================================================='+ApexPages.currentPage().getParameters().get('oauth_verifier'));
            OAuth oa = new OAuth();
            authSuccess = oa.completeAuthorization(token,verifier);
              
            if(authSuccess!=null||authSuccess!=' ')
            {
                authSuccessBool=true;
            }
            this.message = oa.message;
        }
        else {
            message = 'Invalid request. Missing parameter oauth_token';
        }
        
        
         //--------------------------------------------------------
            Http h = new Http();
            HttpRequest req = new HttpRequest();
            HttpResponse  res = new HttpResponse();
            String endpoint='https://docs.google.com/feeds/download/documents/Export?id=1ok94msdl7FDfo51R9cCSVqdRY6yRVO16byfv-GpvDOs&exportFormat=html';
            req.setMethod('GET');
            req.setEndpoint(endpoint);
            res=h.send(req);
            System.debug('====================='+res.getBody());
         //--------------------------------------------------------
        
        return null;
    }