0

我有一个带有主关系字段的 VF 页面,我可以在该字段中自动插入值吗

<apex:inputField value="{!a.Parent__c}"/>
4

1 回答 1

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;
}

}

于 2012-05-10T17:30:46.943 回答