0

I want to make sure that either my assignedOpps or updatedOpps list contains at least one value, before executing the rest of my code.

The next set of steps in the code apply to either list, before later steps only apply to one list or the other.

But when I use

if(reassignedOpps.size() > 0 OR UpdatedOpps.size() > 0){

I get an error

expecting a right parentheses, found 'OR'

and I can't find an alternative?

trigger OpportunityTargetUpdate on Opportunity (after update) {

    for (Opportunity o : Trigger.new){

        //check that Opportunity record type is valid
        if(validRecordTypeIds.contains(o.RecordTypeId))
        {
            //check whether Opportunity owner has changed
            Opportunity oldOpp = Trigger.OldMap.get(o.Id);
            if(oldOpp != null
               &&
               oldOpp.OwnerId != o.OwnerId)
            {
                identifiers.add(o.Identifier__c);
                reassignedOpps.add(o);
                system.debug('reassignedOpps contains ' + reassignedOpps);
            }else
                //check whether close date month or year has changed
                if(oldOpp != null 
                   &&
                   (oldOpp.CloseDate.month() != o.CloseDate.month()
                    ||
                    oldOpp.CloseDate.year() != o.CloseDate.year()
                   )){
                       identifiers.add(o.Identifier__c);
                       updatedOpps.add(o);
                       system.debug('updatedOpps contains ' + updatedOpps);
                   }
        }else{
            system.debug('No Opportunities with a valid Record Type Id were found');
        }
        if(reassignedOpps.isEmpty() == true){
            System.debug('no Opportunities had new owners');
        }
        if(updatedOpps.isEmpty() == true){
            System.debug('no Opportunities had a close date with a new month or year');
        }
        system.debug('identifiers contains ' + identifiers);
    }

    if(reassignedOpps.size() > 0 OR UpdatedOpps.size() > 0){
1

You cannot use OR operator in apex to perform a logical OR operation. You will have to use the double pipe || for that (and its already being used in your code (oldOpp.CloseDate.month() != o.CloseDate.month() || oldOpp.CloseDate.year() != o.CloseDate.year())).

YOu can check it out here for more details ;

You can use OR in formulas and in SOQL queries.

| improve this answer | |

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.