0

So I created for te first time a lightning component and I'm just getting familiar with it all. What I did was create the apex controller, the lightning component, the js contoller and the js helper.

What I want is once the method is executed and the email sent, we display it in the component via the 'v.sendstatus'.

But the "component.set("v.sendstatus","Sent successfully")" seems to never be working which I don't understand why. At first I thought maybe there's something wrong with the callback function but even when alone right after it, nothing still. (Btw I would appreciate it if you let me know wether the if and else are correct?)

The code is actually working once I use the component I get the popup which is blank (the problem I'm facing) however the email gets sent with no problem.

So my thought are that this line "component.set("v.sendstatus","Sent successfully")" is the problem but that's the syntax I find people use. But maybe I'm not using correctly? I would really appreciate your help thank you

For the Apex controller:

public class EmailManager {
    @AuraEnabled
    public static void getsendEmail(String receiverid, String subject, String body) {
    // Code here
}}

Light.Component:

<aura:component controller="EmailManager" implements='force:lightningQuickActionWithoutHeader,force:hasRecordId'>

   <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> 
   <aura:attribute name="recordId" type="Id" />
   <p>{!v.sendstatus}</p>

</aura:component>

JS Controller: ({ doInit : function(component, event, helper) { helper.sendemail(component); } })

JS Helper:

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

    var action = component.get("c.getsendEmail");
    action.setParams({
        "receiverid": component.get("v.recordId"),
        "subject" : "subject",
        "body": "body"
    });
//  component.set("v.sendstatus","Sent successfully"); not working

    action.setCallback(this, function(actionResult) {
        var state = actionResult.getState();
        if(state == 'SUCCESS') {
            component.set('v.sendstatus',"Sent successfully");
        } else if(state == 'ERROR') {
            component.set('v.sendstatus',"An error has occured");
            console.error(actionResult.getError());
        } else {
            console.log("something went wrong!");
        }
    });

    $A.enqueueAction(action); 
        }
})
  • Have you checked your Javascript Developer Console? Maybe you have some problem inside the javascript callback function and that code can not be compiled and because of that, the code is not executed – Patlatus Apr 18 at 11:35
  • @Patlatus Actually I checked commenting that callback and using only the set.component alone but still it didn't work – dotname Apr 18 at 11:37
0

You need to define sendstatus as an attribute:

<aura:attribute name="sendstatus" type="String" />

Also, it is recommended that you do not define a recordId attribute when using force:hasRecordId, as this may cause problems. You should consider removing this attribute from your component markup.

  • I made the modification but still nothing, does the parameter name should only have sendstatus? I also erased the the recordId as instructed but still nothing? – dotname Apr 18 at 11:53
  • @dotname Anything in the browser's developer console? You have lots of debug messages, I presume something should show up there. – sfdcfox Apr 18 at 11:57
  • I actually didn't find anything in the console it looks like the callback isn't working. When I added a console.log() before it did show up though. But I'm not sure why the component wasn't set either sinc I uncommented this line "// component.set("v.sendstatus","Sent successfully"); " Is the syntax correct? – dotname Apr 18 at 14:39
  • @dotname Yes, that's the correct syntax. Not sure what else to tell you. – sfdcfox Apr 18 at 14:43
  • my bad I just realized that I had forgotten to uncomment the line where v.sendstatus was after a previous attempt. It's working now, thank you – dotname Apr 18 at 16:13
1

You have to create <aura:attribute> in your Lightning component.

<aura:attribute type="String" name="sendstatus"/>
  • I did the modification but there was no change still nothing is displayed – dotname Apr 18 at 11:55

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.