-3

I want to use aura enabled method. How can I do it? Input-ID event id Output-void Process - update "Escalation Date/Time" with current date

closed as unclear what you're asking by glls, David Reed, battery.cord, Derek F, Oleksandr Berehovskyi Aug 29 '18 at 13:52

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Could you please add more details like on which object you want to perform the operation and what's the logic and all? – Abhishek Daware Aug 29 '18 at 11:57
  • Have you looked at the documentation on Lightning Apex Server-Side Controllers? That's a good place to start. For a question to fit the SFSE format, it needs to be specific and detailed. – David Reed Aug 29 '18 at 12:48
  • I've downvoted this question because it does not show an effort to research your question before it was asked. – Derek F Aug 29 '18 at 13:51
  • @AuraEnabled public static void updateEscalationDateTime(Id eventId) { SObject evnt = [SELECT Id, Escalation__c FROM Event WHERE Id = :eventId]; Event e = new Event (Id=eventId); update evnt; } This is what I was trying but problem is that already I have event id and I just want when I am clicking Escalate button update "Escalation Date/Time" with current date/tme – Archana Jaladi Aug 30 '18 at 18:32
1

Things to keep in mind:

  1. The methods in your Apex controller must have @AuraEnabled annotation, and must be static.
  2. Include your apex controller in component markup.
  3. The name of your Controller JS method and apex method must be different.

Here is how:

Apex Controller:

public with sharing class MyApexController {

    //@AuraEnabled AND static ARE REQUIRED
    @AuraEnabled
    public static void updateEscalationDateTime(Id eventId) {
        SObject o = [SELECT Id, Escalation_Date_Time__c FROM Event__c WHERE EventId__c = :eventId];
        o.Escalation_Date_Time__c = System.now();
        update o;
    }
}

Component Markup:

<aura:component controller="MyApexController">
    <aura:attribute name="eventId" type="String" default="0KK31j0085001R2N"/>
    <!-- YOUR MARKUP -->
</aura:component>

Controller JS:

modifyEscalationDateTime: function(component, event, helper){
    try{
        //THIS IS HOW YOU CREATE/DECLARE/DEFINE YOUR APEX METHOD THAT WILL EVENTUALLY BE ENQUEUED TO BE EXECUTED
        var action = component.get('c.updateEscalationDateTime'); 

        //GET eventId FROM COMPONENT
        var myEventId = component.get('v.eventId');

        //THIS IS HOW YOU PASS PARAMETERS TO YOUR APEX METHOD 
        action.setParams({
            'eventId': myEventId
        });

        //DEFINE WHAT SHOULD HAPPEN AFTER SERVER-SIDE CALL RETURNS
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(component.isValid() && state === "SUCCESS")
                console.log('-------> Escalation Date/Time successfully updated'); 
            else 
                console.log('-------> Failed to update Escalation Date/Time!');
        });

        //DON'T FORGET TO ENQUEUE YOUR ACTION
        $A.enqueueAction(action);
    } catch(err){
        console.log('-------> ERROR: ' + err + ' ** MESSAGE: ' + err.message + ' ** STACK: ' + err.stack);
    }
},
  • @AuraEnabled public static void updateEscalationDateTime(Id eventId) { SObject evnt = [SELECT Id, Escalation__c FROM Event WHERE Id = :eventId]; Event e = new Event (Id=eventId); update evnt; } This is what I was trying but problem is that already I have event id and I just want when I am clicking Escalate button update "Escalation Date/Time" with current date/tme – Archana Jaladi Aug 30 '18 at 18:27
  • Are you saying that eventId already exists in your component, but is not being passed to your apex controller upon clicking that Escalate button? Have you tried putting a debug statement in the first line of your apex controller: system.debug(logginglevel.ERROR, '-------> ' + eventId); and see if it show up in debug log? And also, just before calling your server-side action, in your ControllerJS, try printing the eventId like so: console.log('-------> ' + myEventId); as see if it shows up in your browser logs? – Lightning Evangelist Aug 30 '18 at 18:44
  • Thanks for the support much appreciated I am sorry I am new in the system so very difficult to understand the issues Only having problem on apex controller SObject evnt = [SELECT Id, Escalation__c FROM Event WHERE Id = :eventId]; Already I have event id , Can I use like this Event e = new Event(); Escalation__c=new update date – Archana Jaladi Aug 30 '18 at 19:39
  • Are you asking how to update an Event object given its id? If so, try something like this: Event e = new Event(Id = eventId, Escalation__c = System.now()); update e; – Lightning Evangelist Aug 30 '18 at 19:49
  • Its working now....Thank you for your response to my query. I appreciate the information you have provided me with and I appreciate the prompt reply. – Archana Jaladi Aug 30 '18 at 20:22

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