Error: Remote action function is not defined

  • 1
  • Question
  • Updated 4 years ago
Remote action function is working for existing records, but it's not working for the new records. Getting an error saying that remote action function is not defined.
Photo of Goutham J

Goutham J

  • 568 Points 500 badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Can you post a screenshot of the error you are getting,  and describe what steps the user is taking, what the expected outcome would be and what actually happens? 

Thanks. 
Photo of Goutham J

Goutham J

  • 568 Points 500 badge 2x thumb
Yeah Sure Rob, Here is the Screenshot.

Step1: I am trying to create a new "Event" record and I am having an action 'snippet' which does the 'Save' for me. It is throwing me an error saying that remote action function is not defined. In this case I am expecting to create a "Event" record.

  

Step 2: When I was trying to edit the existing "Event" record it works. Here I am using the same snippet to do the 'Save' action for. (I mean I am using the remote action function which i was using in step1.)
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Can you post your full snippet?
Photo of Goutham J

Goutham J

  • 568 Points 500 badge 2x thumb
Here it is,

skuid.snippet.registerSnippet('save.Event', function() {    var params = arguments[0],
        model = params.model,
        editor = params.component.element.editor,
        row = params.row,
        $ = skuid.$;

    var requiredFieldsEntered = validateRequiredFields(model, editor);
    if(!requiredFieldsEntered) {return false;}

    var eventId = row.EventID__c === undefined ? null : row.EventID__c;
    OdataExtension.saveEvent(
        eventId,
        JSON.stringify(row),
        function(result, event) {
            console.log(event.status);
            if(event.type === 'exception') {
                console.log("exception");
                console.log(event);
                return false;
            } else if(event.status) {
                console.log('Save successful: ' + result);
                console.log(changedRows);
            } else {
                console.log(event.message);
            }
        }
    );
});
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Where is "OdataExtension" coming from? Is that another snippet on your page? I don't see it defined in this snippet... 
Photo of Goutham J

Goutham J

  • 568 Points 500 badge 2x thumb
Sorry my bad, OdataExtension is nothing but a apex class. where I am having some RET calls going on.

Here is the piece of code for that,

@RemoteAction    global static String saveEvent(String recordGuid, String jsonString) {
Boolean isNewRecord = Guid.isEmpty(recordGuid);
        recordGuid = isNewRecord ? Guid.createGuid() : recordGuid;
        
        jsonString = jsonString.replace('__c', '');
EventMastering.Event event = (EventMastering.Event)JSON.deserialize(jsonString, EventMastering.Event.class);
event.EventID = recordGuid;
System.debug(event);

        buildHttpRequest('POST', EVENTS_ENDPOINT, isNewRecord, recordGuid, JSON.serialize(event));
        
        return recordGuid;
    }


GUID: Is also one of the apex class I have, here is the logic behind the GUID.

global class Guid {    global static Boolean isEmpty(String guid) {
        return guid == null || guid == '00000000-0000-0000-0000-000000000000';
    }
    
    global static String createGuid() {
        Blob b = Crypto.GenerateAESKey(128);
        String h = EncodingUtil.ConvertToHex(b);
        String guid = h.SubString(0,8) 
            + '-' + h.SubString(8,12) 
            + '-' + h.SubString(12,16) 
            + '-' + h.SubString(16,20) 
            + '-' + h.substring(20);
        
        return guid; 
    }
}


Thanks,
Goutham