Skip to main content
Shravya Rama が「#Apex」で質問
Hello All,

I have a custom childobject(Reservation) and a  lookup parent object(User). I am trying to prepopulate the look up field with the current user attributes. My lookup field accepts the values in the form of "UserFirstName UserLastName". So I tried to invoke the default values through constructor like below.

VisualForce Page:

<apex:page standardController="Reservation__c" extensions="ReservationClass" >

<apex:sectionHeader title="New Reservation" />

<apex:form >

<apex:pageBlock>

<apex:pageBlockSection >

<apex:inputField value="{!order.User__c}"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:page>

Custom Controller

public class ReservationClass {

public Reservation__c res{get; set;}

   public String FName = UserInfo.getFirstName() ;

public String Lname = UserInfo.getLastName();

public string UserName = FName + ' ' + Lname ;

public ReservationClass (ApexPages.StandardController stdController) {

res = (Reservation__c) stdController.getRecord();

   res.User__c =  userName ;

}

}

The above code throws an error

"Invalid id: Shravya Rama

 An unexpected error has occurred. Your development organization has been notified."

 
3 件の回答
  1. 2016年12月7日 10:07
    Hi Shravya Rama 9, 

    You will have to assign the user id to the User__c field. Pls try assigning the userinfo.getUserId().
0/9000