2012-05-10 82 views
0

我有一個主關係領域的VF頁自動插入,我可以在此字段中插入值自動在主關係領域

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

回答

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

}

+0

您好,感謝您的回答,我想自動插入主關係字段的值,這樣用戶只需要輸入其他領域沒有這一項,我可以將其隱藏? – Netmaster

+0

當然可以將它從用戶隱藏起來。您可能希望將其設置爲隱藏輸入或甚至頂點:變量字段,以便標準控制器仍然可以查詢該字段。通過這種編輯方式,您仍然可以看到該字段,只要您在控制器類中設置值,無論是在保存方法還是構造函數中,您都應該可以。 –