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
pjaenick.ax736pjaenick.ax736 

Issue with passing a Null id from form to controller

Relatively new to VF - begging some guidance please :

I have a custom obj that relates to itself (contact call logs, can relate one call to a prior)

If the user (on call (C)) selects to associate prior call (B) that itself has a prior call (A), logic should take then associate (C) to (A).  (A)'s id is inserted into the lookup field of record (C).  This works fine.

What doesn't work is when (B) has no prior call.  I get a "System.TypeException: Invalid id value for this SObject type"

Here's the VF page section where I'm passing both the "ParentTo" and "ParentsParent" id's :
(can I do the null check right here in the VF page and pass a single value?)

<apex:commandButton value="Associate" action="{!Associate}" rerender="all”>
    <apex:param name="Parent" value="{!prior.id}" assignTo="{!Parent}"/>
    <apex:param name="ParentsParent" value="{!prior.First_call__c}" assignTo="{!ParentsParent}"/>
</apex:commandButton>

Controller excerpt:
91        if(ParentsParent != null) {
92            call__c ParentCall = new call__c(id=ParentsParent);

Line [92] produces the error, even though (I thought) the null-check should have avoided this line entirely.

Thanks for any assistance
Best Answer chosen by pjaenick.ax736
pjaenick.ax736pjaenick.ax736
"Would it be possible to avoid all this and instead do the null check right within page logic?  - only pass a single non-null id to the controller method."

Heh, this solved it :)  Removed the two "param name" passes above with the singular :

<apex:param name="Parent" value="{!IF(ISBLANK(prior.First_call__c),prior.id,prior.First_call__c)}" assignTo="{!Parent}"/>

For academic purposes, I still would love to know the cause of my intiial trouble.

Thanks!
Pete

All Answers

Phillip SouthernPhillip Southern
With the error message being sobject type...that makes me think the Id you are assigning is not of type call__c object.  Is that possible?  Also assuming first_call__c is a lookup field correct?
pjaenick.ax736pjaenick.ax736
I suppose technically, it's of type Call__r.call__c object, since I'm trying to pull in the selected row's lookup value to another row, (which fails if blank, succeeds if it actually contains an Id).

Yes, it is a lookup field.

Thank you.
Phillip SouthernPhillip Southern
For the times it fails, if you do a system.debug....what are you seeing as the value?
pjaenick.ax736pjaenick.ax736
system.debug('>>>>> ParentsParent = >' + ParentsParent + '<');

produces
>>>>>> ParentsParent = ><

(seemingly null, but it passes the null check in the preceding line).
Phillip SouthernPhillip Southern
Are you instantiating parentsparent anywhere else in the controller?
pjaenick.ax736pjaenick.ax736
Yes -

    public Id ParentsParent {get; set;}  
Vamsi KrishnaVamsi Krishna
try changing the condition
if(ParentsParent != null && ParentsParent != '')
pjaenick.ax736pjaenick.ax736
This produces an error.  I've isolated it to the empty-string check :

91      if(ParentsParent != '') {

System.StringException: Invalid id:
Error is in expression '{!Associate}' in component <apex:commandButton> in page call

Class.CallController.associate: line 91, column 1

-------------------------

Would it be possible to avoid all this and instead do the null check right within page logic?  - only pass a single non-null id to the controller method.

In other words, if ParentsParent is null, pass "Parent", else pass ParentsParent by modifying this section of page logic:

<apex:commandButton value="Associate" action="{!Associate}" rerender="all”>
    <apex:param name="Parent" value="{!prior.id}" assignTo="{!Parent}"/>
    <apex:param name="ParentsParent" value="{!prior.First_call__c}" assignTo="{!ParentsParent}"/>
</apex:commandButton>
pjaenick.ax736pjaenick.ax736
"Would it be possible to avoid all this and instead do the null check right within page logic?  - only pass a single non-null id to the controller method."

Heh, this solved it :)  Removed the two "param name" passes above with the singular :

<apex:param name="Parent" value="{!IF(ISBLANK(prior.First_call__c),prior.id,prior.First_call__c)}" assignTo="{!Parent}"/>

For academic purposes, I still would love to know the cause of my intiial trouble.

Thanks!
Pete
This was selected as the best answer