+ Start a Discussion
Geoffrey CGeoffrey C 

Trigger Does Not Create 1st Record.



I created a an object to hold history of a status change indefinitely (SDFC states it only holds history for 18 months). 

There there is a complaint__c object that was created before previously.  I created a new object call Complaint_Status_Record__c to record status changes.  I also created a trigger a trigger to create a new record when the Complaint's Status is changed.   But the 1st status update does not record.....all time.


Scenario 1.

1.) Create a Complaint Record.  NO CSR (Complaint Status Record) is created.  OK created not updated....Status is 'New' by default

2.) Edit Complaint Record, change status 'CS Investigated'. No CSR is created.  BAD. It should create a record.

3.) Edit again, change status to anything else. A CSR is created.  Good


*At this point I can change a status to new, are record is created, and then change it from new to anything else and it still works.  its only the first update.


Senario 2.

1.) Create a Complaint Record BUT I don't take the default I choose 'CS Investigated'. No CSR Record OK.

2.) Edit Compalaint Record, change status to anything else.  Good...It works.


Senario 3.

One time in Production, and Existing New Complaint Record was changed and it created a CSR record. I'm not sure why this worked and if it was existing before I deployed the CSR changes.


OK I tried to paste the trigger, but the formating off.  Does anyone have an idea before paste and format the trigger?




Seems one of those problem where you need a second pair of eyes. According to what you are saying that should work.

I think you probably did this like looking at  debug logs and check out if your insert dml occurs or not on first update with New  status to something else? Do you have a unit test written for it and does it fail there as well?


Is there any workflow rule very specific for a case when the Status changes from  New to something?


If I were you I would lok into those stuffs. 


If possible put the code.



Whether u have written the trigger to hit while inserting the record,

Or else, While inserting trigger.old will be null, so the condition may fail at that time, so it may create problem,


Not sure, If you could paste the trigger, we can trace it out.

Geoffrey CGeoffrey C

Thank You for the replies.  After testing more senarios, it is the 'New' in the status pick list.  If I edit the selection and call it 'New Complaint'.  It works.  If I change the default to another selection in the pick list, it works.  If I change status from another selection back to 'New' then edit again it still works.  It's just when its defauIted to 'New' upon creation pf a complaint.  I checked all the workflows related to the complaint object and even deactivated them and I still get the same error.  I also looked the other triggers.  Where else can be affecting this besides other triggers and workflows?