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
Shawn C KingShawn C King 

Task Trigger

Does anyone know why an Activity is not showing up when I edit my BeazerLot__c object although I have made the following trigger code:

 

trigger CreateTaskonCloseofDateEscrow45DayCall on BeazerLot__c (after update) {


BeazerLot__c b = new BeazerLot__c ();


Task t = new Task();
t.OwnerID = trigger.new[0].Ownerid; //trigger.new[0].DefaultCaseOwner__c;
t.Subject = '45 Day Call';

insert t;

}

Best Answer chosen by Admin (Salesforce Developers) 
Shawn C KingShawn C King

Yes, I will mark it as solution when I get it to show up on my BeazerLot screen.  You have been an invaluable help!  So if I understand correctly you are saying there is literally something called whatid?  So would this code be adequate: (I've added the line before .add(t) statement)

 

trigger CreateTaskonCloseofDateEscrow45DayCall on BeazerLot__c (after update) {

List<Task> tasklist = new List<Task>{};

for(BeazerLot__c b:Trigger.new){
   Task t = new Task();
   t.OwnerID = b.Ownerid;
   t.Subject = '45 Day Call';
t.whatid = b.id tasklist.add(t); } insert tasklist; }

 

All Answers

Maf_007Maf_007
trigger CreateTaskonCloseofDateEscrow45DayCall on BeazerLot__c (after update) {

List<Task> tasklist = new List<Task>{};

for(BeazerLot__c b:Trigger.new){
   Task t = new Task();
   t.OwnerID = b.Ownerid;
   t.Subject = '45 Day Call';
   tasklist.add(t);
}

insert tasklist;

}

 

Try above code, should work.

 

Please mark as solution if this helped you.

 

Many Thanks,

Maf

Shawn C KingShawn C King

Hello Maf, this also did not work. i am expecting the tasks.. so show up in Open Activities but see nothing.  I ran a job from the database and under Beazer Lot History, it shows updates.  I also tried to edit the address field to get the trigger to fire and nothing.  Is there anything else you can think of

Maf_007Maf_007

Hi,

 

Could you please check if your trigger is active for me. This trigger should create a task everytime you update your custom object.

 

Thanks,

Maf

Shawn C KingShawn C King

Maf, thanks for your quick response, I am extremly new to SalesForce and have a tight deadline.  Yes the Status is Active

 

 

Maf_007Maf_007

Hi, I have checked the trigger just now and it has created a task for me. Go to home page and on calendar click activity list view you will see your task. Or enable related list on the object...

Shawn C KingShawn C King

Oh, cool I see it on the Home Page.  however I need it to show up in the Beazer Lot Page under open activities and it is not, any idea why?

Maf_007Maf_007

Hello,

 

You need to give what id to the task.

 

like task.whatid = object.id;

 

 

Could you also mark as solution if that helped you??

Shawn C KingShawn C King

Yes, I will mark it as solution when I get it to show up on my BeazerLot screen.  You have been an invaluable help!  So if I understand correctly you are saying there is literally something called whatid?  So would this code be adequate: (I've added the line before .add(t) statement)

 

trigger CreateTaskonCloseofDateEscrow45DayCall on BeazerLot__c (after update) {

List<Task> tasklist = new List<Task>{};

for(BeazerLot__c b:Trigger.new){
   Task t = new Task();
   t.OwnerID = b.Ownerid;
   t.Subject = '45 Day Call';
t.whatid = b.id tasklist.add(t); } insert tasklist; }

 

This was selected as the best answer
Maf_007Maf_007

Yes that should show that in related list

Shawn C KingShawn C King

it works, thanks for your help Maf

Maf_007Maf_007

No Worries, Have a good day....:)