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
Nithin_007Nithin_007 

Pass custom object filed value from VisualForce to controller extension

Hi Guys,

 

I am new to VF and Apex coding

 

I went though a lot of topic similar to this but no solution to my problem 

 

Problem: in my VF 

 

 <apex:inputField id="searchRecordNo" value="{!Record_Tracking_System__c.Record_No__c}" required="true" />

 

where 'Record_No__c' is a record number user enter in VF - i want to pass this user entered value to controller extension 

 

for that, this is what i did:

 

public Record_Tracking_System__c record {get; set;} 

 

// Constructor
public RecordControllerExt(ApexPages.StandardController Controller) {

// Initz
record = new Record_Tracking_System__c ();

}

 

next i want to pass this user entered record number from controller to Record_Tracking_System__c  object filed 'Record_No__c' in standard page layout through URL 

for that, in controller extension i did this 

urlString += '&00NQ000000158Bb=' + record.Record_No__c;

 

where '00NQ000000158Bb' is the filed id of Record_No__c

 

but the problem is when i go to standard layout for Record_Tracking_System__c, Record_No__c field is showing 'null' instead of user entered record number 

 

any help is much appreciated 

 

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Go through this. You will get your solution

http://boards.developerforce.com/t5/Apex-Code-Development/How-to-populate-default-look-up-value/m-p/639863#M118371

 

You have to do like this

public RecordControllerExt(ApexPages.StandardController Controller) {

// Initz
record = new Record_Tracking_System__c ();
 this.record = (Record_Tracking_System__c)controller.getRecord();
}

 

AND in VF like this

 

<apex:inputField id="searchRecordNo" value="{!record.Record_No__c}" required="true" />

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

All Answers

Eli Flores, SFDC DevEli Flores, SFDC Dev

You have to a little URL action... Basically open a edit page for that object and then look at the source... you should see the fields and you have to use the ID field in the HTML as the the parameter... So here's an example from the account object

 

/0013000000Hk0Nu/e?retURL=%2F0013000000Hk0Nu&acc20=testsing

 

The red is the object ID. I went into the source (ie developer tools element inspector is great for tracking these down) and found this section:

 

<td class="labelCol last"><label for="acc20">Description</label><div class="textCounterOuter"><div class="textCounterMiddle"><div class="textCounter" id="acc20_counter">31992 remaining</div></div></div></td><td class="dataCol col02 last"><textarea  cols="40" id="acc20" maxlength="32000" name="acc20" onpropertychange="handleTextAreaElementChangeWithByteCheck('acc20', 32000, 0, 'remaining', 'over limit');" tabindex="7" type="text" wrap="soft">testsing</textarea></td>

 

So based on this on this, i can tell that acc20 is the id for the description field in the html. So now I can pass it as a parameter in the URL. So if I click on the above link. It will take me to the edit page and the description field will be pre-populated with testing. 

souvik9086souvik9086

Go through this. You will get your solution

http://boards.developerforce.com/t5/Apex-Code-Development/How-to-populate-default-look-up-value/m-p/639863#M118371

 

You have to do like this

public RecordControllerExt(ApexPages.StandardController Controller) {

// Initz
record = new Record_Tracking_System__c ();
 this.record = (Record_Tracking_System__c)controller.getRecord();
}

 

AND in VF like this

 

<apex:inputField id="searchRecordNo" value="{!record.Record_No__c}" required="true" />

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

This was selected as the best answer
Nithin_007Nithin_007

Hi Souvik,

 

changing <apex:inputField id="searchRecordNo" value="{!Record_Tracking_System__c.Record_No__c}" required="true" /> this to 

<apex:inputField id="searchRecordNo" value="{!record.Record_No__c}" required="true" /> in VF solved the problem i was facing 

 

this change in controller throws me an error message 

 

this.record = (Record_Tracking_System__c)controller.getRecord();

thanks

Nithin

souvik9086souvik9086

Can you please post the error which you are facing?

 

Thanks