I have a custom controller extension below which pre-populates the Opportunity ID and a Contact Role ID to a Visualforce page for a custom object that has a Master-Detail relationship to the Opportunity object. I am now trying to create 2 buttons on the VF page that will populate a 3rd custom field, save the custom object record, and re-direct the user to another VF page. However, when I try to save the code below I get the error:
Error: VF_CampaignCaseCreateController Compile Error: Initial term of field expression must be a concrete SObject: List at line 37 column 9
I'm sure my syntax is incorrect for populating the 3rd field in each method, but I'm not sure how to fix it.
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 AdCamp() {
insert CCR;
CCR.Requested_Action__c = 'Create and Add';
PageReference RetPage = new PageReference('/VF_CampaignCreate_Edit?id=' + CCR[0].id);
RetPage.setRedirect(true);
return RetPage;
}
public PageReference Camp() {
insert CCR;
CCR.Requested_Action__c = 'Create Only';
PageReference RetPage = new PageReference('/VF_CampaignCreate_Edit?id=' + CCR[0].id);
RetPage.setRedirect(true);
return RetPage;
}
}
CCR.Requested_Action__c
, butCCR
is a list. That is the source of your exception.CCR[0].id
. I'm assuming you'd want to do the same thing.CCR[0].Requested_Action__c
. Also, you're changing that value just after you insert the list so if I'm not mistaken, those changes are lost when you redirect.