1

Hello I am trying to make a Lightning component common to Community and SF1 . This component has been added as quick action on one of the object detail page.

Now when i am using the toast event, it gives me error as

Something has gone wrong. [TypeError: Cannot read property 'setParams' of undefined] . Please try again.

Code for same -

action.setCallback(this, function(response) {
            var state = response.getState();
            console.log('state--->1', state);
            if (state === 'SUCCESS') {
                jobApplicantId = response.getReturnValue();
                fromPos = toPos;
                console.log('fileContents.length -->', fileContents.length);
                toPos = Math.min(fileContents.length, fromPos + CHUNK_SIZE);
                console.log('fromPos -->' , fromPos);
                console.log('toPos -->' , toPos);

                if (fromPos < toPos) {
                    this.uploadChunk(component, file, fileContents, fromPos, toPos, attachId);  
                } else if (fromPos == toPos) {
                    //alert('Job Application Successful');
                    var toastEvent = $A.get("e.force:showToast");
                    console.log('toastEvent -->', toastEvent);
                    toastEvent.setParams({
                        "title": "Success!",
                        "message": "The record has been updated successfully."
                    });
                    toastEvent.fire();
                    component.find("comments").set("v.value", "");
                    component.find("file").getElement().value = "";
                    this.displayJobAppliedButton(component);
                    //component.find("file").getElement().removeAttribute('value');
                }
            } else {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        alert("Error message: " + 
                                 errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }

        });

Snapshot - enter image description here This whole thing is in a helper class? can this be the issue?

8
  • Is this inside SF1 app or community builder? Jun 21, 2016 at 11:23
  • I am trying this in SF1
    – SEuser
    Jun 21, 2016 at 11:27
  • What type of org it is ?Summer 16 or spring org with locker enabled ? Jun 21, 2016 at 11:29
  • @MohithShrivastava I checked something else. It looks like $A related metehods are not working in SF1 which is working in Community lightning component. Is there any restrcition around that? I tried $A.util.addClass() method and it seems to be failing
    – SEuser
    Jun 21, 2016 at 11:30
  • Summer 16 but Locker not enabled
    – SEuser
    Jun 21, 2016 at 11:31

1 Answer 1

3

From the description and image ,I see that you are using Lightning components inside the Visualforce page . Having lightning components inside the visualforce ,you will loose certain events as documented in the guide .The events that are not supported are as below

1.force:createRecord

2.force:editRecord

3.force:navigateToList

4.force:navigateToObjectHome

5.force:navigateToRelatedList

6.force:showToast

Official Documentation On Toast event

I think you should open an Idea on Idea Exchange to support lightning components directly from publisher actions .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .