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
Kraftti1Kraftti1 

Trigger not firing in Dev account

I created a custom object that i would like to trigger the creation of a Case when the object is created or updated with an open status. I found a previously writen trigger that I am using:

 

trigger CreateCase on PE_Case__c(After Update)

{

    if(Trigger.isUpdate){
        for(PE_Case__c  p: Trigger.new)

       {

          if(p.Status__c == 'Open')

          {

               Case cs = new Case();

              

                  cs.Reason = 'Internal';

 

                insert c;

          }
        
        }
    } 

}

 

Saleforce is accepting the trigger with no errors, but it is not firing.

 

Any help would be appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
XhitmanXhitman

Since you mentioned that you would like the trigger to act upon insert and upon update.

 

I've optimized the code for bulk processing. Please check the following code:

 

 

trigger CreateCase on PE_Case__c(After Insert, After Update)
{
List<Case> casesToInsert = new List<Case>();
for(PE_Case__c  p: Trigger.new)
{
if(p.Status__c == 'Open')
{
  Case cs = new Case();
  cs.Reason = 'Internal';
  casesToInsert.add(cs);
}
}
if(!casesToInsert.isEmpty())
insert casesToInsert;
     
}
trigger CreateCase on PE_Case__c(After Insert, After Update)
{
	List<Case> casesToInsert = new List<Case>();
	for(PE_Case__c  p: Trigger.new)
	{
		if(p.Status__c == 'Open')
		{
		   Case cs = new Case();
		   cs.Reason = 'Internal';
		   casesToInsert.add(cs);
		}
	}
	if(!casesToInsert.isEmpty())
		insert casesToInsert;
     
}

 

 

Hope it helps!

All Answers

kbromerkbromer

The trigger is for After Update only, so creation of a new PE_Case__c record won't fire the trigger.

 

Also, make sure your trigger is set to be both Active and Valid under the trigger menu (Setup->Develop->Apex Triggers) A trigger is set to valid once the code fires, if it isn't already.

Kraftti1Kraftti1

The trigger is showing a status of Active and has a check mark for Is Valid.

 

Understanding it will not create a ticket at creation, I had temp changed to try to make it work at least for an After Update. I even tried Before Update to see if that would work, but it is still not firing..

 

Thank you for the feedback... assistance is very much appreciated.

User@SVFUser@SVF

Kraftti1,

 

Just check the insert statement. You are declaring the case variable as cs, but while inserting you are issuing insert c.

change it to insert cs and it should work.

 

Aslo do use system.debug, for the checking if the control is being passed to the trigger or not and make best utilization of the debug logs.

 

Hope it helps

XhitmanXhitman

Since you mentioned that you would like the trigger to act upon insert and upon update.

 

I've optimized the code for bulk processing. Please check the following code:

 

 

trigger CreateCase on PE_Case__c(After Insert, After Update)
{
List<Case> casesToInsert = new List<Case>();
for(PE_Case__c  p: Trigger.new)
{
if(p.Status__c == 'Open')
{
  Case cs = new Case();
  cs.Reason = 'Internal';
  casesToInsert.add(cs);
}
}
if(!casesToInsert.isEmpty())
insert casesToInsert;
     
}
trigger CreateCase on PE_Case__c(After Insert, After Update)
{
	List<Case> casesToInsert = new List<Case>();
	for(PE_Case__c  p: Trigger.new)
	{
		if(p.Status__c == 'Open')
		{
		   Case cs = new Case();
		   cs.Reason = 'Internal';
		   casesToInsert.add(cs);
		}
	}
	if(!casesToInsert.isEmpty())
		insert casesToInsert;
     
}

 

 

Hope it helps!

This was selected as the best answer
Kraftti1Kraftti1

Thanks to all for the help...

 

Xhitman - Your the man...