function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sowmya thotthadisowmya thotthadi 

Method does not exist or incorrect signature: void addall(List<OpportunityContactRole>) from the type Set<Id>

I WAN TO ADD THE LIST OF RECORDS IN SET SOO THAT NO DUPLICATE
public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<id> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
     contactRole=[select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name  from OpportunityContactRole];
     accountid.addall(contactRole);
   }
}
Best Answer chosen by sowmya thotthadi
Pradeep SinghPradeep Singh
for(OpportunityContactRole contactRole : [select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole]){
     accountid.add(ContactRole.Opportunity.AccountId);
 }
 

All Answers

Pradeep SinghPradeep Singh
Hi,

The set you are using is of ID type and the values you are adding is of Contactrole type. Moreover, you are using the wrong method to add one value.
either change yout set type to contactRole from ID.

If you want the set of ids, then you have to change the code. Use below code for this :-

for(contactRole : [select ContactId ,Contact.AccountId,Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name  from OpportunityContactRole]){
     accountid.add(Contact.AccountId);
 }
 
Pradeep SinghPradeep Singh
Hi,
your set should be of type OpportunityContactRole to add the OpportunityContactRole records to the set.
Pradeep SinghPradeep Singh
sorry for the typo,
replace accountid.add(Contact.AccountId); by accountid.add(contactRole.Contact.AccountId); and add Contact.AccountId to the query as mentioned in first answer.
 
Pradeep SinghPradeep Singh
Hi, If this solves your problem, please mark it as solved/ best answer.
sowmya thotthadisowmya thotthadi
Hi,
 as i want from OPPORTUNITY .
error : AccountContactOppurtunitycon Compile Error: Variable does not exist: Opportunity at line 7 column 32
public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<OpportunityContactRole> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
     contactRole=[select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name  from OpportunityContactRole];
     accountid.add(contactRole.Opportunity.AccountId);
   }
}
Pradeep SinghPradeep Singh

public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<Id> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
    accountid = new set<id>();
     contactRole=[select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole];
     accountid.add(contactRole.Opportunity.AccountId);
   }
}
Pradeep SinghPradeep Singh
for(OpportunityContactRole contactRole : [select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole]){
     accountid.add(ContactRole.Opportunity.AccountId);
 }
 
This was selected as the best answer
sowmya thotthadisowmya thotthadi
Error: AccountContactOppurtunitycon Compile Error: Variable does not exist: Opportunity at line 8 column 32
public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<Id> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
    accountid = new set<id>();
     contactRole=[select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount, opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole];
     accountid.add(contactRole.Opportunity.AccountId);
   }
}
Pradeep SinghPradeep Singh

public class AccountContactOppurtunitycon {
        Public list<OpportunityContactRole> contactRole{get;set;}
        set<Id> accountid{get; set;}
   public AccountContactOppurtunitycon()
   {
    accountid = new set<id>();
     for(OpportunityContactRole contactRole : [select ContactId , Contact.Name, opportunityId ,opportunity.Name ,opportunity.Amount,         opportunity.Account.Name,Opportunity.AccountId  from OpportunityContactRole]){
     accountid.add(ContactRole.Opportunity.AccountId);
   }
}