Andy in the Cloud

From BBC Basic to and beyond…

MavensMate Templates and Apex Enterprise Patterns


mavensmateI’ve been using MavensMate as alternative IDE for coding on for the past 6 months and loving it more and more to be honest, it receives a strong stream of updates, feels modern, responsive (as much as the underlying platform API’s permit) and is light weight. I’m also getting to grips with the power of the Sublime Text editor (which hosts MavensMate) and it’s excellent find and replace tools for example.  Recently i’ve been working on a feature with the help of the author of this fantastic tool Joe Ferraro.

One of the cool social features of MavensMate is it’s template engine, when ever you create a Apex class, Apex trigger, Visualforce Page or Visualforce Component, you can elect to start editing from scratch or pick one of a growing number of templates, ranging from Batch Apex, Controllers, Schedulers to Unit test templates, including a new one from a new friend in the push for BDD on, Paul Hardaker (also a employee btw). The whole thing is driven by a GitHub repository, if you contribute to that repository (and your pull request is merged) your template is instantly live across the world! Now that’s a social IDE!

I set about developing templates for the Apex Enterprise Patterns and quickly bumped into a gotcha! The previous template engine only took one parameter, the name of the Metadata component (Apex class or trigger name for example). When creating Domain classes or Selectors, the name of the class and the underlying custom object is required. After a quick Twitter conversation and GitHub issue, Joe had already nailed the design for a new feature to fix this situation! You can read more about how to use it here.


I’m pleased to report it worked like a charm the first time, great design and very flexible! The templates have now been submitted and successfully merged by Joe into the repository and are now live and ready to use!

  • DomainClass
  • DomainTrigger
  • SelectorClass
  • ServiceClass

The follow screenshot shows the template selection prompt, just start typing and it narrows the options down as you go, press enter and you are prompted for the template parameters. These parameters default to examples defined in the template configuration file, overwrite these with your own following the examples as a naming convention guide. Press enter again and MavensMate will create your class and present it back to you ready for you to start editing!


If you want to see a quick from zero to Domain class demo check out my demo video below. Thanks again Joe for such a great community tool and providing great support for it!

12 thoughts on “MavensMate Templates and Apex Enterprise Patterns

  1. Hi Andrew Fawcett,

    Using metadata api how to get all custom objects an custom fields in a pageblock table Dynamically?

    please help me………

    • Wow thats going to be a big page! Are you rewriting the standard Salesforce Setup menu and pages? Anyway, you don’t need to use Metadata API for this, the standard Apex Describe feature in Apex will work for this. Just look for Apex Describe in the Apex Developers Guide.

      • Hi Andrew Fawcett,

        Using schema methods i retrieved all custom objects.I try to delete object purpose i was using metadata api like below

        public PageReference doDelete(){
        List myCustomObjectList = new List();
        MetadataService.MetadataPort service = createService();
        for(objWrapper s:lstwrap ){

        MetadataService.CustomObject customObject = new MetadataService.CustomObject();
        customObject.fullName = ‘rajesh__’+ s.objName;
        System.debug(‘********del fullName******’+customObject.fullName);
        MetadataService.AsyncResult[] results = service.deleteMetadata(myCustomObjectList);
        return null;

        I try to delete but i got following error

        System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: EXCEEDED_ID_LIMIT: record limit reached. cannot submit more than 10 records in this operation faultcode=sf:EXCEEDED_ID_LIMIT faultactor=
        Error is in expression ‘{!doDelete}’ in page rajesh:customobjectlist

        Class.rajesh.MetadataService.MetadataPort.deleteMetadata: line 8470, column 1
        Class.rajesh.CustomObjectList.doDelete: line 59, column 1

        how to add schema methods related custom object list to my custom object list(Related to metadata api)

        please help me……………….

      • Hello again! 🙂

        Firstly, please can you post comments on related blog posts, this blog post is not related to Metadata API. I also please strongly request that you post new questions on the Apex Metadata API GitHub issues, my blog is not really for continous Q&A / forum discusison as we seem to be having. Please post new questions here…

        Secondly, I will answer this question, this one time here… As I have have had said before this is a documented limit in the Metadata API you cannot send more than 10 items at once. You will have to break up the calls passing no more than 10 at a time. Maxmimum this way would be 100 items (as you can only make 10 callouts). If you need even more than this consider Batch Apex.

  2. Hi Andrew Fawcett,
    Actually i am new in IT,Sorry again i don’t post

    thank you for replys

  3. Hi Andrew,
    I find your blogs, post on stackexchange very useful.

    I am using Mavensmate for a few weeks. What i found was there is no way to check the code history like it used to be in eclipse. May be i missed that feature in Mavensmate. Or is it possible to have a repo integrated with mavensmate so that when i do a successful compilation of a apex code, it gets auto-committed to repo.

    Request you to guide me on this.

    • Thank you for your kind words! It’s not an area I am familiar with tbh, but I think maven does have git integration, try googling for it.

  4. Any advice for how to implement these templates now that mavensmate has been discontinued. Anyone know of a VSCode version?

  5. Pingback: Awesome Salesforce – Massive Collection of Resources – You Ever Wondered To Get – Learn Practice & Share

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s