I'm running into a bit of an issue. I'm trying to have two fields auto-populate on the VisualForce page load to save the reps from having to fill them out. (They are required name fields but we have a system that dictates the names of Opportunities and quotes.) I have tried using Jquery but I don't know enough about Java to know if I'm editing correctly. I've also tried controller solutions but the code is a bit foreign to me and hard to dictate. Are there any other solutions I'm missing?
1 Answer
If the page is creating new objects, then the simple way to have the fields in the Visualforce pre-popupated is for the controller to default the values e.g.:
public with sharing class MyController {
...
public MyObject__c myObject {
get {
if (myObject == null) {
myObject = new MyObject__c(Name = 'Default Name');
}
return myObject;
}
private set;
}
...
}
and then when the page displays the field it will already have a default value:
<apex:inputField value="{!myObject.Name}"/>
While this could also be done using JavaScript, as you have noticed that requires additional knowledge and can be tricky to get right at first.