function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Semira@gmail.comSemira@gmail.com 

Using Aura, getting System.StringException: Invalid id: undefined

Hi all, 

This is kind of urgent. I'm using a Aura component and trying to pass an ID to a apex code. However, without using the aura, in classic, my code works like a charm. When I try to pass the value via aura, it does not. 

Below is my Aura Controller which is setting the URL. 
myAction : function(component, event, helper) {
        debugger;
		var action = component.get("c.getOpportunity");
        action.setParams({"OppId": component.get("v.recordId")});
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state == "SUCCESS"){
                var elem = response.getReturnValue();
                var redirectURL = "/apex/SubmitForApproval?id=" + elem.id;
                redirectURL += "&lock=0";
                
                var urlEvent = $A.get("e.force:navigateToURL");
                urlEvent.setParams({
                  "url": redirectURL
                });
                urlEvent.fire();
            } else {
                component.set("v.hasErrors", true);
                
            }
        });
        $A.enqueueAction(action);
	},

Below is my existing Apex code trying to modify:
public without sharing class SubmitForApprovalExtension {
    public Id objId { get; set; }
    public String doLock { get; set; }
    public SubmitForApprovalExtension(){

//below line is where I'm getting the error for objId
        objId = ApexPages.currentPage().getParameters().get('id');
        doLock = Apexpages.currentPage().getParameters().get('lock');
    }
    
-
-
-
-
-

//enabling the Aura controller

@AuraEnabled
    public static Opportunity getOpportunity(String OppId){
        Opportunity opp = [select Id from opportunity where Id =: OppId limit 1];
        return opp;
    }
}

I'm getting error message saying System.StringException: Invalid id: undefined. I have no idea what it means Undefined. When I put in the actualy Id of the record, it works fine.. Just the ApexPages.currentPage() will not work. Please help!!! 
 
Best Answer chosen by Semira@gmail.com
SScholtzSScholtz
When you say you're "using the aura", I'm assuming you're referring to Lightning Experience?

By "undefined", it sounds like your query string parameter is not surviving the transition from your component to your VF page, either because Lightning is mangling the URL, or your component is not getting back a valid id from your "getOpportunity" function, or something else.

In your component javascript code, double check that elem.id is actually returning a valid value.  Also, double check the contents of elem with a console.log('CHECK: elem = ' + JSON.stringify(elem)) call and look in your browser's javascript console at the result.  Javascript is case sensitive, while Apex is not.  What I suspect is happening is that elem.id (lowercase "i") is null, but elem.Id (capital "I") has the value you're looking for.  Try making that change and see if it works.

All Answers

SScholtzSScholtz
When you say you're "using the aura", I'm assuming you're referring to Lightning Experience?

By "undefined", it sounds like your query string parameter is not surviving the transition from your component to your VF page, either because Lightning is mangling the URL, or your component is not getting back a valid id from your "getOpportunity" function, or something else.

In your component javascript code, double check that elem.id is actually returning a valid value.  Also, double check the contents of elem with a console.log('CHECK: elem = ' + JSON.stringify(elem)) call and look in your browser's javascript console at the result.  Javascript is case sensitive, while Apex is not.  What I suspect is happening is that elem.id (lowercase "i") is null, but elem.Id (capital "I") has the value you're looking for.  Try making that change and see if it works.
This was selected as the best answer
rajat Maheshwari 6rajat Maheshwari 6

Hi Semira,

As per your error, I would like to suggest that, In your javascript,  var elem = response.getReturnValue();   It returns string .

Please give a try to check the returnType of elem.

Thanks
Rajat Maheshwari
rajatzmaheshwari@gmail.com

 

Semira@gmail.comSemira@gmail.com
Thank you. It was one of the syntex error I had.