0

I am trying get the url for facebook profile photo which appears in contact detail page. I am able get the photoUrl of Contact by SOQL query:
select photourl from contact where id = 'contact Id' response = /services/images/photo/contactId If I use this in workbench REST Explores I am getting the proper response with facebook profile image url. But how to do this Rest call in apex. I tried : public String getCalloutResponseContents(String url) { // Instantiate a new http object Http h = new Http();

// Instantiate a new HTTP request, specify the method (GET) as well as the endpoint    
HttpRequest req = new HttpRequest();    
req.setEndpoint(url);    
req.setMethod('GET');

// Send the request, and return a response    
HttpResponse res = h.send(req);
System.debug(res);
return res.getBody();

} but getting bad request error.

1

In Apex you should Query directly for the Contact:

Contact c = [SELECT PhotoUrl FROM Contact WHERE Id = :contactId LIMIT 1];

No need to make a ReST callout from Apex.

  • Thanks for the response. I am doing this, but i am getting response like : /services/images/photo/contactId But i want the facebook photo url like: fbcdn-profile-a.akamaihd.net/hprofile-ak-xtf1/v/t1.0-1/p120x120/… This i am getting in workbench rest explore but how to implement in apex. – Manoj Dega Feb 5 '16 at 15:53
  • So the full link would be the server along with your result. You can get the server using URL.getSalesforceBaseUrl(); – Bradley Delaune Feb 5 '16 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.