On my page am doing a search (Case Number) and storing the Data in the user record, So whenever the user login back trying to display the records based on old search.

In that case, Trying to build a dynamic object and adding the value

sObject sObj; //Schema describe to get the object
sObj.put(fld, fdValue); 

/*Here I want to add caseNumber as field set an value
Not going to any DML operation
Need to refer it in VF page to display the search using apex:inputfield*/

When I do am getting an error as CaseNumber is NOT Editable. Is there any way workaround to add value to the ReadOnly field just for reference in the VF page.

  • Cases are auto numbered and you can't change it or assign any value. You can create another field and put the Case number into that. Jan 10 '20 at 7:54
  • 1
    Why won't you just query case from DB with Case cs = [SELECT Id, CaseNumber, Description FROM Case WHERE CaseNumber = :fdValue];? Is that a particular difference to refer an existing record instead of creating new one? (even if you do not use DML). Jan 10 '20 at 8:28
  • @MariiaIllarionova Why I am trying to add those values to a new object is because those are the values of the fields I entered in Filter and trying to repopulate the filter after the page refresh. Here If I query only the fields with value then another fields when accessed throws the error as accessed without querying the field. If I query all the fields that are needed it might bring values from the record, but I need only the values that I filtered.
    – SFDC
    Jan 23 '20 at 13:15

You can coerce a value into a readonly field using JSON.deserialize


produces an SObject of type Case with the CaseNumber populated:


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.