Thursday, August 9, 2018

Remote Site Settings : Way to Create/Update Using Apex (Metadata API)

We can create or update Remote Site Settings in Apex using Metadata API.

You can either download Metadata API WSDL from Salesforce and generate apex class by clicking on Generate from WSDL button.


Or you can download the MetadataService class from below link:

MetadataService.cls

Below is sample to code to create remote site settings.


Execute this static method from execute anonymous and check if records created or not.

 MetadataAPIUtility.createRemoteSiteSettings();

Below is snapshot of remote site settings created


Note:
  • I have used upsertMetadata method. If you want to only insert new remote site setting, then use insertMetadata method
  • fullname property is considered in order to decide whether remote site setting needs to be created or updated.
Hope this will help!!!


Create Custom Metadata Types Using Metadata API
Create Update Custom Label by Using Metadata API


46 comments:

  1. Hi, I'm getting this error:

    Error: Method does not exist or incorrect signature: void createService() from the type MetadataAPIUtility line 24 column 52

    ReplyDelete
  2. Hello ,
    thanks for this tutorial (very useful)
    I encounter an error when trying to execute the code in anonymous MetadataAPIUtility.createRemoteSiteSettings();

    Line: 13497, Column: 1
    System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out

    I don't know why because i'm trying to udpate any record other than the remote site settings. Any idea ?

    ReplyDelete
    Replies
    1. NO problem: I found my error... => there was something i was trying to update before creating the remotesite Settings

      Delete
  3. Hi,
    How can i fetch remote site setting records using apex?

    ReplyDelete
    Replies
    1. Hi Raj,

      You can use tooling API to fetch remote site settings. Execute below code in developer console which uses tooling API to get remote site settings details:

      HttpRequest req = new HttpRequest();
      req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
      req.setHeader('Content-Type', 'application/json');
      String domainUrl=URL.getSalesforceBaseUrl().toExternalForm();
      system.debug('********domainUrl:'+domainUrl);
      req.setEndpoint(domainUrl+'/services/data/v44.0/tooling/query/?q=Select+EndpointUrl,SiteName+from+RemoteProxy');
      req.setMethod('GET');

      Http h = new Http();
      HttpResponse res = h.send(req);
      system.debug(res.getBody());

      Now parse the JSON response.

      Delete
  4. Hi,
    I'm Trying to create remote site Setting in apex using Metadata Service.But i'm Unable to create, It says it 'Unauthorized endpoint'.The remote site is my Base URL,any Idea to resolve this
    Thanks in advance.

    ReplyDelete
    Replies
    1. Hi Ankit,
      I am getting same issue. Are you able to resolve this issue?

      Delete
    2. Hi,
      If we are creating it of the first time and it is not available in remote site setting then we need to create remote site from VF page in JS, because if we hit an callout in apex we need that in remote site but it will not apply for Visualforce JS

      Delete
  5. The time has arrived now IT staff can easily perform a unified desktop management for remote workers, remote offices, and local networked users  task list templates

    ReplyDelete
  6. Hi,
    Can we use this as a part of managed package, to update subscriber org

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Did you figure out how to query for the list of existing RemoteSiteSettings at all?

    ReplyDelete
  9. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. web-agency

    ReplyDelete
  10. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. sviluppo sito ecommerce

    ReplyDelete
  11. This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. sites like fiverr australia

    ReplyDelete
  12. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. WordPress Developer Brisbane

    ReplyDelete
  13. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
    quenza software

    ReplyDelete
  14. I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
    คลินิกความงาม

    ReplyDelete
  15. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.
    먹튀검증커뮤니티

    ReplyDelete
  16. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me.
    메이저놀이터

    ReplyDelete
  17. Thank you for some other informative blog. Where else could I get that type of information written in such an ideal means? I have a mission that I’m just now working on, and I have been at the look out for such information.
    SEO Company Australia

    ReplyDelete
  18. I really appreciate your efforts. Can you please provide test class for MetadataAPIUtility class.

    ReplyDelete
  19. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
    merchant services iso

    ReplyDelete
  20. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!!
    how to start a payment gateway company

    ReplyDelete
  21. This is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post!
    selling credit card terminals

    ReplyDelete
  22. Very interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know.
    https://solarmovie.design/

    ReplyDelete

  23. Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.
    North American Bancard Partners

    ReplyDelete
  24. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!!
    representative job description

    ReplyDelete

  25. Wonderful article, thanks for putting this together! This is obviously one great post. Thanks for the valuable information and insights you have so provided here.
    Wholesale ISO program

    ReplyDelete


  26. Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.
    how to become an iso agent

    ReplyDelete
  27. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
    tips on selling merchant services

    ReplyDelete
  28. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
    iso partner program

    ReplyDelete
  29. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
    how to sell merchant services

    ReplyDelete
  30. Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
    Flyttstädning Boden

    ReplyDelete
  31. Admiring the time and effort you put into your blog and detailed information you offer!.. Website Hosting

    ReplyDelete
  32. Nice post. I was checking constantly this blog and I’m impressed! Extremely useful info specially the last part I care for such information a lot. I was seeking this certain info for a long time. Thank you and good luck. 먹튀사이트

    ReplyDelete
  33. Nice to be visiting your blog once more, it has been months for me. Well this article that ive been waited for therefore long. i want this article to finish my assignment within the faculty, and it has same topic together with your article. Thanks, nice share. แทงบอล i99pro

    ReplyDelete
  34. Good website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! psychiatric service dog letter

    ReplyDelete
  35. Impressive web site, Distinguished feedback that I can tackle. Im moving forward and may apply to my current job as a pet sitter, which is very enjoyable, but I need to additional expand. Regards. 안전놀이터

    ReplyDelete
  36. Hi there! Nice post! Please tell us when I will see a follow up! 안전놀이터

    ReplyDelete
  37. Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it. 먹튀검증

    ReplyDelete
  38. Wohh exactly what I was searching for, appreciate it for posting.

    Feel free to surf to my weblog :: 풀싸롱

    ReplyDelete
  39. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. 안전놀이터

    ReplyDelete
  40. I high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information? 온라인릴게임

    ReplyDelete