我有一个带有主关系字段的VF页面,我可以自动在此字段中插入值
<apex:inputField value="{!a.Parent__c}"/>
答案 0 :(得分:1)
问题有点模糊,但如果要为Parent__c设置默认值,则只需在控制器类中应用该值即可。
实施例
public class VFController {
private Account controllerAccount;
//Basic Constructor
public VFController() {
controllerAccount = new Account();
controllerAccount.Parent__c = getDefaultParentAccount();
}
//Standard Controller Constructor
public VFController(ApexPages.Controller standardController) {
controllerAccount = (Account)standardController.getRecord();
controllerAccount.Parent__c = getDefaultParentAccount();
}
private Id getDefaultParentAccount() {
Id parentAccountId = null;
//Lookup default parent Account
List<Account> parentAccounts = [SELECT Id FROM Account WHERE /*Your Criteria here*/ LIMIT 1];
if (parentAccounts.isEmpty() == false) {
parentAccountId = parentAccounts[0].Id;
}
return parentAccountId;
}
}