There is a uploaded code at this location 'https://github.com/financialforcedev/apex-mdapi'. I want to use this code in my apex class.

How can i use this code?

Is there any import/include technique in sales-force?

Thanks in advance.

3 Answers 3


Apex doesn't include the concept of imports so you don't have to do anything. You can directly reference the code once you have added it to your org:

MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
... = service.readMetadata(...);

without any import statements or extra namespace qualification.

I haven't tried it, but the repository you reference has a "Deploy to Salesforce" button that should make it easy to add the code.

Apex does have the concept of inner classes, so references such as MetadataService.MetadataPort are a class called MetadataPort nested inside a class called MetadataService.

A further case is where code is delivered as a managed package rather than as source code. In that case classes must be referenced by adding a namespace prefix e.g. thens.TheClass and only global classes are accessible.

  • So there is no import concept in salesforce. And if we need 3'rd party code then we need to download it and create new class in salesforce, copy-paste the code and then directly use it by using class name. Am i right Keith? Commented Jul 21, 2015 at 12:16
  • @HarishMache If it was just one class then copy and paste probably would be quickest. But there APIs used by Ant tasks or IDEs that can push code in and the "Deploy to Salesforce" button on the site you linked to is using some tooling on top of those APIs.
    – Keith C
    Commented Jul 21, 2015 at 12:40

Unlike java, Apex doesn't have the concept of packages, all the classes you write belong to a single package. So you don't have to import classes explicitly to use them.

However, you can still logically separate classes using namespaces. you can access these classes using the namespace prefix, for example:

if you have two classes with the same name but in different namespaces,

  1. np1.MyUtilityClass
  2. np2.MyUtilityClass

np1.MyUtilityClass obj0 = new np1.MyUtilityClass(); np1.MyUtilityClass obj1 = new np1.MyUtilityClass(); np2.MyUtilityClass obj2 = new np2.MyUtilityClass();

(obj0 instanceof obj1) // Evaluates to TRUE! (obj1 instanceof obj2) // Evaluates to FALSE!


You can download and package it and install in you Salesforce org using this you can communicate between two code base, yours and packaged.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .