I have a custom object with a Mast-Detail relationship to the Opportunity. I am trying to create a Visualforce page that will pre-populate fields based upon values in the Opportunity and Account. I have a custom controller where I can pull in the Opportunity ID, but I have some formula fields in my custom object that I need to populate in the initial VF page and I'm not sure how. For example, I have a field where the formula is Opportunity__r.Type, which pulls the Type field from the Opportunity associated to my custom object record. It works fine when I save a record, but I do I get it to populate upon the initial view? My controller is below:
public class VF_CampaignCaseCreateController{
public List<Campaign_Create_Request__c> CCR {get; set;}
private final Opportunity opp;
public VF_CampaignCaseCreateController(ApexPages.StandardController myController){
CCR = new List<Campaign_Create_Request__c>();
if (!Test.isRunningTest())
{
myController.addFields(new List<String>{'Id', 'OwnerId', 'Owner.Phone'});
}
opp=(Opportunity)myController.getrecord();
}
public Campaign_Create_Request__c CCR2 = new Campaign_Create_Request__c();
public void CampaignCaseCreate(){
CCR2.Opportunity__c = opp.Id;
Opportunity o = [SELECT (SELECT Id, contactId
FROM OpportunityContactRoles
WHERE role = 'Signatory')
FROM Opportunity
WHERE id = :opp.id];
CCR2.Primary_User__c = o.opportunityContactRoles.size() != 0
? o.opportunityContactRoles[0].contactId
: null;
CCR.add(CCR2);
}
public PageReference save() {
insert CCR;
PageReference RetPage = new PageReference('/?id=' + CCR[0].id);
RetPage.setRedirect(true);
return RetPage;
}
}
VF_CampaignCaseCreateController
a controller extension on Opportunity or a custom controller (not an extension)?