• Samer Aboobacker
  • NEWBIE
  • 25 Points
  • Member since 2015

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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."

 
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."