function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rajendra RathoreRajendra Rathore 

Add Remote Site Setting Url At Runtime Using Apex Code and Change Profile Photo Of User From Profile Photo Url

I'm trying to change User Profile Photo from a Profile Photo url.

So to get a image body from image url i'm make a http request on that url like:

HttpRequest req= new HttpRequest();
req.setEndPoint(currentUser.Profile_Photo_Url__c);
 req.setMethod('GET');
Http http =  new Http();
HttpResponse res = new HttpResponse();

res = http.send(req);
ConnectApi.ChatterUsers.setPhoto(null, currentUser.id, new ConnectApi.BinaryInput(res.getBodyAsBlob(), 'image/jpg', UserInfo.getLastName()+'.jpg'));


But the Profile Picture url may be from Facebook,Yahoo,Google+, Linkedin etc and before make a http request that End Point url required in Remote Site Setting.

Can anyone please let me know  how can i set endpoint url in remote site setting at  runtime using apex code.
Also is there any other way to download image from url and change User profile photo from Url?

Thanks
Deepak Kumar ShyoranDeepak Kumar Shyoran
No you can't remote site setting at run time or dynamically. But there is a workaround to solve your problem is first you can insert an attachment with have the Photo you are getting from Facebook, Yahoo, Google etc and then can change the profile photo with the newly inserted photo.
Hope you will be able to solve your problem with this workaround.

Please mark it as best solution to your problem if it does solve your problem.
Rajendra RathoreRajendra Rathore
Thanks Deepak for reply.


@Deepak Kumar  But can you please let me know how can i'm insert an attachment from a photo url without making a http request on that url?

For example: I have profile photo url: https://lh5.googleusercontent.com/-vyn06sBsZu0/AAAAAAAAAAI/AAAAAAAAAOE/13GydQhKgnA/photo.jpg?sz=400

So how can i'm save that image from url and save in attachment in salesforce?

Thanks



Deepak Kumar ShyoranDeepak Kumar Shyoran
You can’t insert an attachment from an third party in salesforce without making any HTTP request. For that you need to make an HTTP call.