• Mani Anand 10
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
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);
    }

}

Hi All -

 

I am new, so please forgive my green - but I am having a perplexing problem in generating a Visual Force email template showing related lists for a custom object.

 

I CAN get a list of Cases related to an Account with no problem, but when I put in a custom object  (Child Relationship Name "Suppliers") which is also (Master-Detail) related to Account I get the following error: Error: Invalid field Suppliers for SObject Account

 

I have tried everything I can think of - using API name instead, appending "__c" to the end, but it seems that i can't make any lists at all with custom objects in this code.

 

Is there a restriction within this type of code that allows only lists with standard objects or is there something I'm missing?

 

Any help would be greatly appreciated. I am not good enough to make a custom Apex controller yet and a little under the gun to kluge something together.

 

Thanks much,

 

Lex

 

Below is relevant code:

 

 

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Account"
    subject="Supplier report for Account: {!relatedTo.name}"
    replyTo="support@acme.com" >
<messaging:htmlEmailBody >   
<html>
    <body>
     <STYLE type="text/css">
           TH {font-size: 11px; font-face: arial;background: #CCCCCC; border-width: 1;  text-align: center }
           TD  {font-size: 11px; font-face: verdana }
           TABLE {border: solid #CCCCCC; border-width: 1}
           TR {border: solid #CCCCCC; border-width: 1}
     </STYLE>
         <font face="arial" size="2">
      <p>Dear {!recipient.name},</p>
      <p>Below is a list of supplier records related to the account: {!relatedTo.name}.</p>
<table border="0" >
        <tr >
            <th>Action</th><th>Product</th><th>Status</th><th>Creator Email</th><th>BL date</th>
         </tr>
<apex:repeat var="cx" value="{!relatedTo.Suppliers}">
   <tr>
       <td><a href="https://na1.salesforce.com/{!cx.id}">View</a> |  
       <a href="https://na1.salesforce.com/{!cx.id}/e">Edit</a></td>
(...snip...)