Environment variable as custom metadata type in Salesforce

0 votes
I stumbled across Custom Metadata Types when trying to represent environment variables in the Salesforce codebase. So, depending on whatever Sandbox I'm in, I'd like to change the baseURL of an external service to hit my apex class calls. I don't want to hard code anything in the class, so I'm looking for an environment variable-like approach.

As a custom metadata type, how would you express the URL? Also, how can I get to it in class? When a QA sandbox is refreshed from production, what happens? Is it possible for custom metadata type records to be overridden?
Mar 29 in SalesForce by surbhi
• 3,810 points
23 views

1 answer to this question.

0 votes
What's the name of the external service you're referring to? If it's actually a base url, "named credential" might be a better option. It'll abstract the base url for you, and if you need to offer authentication or a certificate, it'll do so...

If that fails, custom metadata could be a bad idea. You can add more (but not from apex) but if you deploy using Git/Ant/SFDX CLI instead of changesets, it'll be a nuisance because you'll require distinct custom metadata values for sandbox and production. It sort of ruins the purpose.

You might be better off utilising custom settings (hierarchy is enabled by default, but list requires a checkbox to be flipped in setup).

You can also change them using Apex. In an ideal world, you'd have a "postcopy" class that runs as soon as the sandbox is refreshed, overwriting the custom setting with the non-prod value. I don't think you can do it with named credentials; you'd need a tiny deployment or a manual step.
answered Apr 1 by CoolCoder
• 4,360 points

Related Questions In SalesForce

0 votes
0 answers

Apex (Salesforce) read json from response and store it in a string variable

I am trying to hit a API ...READ MORE

Mar 4 in SalesForce by surbhi
• 3,810 points
90 views
0 votes
1 answer

Upsert fields must be defined as unique External ID fields in Salesforce - Heroku Connect

You can use either the Salesforce record ...READ MORE

answered Apr 6 in SalesForce by CoolCoder
• 4,360 points
27 views
0 votes
0 answers

How to take test.salesforce.com while deployment as salesforce login url for api connection logic app?

In logic app i'm using salesforce connector after deployment ...READ MORE

Mar 1 in SalesForce by surbhi
• 3,810 points
92 views
0 votes
1 answer

How to take test.salesforce.com while deployment as salesforce login url for api connection logic app?

you are not passing the parameterValues, use ...READ MORE

answered Mar 2 in SalesForce by surbhi
• 3,810 points
64 views
+2 votes
2 answers

Salesforce Interview questions

Here are some questions very important for ...READ MORE

answered Jan 11, 2019 in Career Counselling by Suresh
• 720 points
1,834 views
0 votes
1 answer

How to connect to salesforce from tableau?

Hi, follow these steps to connect to Salesforce: 1. ...READ MORE

answered Mar 25, 2019 in Tableau by Cherukuri
• 33,010 points
287 views
0 votes
1 answer

Power BI - Salesforce

Hi, Follow below steps: 1. Go to Data source. 2. ...READ MORE

answered Mar 25, 2019 in Power BI by Cherukuri
• 33,010 points
174 views
0 votes
1 answer

What is the best training for Salesforce ADM-201 Exam?

Hi @Vardhan, I took Edureka's Salesforce Training that covers all ...READ MORE

answered Jun 3, 2021 in Others by Jaya
• 140 points

edited Dec 22, 2021 by Soumya 202 views
0 votes
1 answer

Apex (Salesforce) read json from response and store it in a string variable

String jsonStr = '{ "oktaToken":"eyJraWQiOiIyNlN1NHFMNnVVZTVJX2M5X2Z3WmZvX09ON0dNUHRtQzlEeHFsTGplLS00IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULlVINmdIOF9BcWJ" }'; Map<String, String> ...READ MORE

answered Mar 3 in SalesForce by CoolCoder
• 4,360 points
397 views
0 votes
1 answer

how to create a custom login page in salesforce.com?

Here are a few things to consider: Is ...READ MORE

answered Apr 6 in SalesForce by CoolCoder
• 4,360 points
73 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP