You need to sign in to do that
Don't have an account?
Jason McCarthy 2
New Error: Invalid field initializer: con.Candidate_Opportunity__c at line 43 column 61
I am trying to add existing contacts to a related list on Opportunities as "Job Candidates" through a VF page and kicked off by a custom button. I keep getting the compile Error: Invalid field initializer: con.Candidate_Opportunity__c at line 43 column 61. I have created a field on the Contact object "Candidate_Opportunity__c" and named the variable.
What am I missing?
public with sharing class AddContacttoJobOpptController {
public Opportunity opp {get;set;}
public Contact con {get;set;}
public String selectedConId = '';
public String selectedOppId = '';
String selectedOpportunityID = con.Candidate_Opportunity__c;
public AddContacttoJobOpptController(){
opp = new Opportunity();
selectedOppId = Apexpages.currentPage().getParameters().get('aid');
}
public Pagereference addContact(){
Set<String> conIdSet = new Set<String>();
selectedConId = opp.Candidate__c;
selectedOppId = opportunity.Id;
selectedOpportunityID = con.Candidate_Opportunity__c;
if(selectedConId != null && selectedConId != ''){
for(Contact con : [select id from Contact where OpportunityId = :selectedOppId]){
conIdSet.add(con.id);
}
if(conIdSet.contains(selectedConId)){
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'The selected contact is already added to strategic account plan. Please select another contact to add.');
apexpages.addmessage(msg);
return null;
}
else{
Contact con = new Contact(id=selectedConId, con.Candidate_Opportunity__c = selectedOppId);
update con;
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'The selected contact has been added to strategic account plan. Now you can select another contact to add.');
apexpages.addmessage(msg);
return null;
}
}
else{
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select contact then click on Add Contact button.');
apexpages.addmessage(msg);
return null;
}
}
public Pagereference goBack(){
return new Pagereference('/'+selectedOppId);
}
}
What am I missing?
public with sharing class AddContacttoJobOpptController {
public Opportunity opp {get;set;}
public Contact con {get;set;}
public String selectedConId = '';
public String selectedOppId = '';
String selectedOpportunityID = con.Candidate_Opportunity__c;
public AddContacttoJobOpptController(){
opp = new Opportunity();
selectedOppId = Apexpages.currentPage().getParameters().get('aid');
}
public Pagereference addContact(){
Set<String> conIdSet = new Set<String>();
selectedConId = opp.Candidate__c;
selectedOppId = opportunity.Id;
selectedOpportunityID = con.Candidate_Opportunity__c;
if(selectedConId != null && selectedConId != ''){
for(Contact con : [select id from Contact where OpportunityId = :selectedOppId]){
conIdSet.add(con.id);
}
if(conIdSet.contains(selectedConId)){
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'The selected contact is already added to strategic account plan. Please select another contact to add.');
apexpages.addmessage(msg);
return null;
}
else{
Contact con = new Contact(id=selectedConId, con.Candidate_Opportunity__c = selectedOppId);
update con;
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'The selected contact has been added to strategic account plan. Now you can select another contact to add.');
apexpages.addmessage(msg);
return null;
}
}
else{
apexpages.Message msg = new Apexpages.Message(ApexPages.Severity.Info,'Please select contact then click on Add Contact button.');
apexpages.addmessage(msg);
return null;
}
}
public Pagereference goBack(){
return new Pagereference('/'+selectedOppId);
}
}
Why are you using con.fieldname?
if the custom field is created on contacts then you can assign the value to it by simply Fieldaname__c='variable';
try just giving the fieldname.
Thanks.