Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

We're developing applications for AppExchange and are trying to figure out the best way to do development and release management. There are several issues around this:

1) Package Prefixes. We are developing code in unmanaged mode and releasing as managed, so we have to add all the package prefixes into the code. Is there a way to do this dynamically at runtime? Right now we're using an Ant script, which stops us benefitting from the force.com IDE plugin.

2) Resource files... We are doing some ajax-ey stuff and as a result have a few different resource files we upload, some of which are multiple file resources (zip files). Has anyone automated the building of these resources using ANT, and does that work well?

Our environment seems very fragile and works for some developers and not others; have other people had this problem? How did you resolve it?

1 Answer

0 votes
by (32.1k points)
edited by

Try shifting to using Prefix Manager instead of ant substitutions.

Here is the code for the same:

public class PrefixMgr {

    private static string objPrefix = null;

    public static string getObjPrefix() {

        if(objPrefix == null) {

            try {

                Database.query( 'select MyColumn__c from my_prefix__MySmallTable__c' );

                objPrefix = 'my_prefix__';

            }

            catch(Exception e) {

                objPrefix = '';

            }

        }

        return objPrefix;

    }

    public static string getAppPrefix() {

        return 'my_prefix__';

    }

    public static string getObjName(string inp) {

        return getObjPrefix() + inp;

    }

}   

Primarily, this attempts a query (one time) on a table with the prefixed name. If it doesn't exist, then we are in unmanaged mode with no package prefixes. If it does work, then we set the prefix properly. getObjName is a benefit because PrefixMgr.getObjName('MyObject__c') is easier to read (especially in a string concat) than PrefixMgr.getObjPrefix() + 'MyObject__c'.

Enrolling in courses like Salesforce Training will help you to enhance your career!

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...