0

I have this save error "Incompatible element type Id for collection of Account", and i don't know how to remove it. I've found many subject on Internet but nothing seems to correspond to my specific case.

I'm saving in 3 lists results from 3 SOQL requests. Then i'm trying to eliminate doublon searching by IDs. Here is my code :

    Set<Account> setAccount = new Set<Account>();        
    List<Account> newListAccount = new List<Account>();
    List<Account> newListAccountPhones = new List<Account>();
    List<Account> newListAccountEmails = new List<Account>();
    List<Account> myListAccount = new List<Account>();
String query = 'SELECT RecordType.Name,Origine_de_la_piste__c,SellerId__c,Id,Parent.Name,Name,FirstName__c,LastName__c,Phone,Email__c,Adresse_E_mail__c,CompanyName__c,N_Siren__c,SiretNumber__c,IntracomNumber__c,Iban__c,RIBBankAccountNumber__c,AccountOwner__c,BicSwift__c ,ParentId, Statut_CRM__c, Perimetre__c, Owner.Name, Sourceur__r.Name, (SELECT Email,Autre_adresse_e_mail__c, FirstName, LastName, Phone, MobilePhone FROM Contacts WHERE Email != NULL OR (Autre_adresse_e_mail__c != NULL) ) FROM Account WHERE Id NOT IN :relIds AND (' + String.join(conditions, ' OR ') + ')';
        newListAccount = (Database.query(query));
        String query1 = 'SELECT RecordType.Name,Origine_de_la_piste__c,SellerId__c,Id,Parent.Name,Name,FirstName__c,LastName__c,Phone,Email__c,Adresse_E_mail__c,CompanyName__c,N_Siren__c,SiretNumber__c,IntracomNumber__c,Iban__c,RIBBankAccountNumber__c,AccountOwner__c,BicSwift__c ,ParentId, Statut_CRM__c, Perimetre__c, Owner.Name, Sourceur__r.Name, (SELECT Email,Autre_adresse_e_mail__c, FirstName, LastName, Phone, MobilePhone FROM Contacts WHERE Email != NULL OR (Autre_adresse_e_mail__c != NULL) ) FROM Account WHERE Id NOT IN :relIds AND Id IN (SELECT AccountId FROM Contact WHERE Phone IN :Phones)';           
        newListAccountPhones = (Database.query(query1));
        String query2 = 'SELECT RecordType.Name,Origine_de_la_piste__c,SellerId__c,Id,Parent.Name,Name,FirstName__c,LastName__c,Phone,Email__c,Adresse_E_mail__c,CompanyName__c,N_Siren__c,SiretNumber__c,IntracomNumber__c,Iban__c,RIBBankAccountNumber__c,AccountOwner__c,BicSwift__c ,ParentId, Statut_CRM__c, Perimetre__c, Owner.Name, Sourceur__r.Name, (SELECT Email,Autre_adresse_e_mail__c, FirstName, LastName, Phone, MobilePhone FROM Contacts WHERE Email != NULL OR (Autre_adresse_e_mail__c != NULL) ) FROM Account WHERE Id NOT IN :relIds AND Id IN (SELECT AccountId FROM Contact WHERE Email IN :Emails)';           
        newListAccountEmails = (Database.query(query2));

        myListAccount.addAll(newListAccount);
        myListAccount.addAll(newListAccountPhones);
        myListAccount.addAll(newListAccountEmails);

        for(Account myAcc : myListAccount){
            for(Id myId : myAcc.Id )
            {
                if(setAccount.contains(myId) ){

                }

                else{
                    setAccount.addAll(newListAccount);               
                }
            }

        }                        

if(setAccount.contains(myId) => this line is the problem, and i don't know how to fix this.

Thanks in advance for reply !

2

You've Set<Account> so setAccount.contains() should be of Account type and not Id. Refer below example:

for(Account myAcc : myListAccount){
    if(setAccount.contains(myAcc) ){

    }
    else{
        setAccount.addAll(newListAccount);               
    }
}
  • You're right, i needed 2 different Set to do my work thanks a lot for reply – VERYNET May 26 '17 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.