Im trying to create a group in a chattool using aura component in salesforce. when i run the code for creating a group in developer console it runs fine. But i want to to execute when user press a button in the aura component on salesforce following is the code i tried.


public with sharing class ChatWorkOperation {
    public static String CreateGroup(){
        string result;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        HttpResponse response = http.send(request);
        Integer status = response.getStatusCode ();
        result = 'Success';
        return result;



<aura:component controller="ChatWorkOperation" implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global">
<lightning:button label="Group_Create"
                onclick="{!c. creategroupbutton}"/>


    creategroupbutton : function(component, event, helper) {
        var action = component.get("c.CreateGroup");

Can anyone guide me where Im going wrong?

  • If the API version of the apex class is set to an older version, try upgrading to latest version or changing to any other version – Raul Mar 29 at 7:51
  • Just checked its 51 – Tejas Mar 29 at 7:55
  • What are you trying to do with action.set? – Sachin Hooda Mar 29 at 10:41
  • trying to disable the button once pressed. – Tejas Mar 29 at 11:16

I can see that you are not setting the callback for the Apex Action Call. And Also, you are setting the disabled attribute to the wrong element.

Use the below code for the JavaScript Controller

creategroupbutton : function(component, event, helper) {
    var action = component.get("c.CreateGroup");
    component.set('v.disabled', true);
    action.setCallback(this, function(response) {
        var state = response.getState();
        if (state === "SUCCESS") {
            alert("From server: " + response.getReturnValue());
        else if (state === "INCOMPLETE") {
            component.set('v.disabled', false);
        }else if (state === "ERROR") {
            // enable the button if there is any error.
            component.set('v.disabled', false);
            var errors = response.getError();
            if (errors) {
                if (errors[0] && errors[0].message) {
                    console.log("Error message: " + errors[0].message);
            } else {
                console.log("Unknown error");

To disable the button once clicked please use the below code

<aura:component controller="ChatWorkOperation"  impl

ements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes" access="global">
<aura:attribute name="disabled" type="Boolean" default="false"/>
<lightning:button label="Group_Create"

Let us know if this works.


To set an attribute on a component, use component.set, not action.set:

component.set("v.disabled", true);

Note that you haven't set the callback handler, so you have no way to tell if the call failed or not.

  • Thank you so much @sfdcfox – Tejas Mar 30 at 7:40

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.