function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SteveOrg93SteveOrg93 

Create activity after Lead Status is changed

Hi Everyone, I was hoping I could get some insights as to what might be wrong with my trigger.  I have the following trigger I would like to run when a lead status within the lead is changed to a particular value.  When the value is changed, I would like to create a new activity on the lead record.  

 

Here is my code below, and the error I get back is:

 

Error: Compile Error: No access to entity: Activity at line 1 column 1

 

Any help would be greatly appreciated!

 

 

trigger createLeadActivity on Lead (after update) { 

    //make a set to hold opportunity ids that we need
    Set<Id> leadIds = new Set<Id>();
    
    for(Lead l : trigger.new)
        {
        //check to see if our field has been changed
        if(l.status != trigger.oldMap.get(l.Id).Status){
            
            leadIds.add(l.Id);
            
        }

       }
    
    if(!leadIds.isEmpty()){
        
       
        
        List<Lead> leadList = 
            [SELECT Id,Status
            FROM Lead
            WHERE Status = '4 - SAL Engaged' AND Id IN :leadIds ];
        
        
        
        for(Lead leadly: leadList){
        Lead led = new Activity();
        
       
        
        
       
        Activity newActivity = new Activity(Subject='LeadPassed',OwnerId=leadMap.get( record.WhoId ).OwnerId,Status='Not Started',Priority='Normal',WhoId=leadMap.get( record.WhoId ).id);

        ActList.add(newActivity);
        }
       
    }


}

 

Best Answer chosen by Admin (Salesforce Developers) 
CoolSurenCoolSuren

Hi Steve,

 

   Yes Puja is correct. There is no object in the activity in salesforce. for that we can use Task or Event object.

 

for example in your trigger you used the following,

  

Activity newActivity = new Activity(Subject='LeadPassed',OwnerId=leadMap.get( record.WhoId ).OwnerId,
                                Status='Not Started',Priority='Normal',WhoId=leadMap.get( record.WhoId ).id);

 

Changed the above code like the following :

 

Task newActivity = new Task(Subject='LeadPassed',OwnerId=leadMap.get( record.WhoId ).OwnerId,
Status='Not Started',Priority='Normal',WhoId=leadMap.get( record.WhoId ).id);

 

and refer the following link for available salesforce standard objects :

 

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_objects_profile.htm|StartTopic=Content%2Fsforce_api_objects_profile.htm|SkinName=webhelp

All Answers

Puja_mfsiPuja_mfsi

Hi,

In salesforce there is no such object with name "Activity" ,there is two objects related to Activity i.e. Event and  task.

If you want to create any Activity,either you create a new task or new event.

CoolSurenCoolSuren

Hi Steve,

 

   Yes Puja is correct. There is no object in the activity in salesforce. for that we can use Task or Event object.

 

for example in your trigger you used the following,

  

Activity newActivity = new Activity(Subject='LeadPassed',OwnerId=leadMap.get( record.WhoId ).OwnerId,
                                Status='Not Started',Priority='Normal',WhoId=leadMap.get( record.WhoId ).id);

 

Changed the above code like the following :

 

Task newActivity = new Task(Subject='LeadPassed',OwnerId=leadMap.get( record.WhoId ).OwnerId,
Status='Not Started',Priority='Normal',WhoId=leadMap.get( record.WhoId ).id);

 

and refer the following link for available salesforce standard objects :

 

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_objects_profile.htm|StartTopic=Content%2Fsforce_api_objects_profile.htm|SkinName=webhelp

This was selected as the best answer