You need to sign in to do that
Don't have an account?
Semira@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.
Below is my existing Apex code trying to modify:
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!!!
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!!!
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
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.
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