w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Is there a way in Force.com Apex code to "import packages / namespaces" as in java/cpp ?

I think this is a hidden detail in APEX. I've extended classes and referenced system methods without ever having to worry about it.

It might work to think of Salesforce managing one big import list that it adds to all of your code. When you declare a class as global it gets added to your global import list. At least this line in the documentation hints in that direction, "The global access modifier declares that this class is known by all Apex code everywhere."

Regarding namespaces, I've only seen this made available as part of managed packages. So for instance, SteelBrick's managed package QuoteQuickly has the prefix SBQQ on all of it's code. More about that here. I don't believe you can namespace in any other way.

There are some really sharp peeps over at salesforce.stackexchange.com that would know better than me though. I think you should ask over there.

EDIT At DreamForce '13 I attend a presentation by Steven Herod where he made his DTO classes inner classes and referenced them elsewhere like this: QuoteModel.QuoteRequest and QuoteModel.QuoteResponse. I asked him about it and he said it was a decent way of mimicking namespaces. I found his slide deck but it didn't include the code he demo'd live. I found this code which illustrates it a bit anyways. Look for addTextrBox.textBoxClass.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.