What are server side controllers in Lightning Component and how to use server-side controllers?

In this blog post, we will learn about Server side controllers. After we have created a server-side controller in Apex, we can use @AuraEnabled annotation to enable client and server side access to the controller method.

The methods on which you have used @AuraEnabled annotation will be exposed. These server-side actions are not counted against your org’s API limits. But your server-side controller actions in Apex are subject to all the usual Apex limits.

For e.g.:

[sourcecode lang=”Java”]

public with sharing class ServerSideControllerExample{

@AuraEnabled

public static string helloWorld(String name)

{

return (‘Hello from the server, ‘+name)

}
}

[/sourcecode]

 

Whenever you are using @AuraEnabled annotation, your Apex controller should follow some additional guidelines:

  • Methods should be static and also should be marked as public or global. Non-static methods are not supported
  • If a method returns an Object, then instance methods which retrieve the value of the object’s instance field must be public.

How to create an Apex Server Side Controller?

Below are the steps to create Apex Server Controller.

Step 1: Open the Developer Console in Salesforce.

Step 2:Go to File|New|Apex Class.

Step 3: Enter the name of  your server side controller.

Step 4: Click Ok

Step 5: Create a method for each server-side action in the body of the class.

Step 6: Go to  File| Save

Step 7: Open the component which you want to wire to the new Controller class.

Step 8: Use the controller attribute of the <aura:component> tag to wire the component to the controller.

<aura: component controller=”ServerSideControllerExample“>

 

To learn more

This Post Has 17 Comments

  1. contractorhef

    General service provider New York

    The job of General building and construction manhattan is actually to transfer to the client the whole entire establishment overall, and certainly not such as individually conducted job. Of specific relevance is the role of the standard contractor in the course of the massive development of apartment buildings of home kind, commercial facilities, business locations.

    [b][url=https://grandeurhillsgroup.com/]new construction nyc[/url];[/b]
    [u]Industrial structures.[/u]

    Today, the listing of building companies features various corporate interior design. An client and a customer can invest a great deal of time-solving on all organizational concerns. A additional logical service is to leave this duty to General construction NY.

  2. berkey

    We’re a group of volunteers and starting a new scheme in our community. Your web site offered us with helpful info to work on. You’ve done an impressive process and our whole community shall be thankful to you.|

  3. Efren Simard

    i love to use stainless steel hot tubs at home because they require less maintennance and easy to maintain::

  4. Nguyet Skotnicki

    Nice blog here! Additionally your website so much up fast! What web host are you using? Can I get your affiliate link in your host? I desire my website loaded up as fast as yours lol.

  5. Dirk Clayburg

    Well, this Thursday I read through a couple of your posts. I must say this is one of your better ones. ..

  6. There are a couple of interesting points with time in this posting but I do not know if I see these people center to heart. There exists some validity but I’m going to take hold opinion until I check into it further. Great write-up , thanks and we want a lot more! Included with FeedBurner as well

  7. Flavia Lacombe

    I like the helpful information you provide in your articles. I will bookmark your blog and check again here regularly. I am quite sure I’ll learn a lot of new stuff right here! Best of luck for the next!

  8. Jimmie Sugden

    Good Work on your latest blog post. I have been checking for additional data on this topic for quite some time now.

  9. feed

    Piece of writing writing is also a excitement, if you know after that you can write otherwise it is complicated to write.|

  10. thefeed

    Amazing blog! Do you have any tips for aspiring writers? I’m hoping to start my own website soon but I’m a little lost on everything. Would you suggest starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m completely confused .. Any recommendations? Many thanks!|

  11. the feed

    Hi there! Do you know if they make any plugins to help with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good gains. If you know of any please share. Cheers!|

  12. the feed

    Great post. I was checking continuously this blog and I am impressed! Extremely useful information particularly the last part 🙂 I care for such information much. I was looking for this certain info for a very long time. Thank you and good luck.|

  13. JoshuaMurdy

    [b]Nuru Massage Erotic: [url=http://nuru-massage-ny.com]body rub websites[/url][/b]

    Hello! Our firm those who make your life much easier . Our organization that gives you massage .

    Characteristic quality our Honey salon is not an enforced setting. We create sites to develop.
    Provide for you personally check some method massage methods today. We are always looking forward to you personally in our SPA.

  14. JoshuaMurdy

    [b]Nuru Massage: [url=http://nuru-massage-ny.com]four hands massage manhattan[/url][/b]

    We greet you! Our employees firms those who make your current daily life easier. We are a company that gives you massage .

    Special property our erotic salon is not an enforced setting. We search promotion social profiles to create.
    Introduce for you personally check different type massage methods now. Go to service and clear up subtleties of massage.

  15. econub

    [b][url=https://eco-corporation.ru]Септики для дома без откачки[/url][/b]

    Автономная канализация – наиболее востребованная часть технических коммуникаций
    Автономная канализация цена под ключ-это сегодня наш профиль
    Высококачественное сопровождение
    Автономная канализация в частном помещении – лучший выбор от компанииСборка септика – изрядно непростой процесс, предполагающий не только лишь строительство, но и дополнительно выбор нужной системы.
    Для вас мы предлагаем высококлассные сервис по монтажу автономной канализации под ключ, владеем исключительной методикой и частным подходом к работе.

  16. econub

    [b][url=https://eco-corporation.ru]Установка септика цена[/url][/b]

    Автономная канализация цена под ключ-это сегодня наш профиль
    Большой уровень производства септиков
    Автономная канализация в частном помещении – лучший выбор от компанииСборка септика – изрядно непростой процесс, предполагающий не только лишь строительство, но и дополнительно выбор нужной системы.
    Высококачественное сопровождение
    Автономная канализация – наиболее востребованная часть технических коммуникаций

  17. Greetings from Idaho! I’m bored to death at work so I decided to browse your blog on my iphone during lunch break. I love the knowledge you provide here and can’t wait to take a look when I get home. I’m amazed at how fast your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyhow, awesome blog!|

Leave a Reply