You need to sign in to do that
Don't have an account?

Compile Error: Initial term of field expression must be a concrete SObject
Hello,
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<Campaign_Create_Request__c> 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.
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<Campaign_Create_Request__c> 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; } }
Here is your error ,
CCR.Requested_Action__c = 'Create and Add';
CCR is a List<Campaign_Create_Request__c> , and above line basically tells you to update a list with the provided value which system does not understand.
All you need to do is ,
for (Campaign_Create_Request__c ccrUpdate: CCR)
{
ccrUpdate.Requested_Action__c = 'Create and Add';
}
Update CCR ;
By this way, you will be able to retrieve every record in the list and update it.
IF YOU LIKE THE ANSWER, PLEASE VOTE FOR IT.
Thanks,
Rohit Alladi
All Answers
Here is your error ,
CCR.Requested_Action__c = 'Create and Add';
CCR is a List<Campaign_Create_Request__c> , and above line basically tells you to update a list with the provided value which system does not understand.
All you need to do is ,
for (Campaign_Create_Request__c ccrUpdate: CCR)
{
ccrUpdate.Requested_Action__c = 'Create and Add';
}
Update CCR ;
By this way, you will be able to retrieve every record in the list and update it.
IF YOU LIKE THE ANSWER, PLEASE VOTE FOR IT.
Thanks,
Rohit Alladi