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
Suman KunduSuman Kundu 

Error found "StringException: invalid id: " when ajax is being called

I have created a VFPage where I have code a line like:

<apex:inputHidden id="chosenItemId" value="{!cItemId}"/>

 

Here cItemId which is a variable of Id type, is defined in controller like

public Id cItemId{get; set;}

 

In the controller's contructor, I haven't assigned any value to it.

Now in page, whenever ajax is called, salesforce tries to assign(set) its value with blank character. And this makes all the problem because it tries to validate Id pattern with blank character.

 

So what I do in this scenario?

kiranmutturukiranmutturu

y not u convert that as a string then? make that as a string property and try

Andy BoettcherAndy Boettcher

You can set your Id variable as "null" instead of a blank character ("") as well.

Suman KunduSuman Kundu

If I would assign it null in constructor, it will be treated same way in page. I have already tried that, but didn't work.

Suman KunduSuman Kundu

But I need to capture an id.

Andy BoettcherAndy Boettcher

Bah!  Oh well, good try.  Flip it to a string (previous post) and you'll be set.

 

Typically as a rule of thumb - unless I have a very good reason to have Id/Double/other non-string primitive passing between the Page and Controller - I set it all to strings.  If I need to cast it into another data type for processing in the Controller - do it there.

 

-Andy

Suman KunduSuman Kundu

Thanks for advising to use String instead of Id type.

It is working fine. What I have done for temporary fixing, I was initialyzing id variable with some arbitary Id value of the object's pattern. Which was working too, but that was really very bad solution.