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
Rakshith RamachandraRakshith Ramachandra 

custom global variable in salesforce.

Can I create a variable in SalesForce environment and save it. So that it can be accessed in formulas? 
Best Answer chosen by Rakshith Ramachandra
Parker EdelmannParker Edelmann
Yes. As with any lookup field, you may reference that field from anywhere user may be referenced within a formula. If for some reason I'm wrong, just create 5 more custom fields on the user object that reference each field on the quota object. I know you can at least do that. Let me know if this works for you.

Thanks,
Parker

All Answers

Mahesh DMahesh D
Hi Rakshith,

Please look into the below link:

https://help.salesforce.com/apex/HTViewHelpDoc?id=dev_understanding_global_variables.htm&language=en

and check with $Label

Regards,
Mahesh
Parker EdelmannParker Edelmann
@Mahesh, correct me if I'm wrong, but the page you posted doesn't say anything about creating a custom variable. I used Ctrl + Find and searched for "custom" and "$Label", but didn't see a place where it explained how to create a custom variable. Just looking at a high level, the article was over my head, so I could be wrong, but please explain how one would go about creating a global variable in detail if you can.

Thanks,
Parker
Head In CloudHead In Cloud
Hi Parker, 

You can create "custom label" in salesforce. It is a global "name- value" pair..which can be used in Apex classes, validatin rules, custom buttons etc.. 
But I guess you can not use it in formula fields. 
Parker EdelmannParker Edelmann
Good to know, will have to look into that a little more.
Parker EdelmannParker Edelmann
I've heard that a vlookup might work for the purpose instead. If anyone has an all-about-vlookup article, that might help. By the way, @Rakshith Ramachandra, what do you want accomplished by a custom global variable, or are you asking if this can be done in general? If you have just one use case, or a few, there may be a better way to go about this. Thanks.
Rakshith RamachandraRakshith Ramachandra
Hi Parker, Thanks for the follow up. I'm trying to create reports in Salesforce. Consider the following situation. We have products with cost price. I want discounted price in the report. Discount price = 95% * Cost price. If I save a variable called Discount globally in SalesForce as 5% I can calculate discounted price dynamically using a formula in the report. I don't want to create a custom field called Discount or Discounted price. This is not exactly the problem i'm facing, but it's just an example.
Parker EdelmannParker Edelmann
In this case, the global variable's value would be a constant, not a variable. (in other words it has a constant value, it does not change or vary​) so creating a variable for a constant won't save much time. In this case, creating a report formula that reads .95 * Cost price is a little quicker than referencing a variable. Can you share some more use cases, because you mentioned that this wasn't your exact problem. I'd like to help you as much as possible, I just don't think the help you're looking for is in the form of a custom global variable.
Thanks,
Parker
Rakshith RamachandraRakshith Ramachandra
The discount can change anytime. So instead of going to all the reports and changing the formula, I want to change once. Here's the problem I'm facing. We have a lead generation team who needs to complete the quota of number of calls they did every day/week. Lets assume the quota was 200 calls per week and the rep made 180 calls. I want to show % of each in a report. The quota 200 can change next month!! Currently I've created a custom variable called quota and filled 200 for all ID's. How do I tackle this problem? Any pointers would help

Thanks!
Parker EdelmannParker Edelmann
In this case, I would create a field on users that has the quota, and create a process that launches a flow everytime that number is changed on any record. What the flow would do, is lookup every sales rep, either by name or by criteria, loop through the collection, and update that field to the same number that you edited the original record to. I know you don't want to create a custom field, and it may change the way your reports are structured, but that was the solution that came to my mind. Using this method will only require that you edit only one record, so it satisfies that criteria, but I'm afraid it does mean a little administrative work. For this use case, there probaly is a better solution, but this is the one that came to me at this time. If someone else is willing to give a solution, please do.
Rakshith RamachandraRakshith Ramachandra
Agreed. This was my first choice too. But we have a lot of other quota numbers like revenue etc. And that means I've to create custom fields for all of them and write flows for each. If it was just one, I'd be happy do it. Anyway, I totally appreciate your help Parker. Thank you! I'll just research if there's a better way to do it. 
Parker EdelmannParker Edelmann
If you have a bunch of values you need to record, do you think that a custom object would work? If you have a quota object and just extend a lookup field to it from user, and you have just one record in that object dictating all the values you need (calls, revenue, etc.), you can reference its values because users are related to everything, and because of the lookup relationship between users and quota, right? I should have thought of this earlier. This would also make it so that you only have one custom field on the user object, and all the data that you need would be stored on the quota object. Need a new value? add another field to the object and give it the value you need if you can't use an existing field. Would this work for you?
Rakshith RamachandraRakshith Ramachandra
This sounds like it might work. One quick question, If I have 5 quota fields in the custom object, Is one field in user enough to do lookup all those 5 fields from custom object?
Parker EdelmannParker Edelmann
Yes. As with any lookup field, you may reference that field from anywhere user may be referenced within a formula. If for some reason I'm wrong, just create 5 more custom fields on the user object that reference each field on the quota object. I know you can at least do that. Let me know if this works for you.

Thanks,
Parker
This was selected as the best answer
Rakshith RamachandraRakshith Ramachandra
Thanks Parker. I'll try this one and let you know. It's definitely better than what I'm doing right now for sure.