3

I am attempting to run a SOQL query where I need to check for the WhatId from a task in my map, to get the appropriate list of Opportunities to modify.

Map<Id, DateTime> tskMap = new Map<Id, DateTime>();
        Map<Id, DateTime> dtMap = new Map<Id, DateTime>();
        String checkID;
        Datetime prevDate;
        for(sObject s : scope){
            for(Task tsk : (Task)s)
            {
                checkID = tsk.WhatId;
                if(checkID == tsk.WhatId)
                    {
                        prevDate = tsk.CreatedDate;
                        if(prevDate >= tsk.CreatedDate)
                        {
                            tskMap.put(tsk.WhatId,tsk.CreatedDate);
                        }
                    }
                    else
                    {
                        checkID = tsk.WhatId;
                        prevDate = tsk.CreatedDate;
                        tskMap.put(tsk.WhatId,tsk.CreatedDate); 
                    }
            }
        }
        for(List<Opportunity> oppyList : [Select Id, Last_Call_Log_Date__c from Opportunity where Id IN :tskMap.get(tsk.WhatId)])
            {
                for(Opportunity Oppy : oppyList)
                {

                }

            }

I am thinking that is has something to do with GET, but that seems to give me an error stating that the variable do not exist.

Can someone assist please? Thank you

5

Try:

Select Id, Last_Call_Log_Date__c from Opportunity where Id IN :tskMap.KeySet()

Using .KeySet() on a map, you'll get a list of all the keys returned.

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.