• shazz
  • NEWBIE
  • 0 Points
  • Member since 2011

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

I have a pageblock table in which half some of the columns are getting values from an APi call and some columns are getting values from standard objects. I have to add a radio button in each row of the table such that if one radio button is selected in any one of the row the others get disabled. Also when we select a particular row with its radio button in that case it gets to the top of the table as the first row. Any idea how to do that?

Thanks
Shaz

 



  • November 02, 2011
  • Like
  • 0

Hi

 

I m trying to callout an external API using the following code :

 

public class Testapicall {

 
  public String resultProp {get;set;}                                  //Prop for result
  public String inputProp {get;set;}                                   //Prop for input

 
  public PageReference submit() {                                      // On submit button click
         resultProp = getResult(inputProp);                            // Call function getResult that makes HTTP POST call to internal API
         return null;
      }
     
 
    
  private String getResult(String inputProp) {                         // HTTP POST and results back
        
     String json;                                                      // for storing back the json response of the HTTP call
     
     HttpRequest req = new HttpRequest();                              // POST method calling
     Http http = new Http();
     req.setMethod('POST');       
    
     req.setTimeout(2000);          
    
     String username = 'abc';
     String password = 'def';                                     // Settting up of username and password
     String contentTypes = 'application/json';
     String accepting = 'application/json';
    
    
      
     Blob headerValue = Blob.valueOf(username + ':' + password);                          //Setting header values
     String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
     req.setHeader('Authorization', authorizationHeader);
      
        
     req.setHeader('Content-Type', contentTypes);
     req.setHeader('Accept', accepting);
    
     String inp= '{"version": "1.1","method": "sforce_ping","params":{"name":"HELLO"}}';
     req.setBody(inp);                                                                                                                            
    
     String url = 'http://abcd.com:3100/services';         // Setting up end point
     req.setEndpoint(url);
     HTTPResponse resp = http.send(req);                               // Getting back the response
    
          System.debug(resp.toString());
          System.debug('STATUS:'+resp.getStatus());
          System.debug('STATUS_CODE:'+resp.getStatusCode());
    
     json = resp.getBody().replace('\n','');                           // Storing json in the 'json' string
     json = json.replace('\r','');
        
    try{
     String json1=json.replace('\t','');                                // Removing whitespace from json and storing it in json1
    
           System.debug('reading response as json1--->>>>' + json1 );         // ((((((((DEBUG POINT))))))))))
    
     JSONObject j = new JSONObject(json1);                              // JSONize
    
           System.debug('reading response as json object j --->>>>' + j );   // ((((((((DEBUG POINT))))))))))
         
     return toFinalResult(j).toDisplayString();                         // Calling Function toFinalResult which fetches the response from the JSONized response
     }
    catch (JSONObject.JSONException e) {                                // Exception handling
     return 'Error parsing JSON response: '+e;
     }
   
  }
 
 
  private FinalResult toFinalResult(JSONObject resp) {                  // Function toFinalResult which fetches the response from the JSONized response
     FinalResult finalres = new FinalResult();
     try {
          finalres.version = resp.getString('version');                    // Fetching the version
          finalres.result = resp.getString('result'); 
     }
     catch (Exception e) {
     //fail
     }
     return finalres;
  }
    
  private class FinalResult {                                            // Class to display final result
         public String version;
         public String result;
         public String toDisplayString() {
         return result;
        
         }
      }
     
  }

 

The curl request that works fine is :

curl -X POST -H "Content-Type: application/json" -H "Accept:application/json" -u abc:def -d '{"version": "1.1","method": "sforce_ping","params":{"name"

The curl response is :
{"version": "1.1", "result": "\"HELLO\""}
Can some one guide me where I m going wrong as it always calls that exception of timeout. Is it the Authentication issue?



  • October 06, 2011
  • Like
  • 0