• srinivas maredla
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 1
    Replies
public class Send_Data_To_NFS2{ 
    public string result;             
    public HttpResponse res;   
    
    public string reqResMethod(string strJSON, string strEndPoint){
        Http h = new Http();
        HttpRequest req = new HttpRequest();  
        req.setHeader('Content-Type','application/json');        
        string strJSONBody = strJSON;        
        req.setBody(strJSONBody);
        req.setMethod('POST');
        req.setEndpoint(strEndPoint);
        res = h.send(req);
        result = res.getBody();          
        result = result.replace('\\', '').removeStart('"').removeEnd('"'); 
        system.debug('*****res****'+res);         
        system.debug('*****res.getbody****'+result);                
        return result;
    }
        
    Public void push_Data(){            
  
        string strJSON = '-------------------------------------------------------------';
  
        string strEndPoint = '---------------------------------------------------------';
        string resp = reqResMethod(strJSON, strEndPoint);
        
  
        NFSWrapper deserializedResponse = (NFSWrapper)JSON.deserialize(resp, NFSWrapper.class);                  
  
        
        secondResponse deserializedResponse1;
        if(deserializedResponse != null && deserializedResponse.StatusCode == '200'){  
  
  
            string strJSON1 = '------------------------------------------------------------------------';  
            string strEndPoint1 = '-------------------------------------------';

            string resp1 = reqResMethod(strJSON1, strEndPoint1);
            
            deserializedResponse1 = (secondResponse)JSON.deserialize(resp1, secondResponse.class);
            
            
            if(deserializedResponse1 != null && deserializedResponse1.StatusCode == '200'){
            
            Attachment att = new Attachment();
            att = [select name, body from Attachment where ParentId = '*********************'];
            string fileBody = EncodingUtil.base64Encode(att.Body);
            system.debug('**************file body**************' + fileBody);                       
            string url = '----------------------------------------------------------------------';
            url = url + deserializedResponse1.OpportunityId;
            url = url + '&filename=test.pdf';       
            string resp2 = reqResMethod(filebody, url);
            
            //3rd POST Deserilaization
            thirdResponse deserializedResponse2 = (thirdResponse)JSON.deserialize(resp2, thirdResponse.class);
            if(deserializedResponse2 != null && deserializedResponse2.StatusCode == '200'){
                system.debug('*****ATTACHMENT ADDED SUCCESSFULLY****');
            }
            
            else{
                system.debug('*****ERROR MESSAGE****' + deserializedResponse2.Message);
            }
            
        }else{
            system.debug('*****BAD REQUEST2****');
            system.debug('*****MESSAGE****'+ deserializedResponse.Message);
        }
        
                   
            
        }else{            
            system.debug('*****BAD REQUEST1****');
            system.debug('*****MESSAGE****'+ deserializedResponse1.Message);
        }
        
    }       
    
    //Wrapper Classes
    
    public class Nttrapper{
        public String StatusCode;
        public String OpportunityId;
        public String Message;
        public string[] ContactIds;        
        public String BrokerId;
        public cls_Addresses[] Addresses;
        public String AccountId;
    }        

   public class cls_Addresses {
        public String type;
        public String Id;  
    }
    
    public class secondResponse{
        public String StatusCode;
        public String OpportunityId;
        public String Message;
        public String BSNumber;
    }
    
    public class thirdResponse{
        public String StatusCode;
        public String Message;
      
    }   
}
public class Send_Data_To_NFS2{ 
    public string result;             
    public HttpResponse res;   
    
    public string reqResMethod(string strJSON, string strEndPoint){
        Http h = new Http();
        HttpRequest req = new HttpRequest();  
        req.setHeader('Content-Type','application/json');        
        string strJSONBody = strJSON;        
        req.setBody(strJSONBody);
        req.setMethod('POST');
        req.setEndpoint(strEndPoint);
        res = h.send(req);
        result = res.getBody();          
        result = result.replace('\\', '').removeStart('"').removeEnd('"'); 
        system.debug('*****res****'+res);         
        system.debug('*****res.getbody****'+result);                
        return result;
    }
        
    Public void push_Data(){            
  
        string strJSON = '-------------------------------------------------------------';
  
        string strEndPoint = '---------------------------------------------------------';
        string resp = reqResMethod(strJSON, strEndPoint);
        
  
        NFSWrapper deserializedResponse = (NFSWrapper)JSON.deserialize(resp, NFSWrapper.class);                  
  
        
        secondResponse deserializedResponse1;
        if(deserializedResponse != null && deserializedResponse.StatusCode == '200'){  
  
  
            string strJSON1 = '------------------------------------------------------------------------';  
            string strEndPoint1 = '-------------------------------------------';

            string resp1 = reqResMethod(strJSON1, strEndPoint1);
            
            deserializedResponse1 = (secondResponse)JSON.deserialize(resp1, secondResponse.class);
            
            
            if(deserializedResponse1 != null && deserializedResponse1.StatusCode == '200'){
            
            Attachment att = new Attachment();
            att = [select name, body from Attachment where ParentId = '*********************'];
            string fileBody = EncodingUtil.base64Encode(att.Body);
            system.debug('**************file body**************' + fileBody);                       
            string url = '----------------------------------------------------------------------';
            url = url + deserializedResponse1.OpportunityId;
            url = url + '&filename=test.pdf';       
            string resp2 = reqResMethod(filebody, url);
            
            //3rd POST Deserilaization
            thirdResponse deserializedResponse2 = (thirdResponse)JSON.deserialize(resp2, thirdResponse.class);
            if(deserializedResponse2 != null && deserializedResponse2.StatusCode == '200'){
                system.debug('*****ATTACHMENT ADDED SUCCESSFULLY****');
            }
            
            else{
                system.debug('*****ERROR MESSAGE****' + deserializedResponse2.Message);
            }
            
        }else{
            system.debug('*****BAD REQUEST2****');
            system.debug('*****MESSAGE****'+ deserializedResponse.Message);
        }
        
                   
            
        }else{            
            system.debug('*****BAD REQUEST1****');
            system.debug('*****MESSAGE****'+ deserializedResponse1.Message);
        }
        
    }       
    
    //Wrapper Classes
    
    public class Nttrapper{
        public String StatusCode;
        public String OpportunityId;
        public String Message;
        public string[] ContactIds;        
        public String BrokerId;
        public cls_Addresses[] Addresses;
        public String AccountId;
    }        

   public class cls_Addresses {
        public String type;
        public String Id;  
    }
    
    public class secondResponse{
        public String StatusCode;
        public String OpportunityId;
        public String Message;
        public String BSNumber;
    }
    
    public class thirdResponse{
        public String StatusCode;
        public String Message;
      
    }   
}