Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

I found this code herehere only using the classname itself

public String getNamespacePrefix() {
    String namespacePrefix;
    String[] classNameParts = String.valueOf(<Enter className>.class).split('\\.', 2);
    if(classNameParts.size() > 1) {
        Type classType = Type.forName(classNameParts[0], classNameParts[1]);
        if(classType == <Enter className>.class) {
            namespacePrefix = classNameParts[0];
        } else {
            namespacePrefix = '';
        }
    } else {
        //If there is only one part, the class has no namespace
        namespacePrefix = '';
    }
    return namespacePrefix; 
}

I found this code here only using the classname itself

public String getNamespacePrefix() {
    String namespacePrefix;
    String[] classNameParts = String.valueOf(<Enter className>.class).split('\\.', 2);
    if(classNameParts.size() > 1) {
        Type classType = Type.forName(classNameParts[0], classNameParts[1]);
        if(classType == <Enter className>.class) {
            namespacePrefix = classNameParts[0];
        } else {
            namespacePrefix = '';
        }
    } else {
        //If there is only one part, the class has no namespace
        namespacePrefix = '';
    }
    return namespacePrefix; 
}

I found this code here only using the classname itself

public String getNamespacePrefix() {
    String namespacePrefix;
    String[] classNameParts = String.valueOf(<Enter className>.class).split('\\.', 2);
    if(classNameParts.size() > 1) {
        Type classType = Type.forName(classNameParts[0], classNameParts[1]);
        if(classType == <Enter className>.class) {
            namespacePrefix = classNameParts[0];
        } else {
            namespacePrefix = '';
        }
    } else {
        //If there is only one part, the class has no namespace
        namespacePrefix = '';
    }
    return namespacePrefix; 
}
Source Link
Uwe Heim
  • 28.5k
  • 20
  • 121
  • 287

I found this code here only using the classname itself

public String getNamespacePrefix() {
    String namespacePrefix;
    String[] classNameParts = String.valueOf(<Enter className>.class).split('\\.', 2);
    if(classNameParts.size() > 1) {
        Type classType = Type.forName(classNameParts[0], classNameParts[1]);
        if(classType == <Enter className>.class) {
            namespacePrefix = classNameParts[0];
        } else {
            namespacePrefix = '';
        }
    } else {
        //If there is only one part, the class has no namespace
        namespacePrefix = '';
    }
    return namespacePrefix; 
}