I have a custom Visualforce controller that applies to a custom object (SF__c). This object has a master-detail to the Opportunity object. My controller pre-populates the SF__c object with the Opportunity ID and the Owner ID upon creation. I would also like to populate a Contact__c field on the SF__c object with a Contact Role on the Opportunity that has a Role of "Signer". Does anyone know how I can do this in my controller?
public class VF_SFController{
public List<SF__c> ESF {get; set;}
private final Opportunity opp;
public VF_SFController(ApexPages.StandardController myController){
SF = new List<SF__c>();
myController.addFields(new List<String>{'Id', 'OwnerId', 'Owner.Phone'});
opp=(Opportunity)myController.getrecord();
}
public SF__c SF2 = new SF__c();
public void SF(){
SF2.Opportunity__c = opp.Id;
SF2.Rep__c = opp.OwnerId;
SF.add(SF2);
}
public PageReference save() {
insert SF;
PageReference RetPage = new PageReference('/apex/VFSFView?id=' + SF[0].id);
RetPage.setRedirect(true);
return RetPage;
}
}
opp.id