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
Bill WoodsonBill Woodson 

Field value in controller

Hello,

I have a custom VF page that works exactly how I need, I am successfully inserting a new custom object (CO).  However I want to modify the Body property of CO before inserting it.  The code below shows what I am trying to do.  However the custom object record created has the following resulting string in the Body property (I put the word "test") into the orginal custom object body

"null null work at null
test"

Can someone tell me what I am missing?  The if statement does execute so I know that the custom object has properties set.

Here is the code...

At the top of the controller I have this line
public final LT_Note__c Note{get;set;}

public PageReference saveCO() {
    if(CO.Backdoor__c) {
            CO.Body__c = CO.Contact__r.FirstName + ' ' + CO.Contact__r.LastName + ' work at ' + CO.Client__r.Name + '\n' CO.Body__c;
    }  
        
    insert CO;  
}
Tyler Mowbrey 1Tyler Mowbrey 1
Hi Bill,

Because your traversing a relationship to Contact from your CO I would most likely guess that you have not queried or set the properties of the contact correctly.

Unfortunately without more details on your VF page and the controller (where the CO property and the contact information is being set) I can not help further.

Tyler
Bill WoodsonBill Woodson
Thanks Tyler I don't know if this helps but the relationship for client is a lookup field on the form, can I get the name from that? Since this object doesn't get inserted until the insert statement I would expect that no relationship yet exists. So I need to get the name from the account the user selected on the page. How can I do that?
Tyler Mowbrey 1Tyler Mowbrey 1
How do you know which contact to choose from the client? Does the end user select the contact on your VF page?
Bill WoodsonBill Woodson
I set the contact property on the object when I create the object reference. The account however is a lookup set by the user. If we. An solve for account I can solve for contact based on that.
Bill WoodsonBill Woodson
Client = Account