You need to sign in to do that
Don't have an account?
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
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
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
Yes, it is a lookup field.
Thank you.
produces
>>>>>> ParentsParent = ><
(seemingly null, but it passes the null check in the preceding line).
public Id ParentsParent {get; set;}
if(ParentsParent != null && ParentsParent != '')
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>
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