1

I am creating an input form using Lightning component. Based on the data entered by the user in the form, a case should be created in Salesforce. Unfortunately, when I hit the submit button, nothing happens.

Here is my component code where I have the form fields:

    <aura:component implements="forceCommunity:availableForAllPageTypes" 
      access="global" >

      <aura:attribute name="case" type="Case"/>


    <aura:attribute name="newCaseObject" type="Case" default="{ 'sobjectType': 'Case',
                                                                'Email_Address__c': '',
                                                                'Title_of_Event__c': '',
                                                                'Requester_Last_Name__c': '',
                                                                'Requester_First_Name__c': '',
                                                                'Name_of_the_Organization__c': '',
                                                                'Mission_Element__c': 'No',
                                                                'Which_Mission_Element__c': '',

 'OwnerId': '005f4000003STS2',

 'Status': 'New'

     }"/>



    <lightning:input aura:id="emailaddress" label="Email Address"
                             name="eventname"
                             value="{!v.newCaseObject.Email_Address__c}"
                             required="true"/> 
    <br></br>

    <lightning:input aura:id="titleofevent" label="Title of Event(for example: Boy
                                                  Scout Jamboree"
                             name="eventname"
                             value="{!v.newCaseObject.Title_of_Event__c}"
                             required="true"/> 
    <br></br>

     <lightning:input aura:id="requesterlastname" label="Requester Last Name"
                             name="eventname"
                             value="{!v.newCaseObject.Requester_Last_Name__c}"
                             required="true"/> 
    <br></br>

     <lightning:input aura:id="requesterfirstname" label="Requester First Name"
                             name="eventname"
                             value="{!v.newCaseObject.Requester_First_Name__c}"
                             required="true"/>
    <br></br>

     <lightning:input aura:id="nameoftheorganization" label="Name of Organization requesting the event(if any)"
                             name="eventname"
                             value="{!v.newCaseObject.Name_of_the_Organization__c}"
                             required="true"/> 
    <br></br>


      <lightning:select aura:id="ismissionelement" name="ismissionelement" required="true" label="Is this event being requested by a Mission Element-
      value="{!v.newCaseObject.Mission_Element__c }">
              <option value="No">No</option>
              <option value="Yes">Yes</option>
      </lightning:select>
    <br></br>



       <aura:if isTrue="{!v.newCaseObject.Mission_Element__c == 'Yes' }">
           <lightning:input aura:id="whichmissionelement" label="Which Mission Element?" name="eventname" value="{!v.newCaseObject.Which_Mission_Element__c}" required="true"/>
       </aura:if>

    <br></br>

       <ui:button label="Submit" class="slds-button slds-button--neutral" 
      labelClass="label" press="{!c.createCase}"/>




     </aura:component>

Here is the Javascript controller:

    ({
    createCase : function(component, event, helper) {

    var emailAddress = component.find("emailaddress");
    var Email =  emailAddress.get("v.value");

    var titleOfEvent = component.find("titleofevent");
    var TitleOfEvent =  titleOfEvent.get("v.value");

    var requesterLastName = component.find("requesterlastname");
    var LastName =  requesterLastName.get("v.value");

    var requesterFirstName = component.find("requesterfirstname");
    var FirstName =  requesterFirstName.get("v.value");

    var nameOfTheOrganization = component.find("nameoftheorganization");
    var NameOfTheOrganization =  nameOfTheOrganization.get("v.value");

    var isMissionelement = component.find("isUSAFAmissionelement");
    var IsMissionElement =  isMissionelement.get("v.value");

    var whichMissionElement   = component.find("whichmissionelement");
    var WhichMissionElement =  whichMissionElement.get("v.value"); 


    var newCase = component.get("v.newCaseObject");
    console.log("Create Case: " + JSON.stringify(newCase));


    helper.createCase(component, JSON.stringify(newCase));



}

})

Here is my helper class:

 ({

    createCase: function(component, Case) {

        console.log('inside helper');




    var action = component.get("c.saveCase");

        console.log('after method called ');

    action.setParams({

        "Case": Case



    });

    action.setCallback(this, function(response){

        var state = response.getState();

        if (component.isValid() && state === "SUCCESS") {

            var Case = component.get("v.Case");

            Case.push(response.getReturnValue());

            component.set("v.Case", Case);




        }

    });

    $A.enqueueAction(action);

},



})

Here is my Apex Controller class:

  public with sharing class caseCreationController {

    @AuraEnabled
    public static Case saveCase(String caseJSON) {

        Case newCase = (Case)JSON.deserialize(caseJSON, Case.class);
        insert newcase;
        return newcase;
    }
}
  • 2
    Most of your code is useless and should be omitted, the remainder has problems with case sensitivity (e.g. "v.Case" is not the same as "v.case"). In addition, you'll need to figure out exactly what the problem is before we could really help you. "Nothing happens" is not a proper description of a problem. Did you check the Developer Console? Did you check your Apex logs? Something happened, even though you might not have observed anything on your screen. – sfdcfox Nov 21 '18 at 17:14
  • Adding -> Did you check your JS console? – Sebastian Kessel Nov 21 '18 at 17:28

Your Answer

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

Browse other questions tagged or ask your own question.