You need to sign in to do that
Don't have an account?
Jason McCarthy 2
I am getting Error: Compile Error: Invalid field OpportunityId for SObject Contact at line 35 column 75
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 Error: Compile Error: Invalid field OpportunityId for SObject Contact at line 35 column 75 . The functionailty is suppose to search contacts (which i should make for specific record type of "participant" and "Participant Donor" just haven't gotten there yet.
What am I missing?
public with sharing class AddContacttoJobOpptController {
public Opportunity opp {get;set;}
public String selectedConId = '';
public String selectedOppId = '';
public AddContacttoJobOpptController(){
opp = new Opportunity();
selectedOppId = Apexpages.currentPage().getParameters().get('aid');
}
public Pagereference addContact(){
Set<String> conIdSet = new Set<String>();
selectedConId = opp.Candidate__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, OpportunityId=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 String selectedConId = '';
public String selectedOppId = '';
public AddContacttoJobOpptController(){
opp = new Opportunity();
selectedOppId = Apexpages.currentPage().getParameters().get('aid');
}
public Pagereference addContact(){
Set<String> conIdSet = new Set<String>();
selectedConId = opp.Candidate__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, OpportunityId=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);
}
}
By default there is no OpportunityId field available on Contact object.
If you have created a custom field of Opportunity on Contact than please use the API name of that custom field where you are trying to use OpportunityId.
Please replace OpportunityId with API name of Opportunity custom field created on Contact.
Let me know if i can provide you more help on this.
Thanks,
Abhishek
All Answers
NOTE:- OpportunityId is invaild field on Contact. Please change Variable name accordingly.
By default there is no OpportunityId field available on Contact object.
If you have created a custom field of Opportunity on Contact than please use the API name of that custom field where you are trying to use OpportunityId.
Please replace OpportunityId with API name of Opportunity custom field created on Contact.
Let me know if i can provide you more help on this.
Thanks,
Abhishek
By default there is no OpportunityId field available on Contact object.
If you have created a custom field of Opportunity on Contact than please use the API name of that custom field where you are trying to use OpportunityId.
Please replace OpportunityId with API name of Opportunity custom field created on Contact.
Let me know if i can provide you more help on this.
Thanks,
Abhishek
I chose the best answer from Abhishek, because of the requiements if each contact had an actual account attached to it either answer would be the best.
Thank you both for your time.
Best,
Jason
<messaging:emailTemplate subject="Quote Information" recipientType="User" relatedToType="Opportunity">
<messaging:plainTextEmailBody >
</messaging:plainTextEmailBody>
<messaging:attachment renderAs="pdf">
<head>
<style>
@page {
size: auto; /* auto is the initial value */
margin-top: 0.0%;
margin-left: 4mm;
margin-right: 4mm;
margin-bottom: 4mm;
}
td{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
.tds{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
td.normal{
font-family:Arial,Helvetica,sans-serif;
font-weight:normal;
font-size:15px;
}
td.nbold{
font-family:Arial,Helvetica,sans-serif;
font-weight:bold;
font-size:15px;
}
</style>
</head>
The Discount on the Quote exceeds the maximums alloted and hence requires approval.
Below is the Opportunity information:
Opportunity Name : {!relatedTo.Name}
Opportunity Account : {!relatedTo.Account}
Close Date: {!relatedTo.CloseDate}
Stage: {!relatedTo.StageName}
Amount: {!relatedTo.Amount}
Link: {!relatedTo.Link}
<tr>
<td width = "14%"><b>Quote Number</b></td>
<td width = "10%"><b>Quantity</b></td>
<td width = "44%"><b>Expiration Date</b></td>
<td width = "44%"><b>Discount</b></td>
</tr>
<apex:repeat value="{!relatedTo.Quotes__r}" var="line">
<tr>
<td>{!line.QuoteNumber}"/></td>
<td>{!line.Name}"/></td>
<td>{!line.ExpirationDate}"/></td>
</tr>
</apex:repeat>
<tr><td> </td></tr>
<tr><td> </td></tr>
</messaging:attachment>
</messaging:emailTemplate>