0

I want to know if an Opportunity ID of a List is on another List and I get this error:

Method does not exist or incorrect signature: [List<FAST_Opp__c>].contains(Id)

public FAST__c                                      fast{get;set;}
public List<FAST_OPP__c>                            fastOppList{get;set;}
private List<ManageOpp>                             manageOppList{get;set;}
private manageUser                                  oppUser;
public Date                                         quarter;

public ManageFAST() {
    fast = new FAST__c();
    fastOppList = new List<FAST_OPP__c>();
    oppUser = new ManageUser();
    oppUser.load(UserInfo.getUserId());
    quarter = Date.newInstance(2017, 2, 17);
    loadFAST();
    loadFASTOPP();
    initFASTOppList();
}


public void loadFAST(){
    List<FAST__c> fastList = new List<FAST__c>();
    fastList = [SELECT Id, Sales_ID__c, Forecast_Manager_ID__c, Quarter_Date__c, Commit_Manager__c, Transactionnal_Amount_Forecast_Exit__c, Transactionnal_Amount_Optimistic__c, Transactionnal_Amount_Pessimistic__c FROM FAST__c WHERE Sales_ID__c =: oppUser.getId() LIMIT 1];
    if(fastList.isEmpty()){
        fast = new FAST__c();
        fast.Sales_ID__c = oppUser.getId();
        fast.Transactionnal_Amount_Pessimistic__c = 0;
        fast.Transactionnal_Amount_Optimistic__c = 0;
        fast.Transactionnal_Amount_Forecast_Exit__c = 0;
        fast.Commit_Manager__c = 0;
        fast.Quarter_Date__c = quarter;


    } else {
        fast = fastList.get(0);
    }
}


public void loadFASTOPP(){
        fastOppList = [SELECT Id, Opp_ID__c, IsClosed__c, Type__c FROM FAST_OPP__c WHERE FAST_ID__c =: fast.Id ];
}

public void initFASTOppList(){
    oppUser.loadOpportunityList(quarter);
    for(ManageOpp mo : oppUser.getOpportunityList())
    {
        if(!fastOppList.contains(mo.getOppId())){
            FAST_OPP__c fastOpp = new FAST_OPP__c();
            fastOpp.Opp_ID__c = mo.getOppId();
            fastOpp.IsClosed__c = mo.getIsClosed();
            fastOpp.Type__c = '';
            fastOppList.add(fastOpp);
        }

        System.debug('FIRST USER DEBUG BEFORE ADD TO FAST_OPP__c' + fastOppList);
        //upsert fastOppList;

    }

    System.debug('SECOND USER DEBUG AFTER ADD TO FAST_OPP__c' + fastOppList);
}
1
  • 5
    List doesn't support / have a contains() method. you have to either use Sets or Maps Commented Apr 14, 2017 at 12:28

2 Answers 2

2

Use a Map instead:

Map<Id, MyObject__c> records = new Map<Id, MyObject__c>();
for (WrapperClass wrapper : wrappers)
{
    if (!records.containsKey(wrapper.getId())
    {
        records.put(wrapper.getId(), new MyObject__c(/*data*/));
    }
}
List<MyObject__c> collectionYouWant = records.values();
1
  • 1
    Will add more detail but... about to fly.
    – Adrian Larson
    Commented Apr 14, 2017 at 12:55
0

There is a useful constructor on the map that allows creating one directly from a list < sObject >. You can then immediately strip the keyset from this map and use that set for your contains() check.

list<FAST_Opp__c> myList = loadFASTOPP();
set<Id> fastOppIds = new map<Id, FAST_Opp__c>(myList).keySet();

//...

    if (!fastOppIds.contains(mo.getOppId())) {

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .