I tried lots of searching still not able to find any worth documentation related to task, events, task items online. Could you pleaes guide where i can find all these stuffs, i need to undertand all task and event of salesforce to implement it my requirement. I am working on requiremt like where i have find out something like..

if(all tasks of opportunities are close){
//wire web service call etc

  • if you are happy with the answer then close this question Commented Jul 19, 2016 at 1:45

1 Answer 1


Here, I have tried to show if opportunities are getting closed then it will search for any open tasks exists. If open task exists it will throw the error. Otherwise, you can proceed to call webservice.

Just to let you know, I have not compiled the code but to show you how the scenario to be handled.

Sample code will look type this

trigger OpportunityTrigger on Opportunity (after update) {

// Find all opportunities that are being closed...
Set<Id> newlyCloseOpptyIds = new Set<Id>();
for (Id opportunityId : Trigger.newMap.keySet()) {
    if ((Trigger.newMap.get(opportunityId).Stage && 
        && Trigger.newMap.get(opportunityId).Stage.equals('Closed Won')){

for (AggregateResult aggResult : [
        Select Count(Id), WhatId
        From Task
        Where WhatId In :newlyCloseOpptyIds
              And IsClosed = false
        Group by WhatId
        Having Count(Id) > 0
]) {
    Id opportunityId = (Id) aggResult.get('WhatId');
    Opportunity errorOpportunity = Trigger.newMap.get(opportunityId);

    // change error message as appropriate...
    errorOpportunity.addError('All the tasks are not closed' + errorOpportunity.Name); 
//now perform webservice call.  

For documentation on Task and Events you can refer following links:

Task and Event Objects

Salesforce activities need to know

They are many other materials available. You can do a research on that.

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