You need to sign in to do that
Don't have an account?
narendra jagwan
heroku postgres dataclip integration with salesforce
i m trying to integration salesforce with heroku . i create heroku postgres dataclip "https://dataclips.heroku.com/syneoppllnrictclhumigotdrbsl#employees-1" .then create http class in salesforce .but i got Status=Moved Permanently, StatusCode=301. how we can solve this issue .???
code
public class herokuDaaclip {
@future(callout=true)
public static void get() {
HttpRequest req = new HttpRequest();
//req.setHeader('content-type','application/json;charset=utf-8');
// https://dataclips.heroku.com/fcroecrluhwltbjinstfqmwyneex.json
req.setEndpoint('https://postgres.heroku.com/dataclips/syneoppllnrictclhumigotdrbsl.json');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
system.debug('@@@@@@@@@@@@@' + res.getbody());
if(res.getStatusCode()!=200)
{
System.debug('Error from '+ req.getEndpoint() +':'+res.getStatusCode()+''+res.getStatus());
}
string resbody = (res.getbody()).replace('','');
system.debug('fffffffffffff'+resbody);
// System.debug('Data Clip response code: '+res.getStatusCode()+'. Status: '+res.getStatus());
// return (List<JSON2Apex>)System.JSON.deserialize(resbody, List<JSON2Apex>.class);
}
}
code
public class herokuDaaclip {
@future(callout=true)
public static void get() {
HttpRequest req = new HttpRequest();
//req.setHeader('content-type','application/json;charset=utf-8');
// https://dataclips.heroku.com/fcroecrluhwltbjinstfqmwyneex.json
req.setEndpoint('https://postgres.heroku.com/dataclips/syneoppllnrictclhumigotdrbsl.json');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
system.debug('@@@@@@@@@@@@@' + res.getbody());
if(res.getStatusCode()!=200)
{
System.debug('Error from '+ req.getEndpoint() +':'+res.getStatusCode()+''+res.getStatus());
}
string resbody = (res.getbody()).replace('','');
system.debug('fffffffffffff'+resbody);
// System.debug('Data Clip response code: '+res.getStatusCode()+'. Status: '+res.getStatus());
// return (List<JSON2Apex>)System.JSON.deserialize(resbody, List<JSON2Apex>.class);
}
}
using following code
code
public class herokuDaaclip {
public Static String hr;
// public static list<object> name{get;set;}
public static list<String> title{get;set;}
// public static list<integer> id{get;set;}
public static string valuese;
public static list<wrapper> wrapperList{get;set;}
public static void get() {
title=new list<String>();
wrapperList = new list<wrapper>();
HttpRequest req = new HttpRequest();
//req.setHeader('content-type','application/json;charset=utf-8');
// https://dataclips.heroku.com/fcroecrluhwltbjinstfqmwyneex.json
req.setEndpoint('https://dataclips.heroku.com/syneoppllnrictclhumigotdrbsl.json');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
boolean redirect = true;
if(res.getStatusCode() >=300 && res.getStatusCode() <= 307 && res.getStatusCode() != 306) {
do {
redirect = true; // reset the value each time
String loc = res.getHeader('Location');
system.debug(':::redirect:::'+loc);
// get location of the redirect
if(loc == null) {
redirect = false;
continue;
}
req = new HttpRequest();
req.setEndpoint(loc);
req.setMethod('GET');
res = http.send(req);
if(res.getStatusCode() != 500) { // 500 = fail
if(res.getStatusCode() >=300 && res.getStatusCode() <= 307 && res.getStatusCode() != 306) {
redirect= true;
}
// I do special handling here with cookies
// if you need to bring a session cookie over to the
// redirected page, this is the place to grab that info
}
} while (redirect && Limits.getCallouts() != Limits.getLimitCallouts());
system.debug(''+res.getStatusCode());
system.debug(' goddddddddddd' +res.getbody());
String d =string.valueof(res.getbody());
// JSONParser parser = JSON.createParser(res.getbody());
// string d='{"fields":["employee_id","last_name","first_name","title"],"types":[23,1043,1043,1043],"values":[["1","Abreu","Mark","Project Coordinator"],["6","Lee","Sonia","Business Analyst"],["5","Leigh","Stephen","UI Developer"],["4","Miller","Anthony","Marketing Manager"],["2","Nyman","Larry","Security Engineer"],["3","Simmons","Iris","Software Architect"]]}';
Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(d);
list<Object> value=(list<Object>)m.get('values');
system.debug('ffffffffff'+value.size());
for(integer i=0;i<value.size();i++)
{
title = new list<string>();
hr = string.valueof(value[i]).replace('(','');
hr= hr.replace(')','');
list<string> b=hr.split(',');
for(String s:b){
system.debug('mmmmmmmm'+b);
system.debug('AAAAAAAA'+s);
title.add(s);
system.debug('ooooooo'+title);
}
wrapperList.add(new wrapper(title[0],title[1],title[2],title[3]));
}
system.debug('ooooooo'+title.size());
}
}
public class wrapper{
public string Name{get;set;}
public string Test{get;set;}
public string id {get;set;}
public String pro{get;set;}
public wrapper (String te,String fe,string se,string pe ){
Name=te;
Test=fe;
id=se;
pro=pe;
}
}
}