2

I am getting an invalid ID error in my VF page on the below code and I don't understand what I am missing.

In my controller's constructor I am running the below code:

system.debug('SystemChangeRequest View/Edit PAGE demand ID: '+sObjectRFC.Demand__c);

system.debug('SystemChangeRequest View/Edit PAGE GET DEMAND QRY');
if (sObjectRFC.Status__c=='Converted' && sObjectRFC.Demand__c !=''){
    system.debug('SystemChangeRequest View/Edit PAGE GET DEMAND inside IF block');
    demandName=[Select Id, Name from apm2__Demand__c where Id =: sObjectRFC.Demand__c].Name;
    system.debug('SystemChangeRequest View/Edit PAGE demand ID: '+sObjectRFC.Demand__c);

    //demandName='TEST DEMAND';
} 

in the developer console logs I can see that sObjectRFC.Demand__c = 'a0U8E000002tZwj'

and I can access that record on the Demand object through salesforce with the url https://domain.salesforce.com/a0U8E000002tZwj

Of course I can show the Id in my VF page with no problems, but I want to show the record identifier which looks like this: D-04235

In the Demand object, the field is defined as:

enter image description here

Now, in the developer console I can write the below SOQL query:

Select Name, Id from apm2__Demand__c where Id ='a0U8E000002tZwj'

and it returns a record with the results as below: enter image description here

In my VF page, I want to show the Name field from the demand object, which should be D-04235

but the when I run my VF page, all I can see in the log (developer console) is:

enter image description here

so it just stops with that error after the line system.debug('SystemChangeRequest View/Edit PAGE GET DEMAND QRY');

so what am I doing wrong?

  • 1
    did you check the status? – Tushar Sharma Feb 5 '16 at 9:51
5

Id fields cannot be compared with the '' value. If you need to check for blank , then use "null" instead of ''. So change your check like this :

system.debug('SystemChangeRequest View/Edit PAGE demand ID: '+sObjectRFC.Demand__c);

system.debug('SystemChangeRequest View/Edit PAGE GET DEMAND QRY');
if (sObjectRFC.Status__c=='Converted' && sObjectRFC.Demand__c != null){
    system.debug('SystemChangeRequest View/Edit PAGE GET DEMAND inside IF block');
    demandName=[Select Id, Name from apm2__Demand__c where Id =: sObjectRFC.Demand__c].Name;
    system.debug('SystemChangeRequest View/Edit PAGE demand ID: '+sObjectRFC.Demand__c);

    //demandName='TEST DEMAND';
} 
| improve this answer | |
  • Thanks, that was it, such an unhelpful error message from SalesForce as usual :) – Our Man in Bananas Feb 5 '16 at 9:59
  • no worries, yeah what to say :) – Nitin Feb 5 '16 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.