[SalesForce] The value of the “id” parameter contains a character that is not allowed or the value exceeds the maximum allowed length

It fails right here:

      <apex:inputField value="{!Rec.supplier.id}" styleClass="rate" required="true"/>

My code is:

                Public      List<sobject>           Selectedmeters      {get;set;}
@TestVisible    Public      List<loggingWrapper>    contractWrapper     {get;set;}


@TestVisible Public Class loggingWrapper{
    Public      double                  AQ                  {get;set;}
    Public      double                  commission_per_year {get;set;}
    Public      double                  commission_per_kwh  {get;set;}
    Public      account                 supplier            {get;set;}
    Public      id                      meterID             {get;set;}
    Public      string                  unique_identifier   {get;set;}   
    Public      id                      contractID          {get;set;}           
    Public      date                    csd                 {get;set;}     
    Public      date                    ced                 {get;set;}     
    Public loggingWrapper(id meterID, string unique_identifier, account supplier,  double aq, double commission_per_year, double commission_per_kwh, date csd, date ced){
        supplier = supplier;
        unique_identifier=unique_identifier;
        aq = aq;
        commission_per_kwh=commission_per_kwh;
        commission_per_year=commission_per_year;
        meterID=meterID;
        ced = ced;
        csd=csd;
    }
}  

@TestVisible Public List<loggingWrapper> getContractsGrid(){
    list <contract__c> contractList = [select id, meter__r.id, contract_status__c, meter__r.UID__c from contract__c where id in: Selectedmeters];
    contractWrapper = New List<loggingWrapper>();
    for(contract__c contract: contractList){
        string unique_identifier=contract.meter__r.UID__c;
        id meterID= contract.meter__r.id;
        contractWrapper.add(
            new loggingWrapper(
                meterID,
                unique_identifier, null, null, null,null,null,null                                  
            ));
    }
    return contractWrapper;
}

I am struggling to understand this one.

Update: Added to my wrapper:

        account tempAcc = new account();
        contractWrapper.add( 
            new loggingWrapper(
                meterIDtmp,
                unique_identifiertmp, tempAcc, null, null,null,null,null,lineIDtmp

Setting inputField value to rec.supplier does not find the binding.

Setting inputField value to rec.supplier.id or .name works, but does not show the lookup icon.

Best Answer

The actual answer to your question is that you're attempting to dereference the Id field of supplier in your page, but supplier is null. If you set supplier = new Account() instead of null, you would at least be able to render the page without error.

That said, inputField is not normally intended to bind to the Id value of an SObject. If you do as I just suggested, you'll notice that it does not render a visible form element. Even if supplier had a value for Id, it would display the value as read-only text. The standard lookup functionality is available to relationship fields only, not the object's Id field.

If you want the standard functionality that a lookup field provides, you must provide an object and field to the value attribute such that:

  1. The object is a child of the object that you want to look up to.
  2. The field is a relationship field such as lookup or master-detail.

So as an exmaple, I would need to use {!Contact.AccountId} instead of {!Account.Id} or {!Contact.Account} or {!Contact.Account.Id}.

In your case, perhaps you can bring back Account__c in your Contract__c query (or whatever you named the account field) and add a property to your LoggingWrapper and set it to an instance of Contract__c. Then in your page, bind to {!contractPropertyName.Account__c}.