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


49 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 really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.
    먹튀검증커뮤니티

    ReplyDelete
  15. 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
  16. I really appreciate your efforts. Can you please provide test class for MetadataAPIUtility class.

    ReplyDelete
  17. 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
  18. 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
  19. 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


  20. 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
  21. 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
  22. 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
  23. 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
  24. Admiring the time and effort you put into your blog and detailed information you offer!.. Website Hosting

    ReplyDelete
  25. 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
  26. 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
  27. 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
  28. I have read your article, it is very informative and helpful for me.I admire the valuable information you offer in your articles. Thanks for posting it.. 메이저사이트

    ReplyDelete
  29. Great article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks http://www.shuttlesky.in/

    ReplyDelete
  30. A web manage membership office probably won't be an electronic run yet a significant part of the much more expert membership endeavors moreover offer the best web facilitating uncommon arrangements utilizing the net.https://onohosting.com/

    ReplyDelete
  31. Host your domain names, emails and website using the super fast dubai best web hosting in dubai, Affordable servers based in Dubai UAE, Cpanel/Plesk Hosting, Free SSL and Site.

    ReplyDelete
  32. 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. 먹튀검증사이트

    ReplyDelete
  33. ค่ายสล็อตชั้นนำ เกมสล็อตเเตกง่าย เกมสล็อตยอดฮิตทั้งเก่า เเละใหม่ ทั้งหมดนี้รวมไว้ในเว็บไซต์เดียว ambbet เว็บหลัก สล็อตเว็บตรงไม่ผ่านเอเย่นต์ โดยผู้เล่นสามารถปั่นสล็อตผ่านเว็บ ambbets.com ได้ทันที เพียงเเค่เติมเงินเล่นสล็อต หรือ สมัครสมาชิก รับโบนัสฟรี เครดิตฟรี โปรโมชั่นเพียบ !! กดรับเอง ไม่มีเงื่อนไข เปิดให้บริการตลอด 24 ชั่วโมง.

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

    ReplyDelete
  35. Hi all, I am using the same utility to create one lightning page to make org connections but whenever some one is giving any other connection name then the previous one it is creating the two remote site setting with the different one.
    Is there any way we somehow can update the existing RemoteTypeSetting record.
    I have tried using the upsert and update method of the utility(MetaDataService) but that is not helpful, It is not working. It is only creating the new record only.

    ReplyDelete
  36. amazing information and brilliant work by this company services. Author: flyttstädning Växjö

    ReplyDelete
  37. interesting topic, i loved it, hope you will continue sharing this kind of information further in future. editor: flyttstädning borås

    ReplyDelete
  38. Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also visit Now zoopup.

    ReplyDelete