3

I can't get this for loop to work:

global void execute(Database.BatchableContext bc, List<Account> accounts){
    List<Account> acctsToUpdate = new List<Account>();
    List<Contact> allContacts = [SELECT Id, Name FROM Contact];
    List<Interaction__c> allInteractions = [SELECT *fields* FROM Interaction__c];

    List<Interaction__c> relInterations = new List<Interaction__c>();for(Account act : accounts){
        for(Interaction__c relInt : allInteractions) {
            if((ID)relInt.AccountID__c = act.Id){

I get the error

Expression cannot be assigned

If I remove the (ID) I get

Condition expression must be of type Boolean: Id

How can I solve this problem? Could it be because I am using Database.Batchable and the list accounts is void? I don't totally understand the void vs static in this case.

As an aside, I tried act.contains(relInt.AccountID__c) and it says that method does not exist, which seems to be the opposite of what the documentation says, right?

1 Answer 1

5

Replace = with ==, single equals is for assignment and double for comparison.

1
  • 3
    @Chance You need to be careful with that syntax, too, because it can cause subtle bugs when you least expect it: Boolean someFlag; if(someFlag = true) {...} will compile, and always execute. It's a nice-to-have, so I understand why it's not forbidden by the syntax. Just be aware of this feature and you'll be fine.
    – sfdcfox
    Commented Jan 22, 2018 at 18:18

You must log in to answer this question.

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