0

I was reading few articles about Apex Template and after reading everything I really doubt that Apex template is useful. Because as per template concept, if there is repetitive statements or code in application then we just right a common code in template and then just reuse that code in entire application by just writing few lines of code to call template.

In Salesforce, what I understood is we just write few lines of code in Template and writing its definition in every page(wherever we are using that template). I don't see any advantage of using Salesforce template.

Please correct me if I misunderstood.

Thanks

1

In addition to a Visualforce Template, there's also the VisualForce Component which is reusable code that can be used generically in many different circumstances for different objects. In a Visualforce context, what templates do more than anything, is provide a structure for a page. When you repetitively use a specific page that you want to be consistent, you definitely want to follow a template. They're also helpful for convenience when it comes to creating different kinds of pages that follow a specific pattern you want to be able to recreate whenever you do one.

Where templates particularly shine is with other Apex. They're very useful for creating Triggers, and different kinds of classes. I have specific ones for Test Classes, Batch Classes, Queueables, Schedulables, Custom Controllers, Controller Extensions, etc. They come in very handy to help set things up for how the code needs to be structure for these very different uses of code.

3

Visualforce templates are used in: 1. Communities: for example in the communities all the pages have same header and footer (say branding), then we can use vf template which will have only the header and footer and then use this template in all the community pages. 2. It is used for reusing the vf code and related apex code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.