+ Start a Discussion
Geoffrey CGeoffrey C 

The Word 'New' In Picklist Field Affecting Updating Trigger.

I have a custom object call 'Complaints' which has a status picklist field.  I created a trigger to write a record (another custom object called Complaint Status Record, I'll call it CSR for short) when the Status is changed.  The trigger does not work when the the status is 'New' when the complaint record is first created.

Senario 1

- Create a Complaint, default status 'New'

- Edit Complaint, Change status 'New' to 'Step 1' - No  CSR **BAD**

- Edit Complaint, Change status 'Step 1' to 'Step 2' - CSR Created *Good*

From here I can change it to anything. New, Step 3, Step 15, Closed, etc., it will create a CSR record.


Senario 2 - Edit Status Field.  Change default status to 'Step 1'

CSR writes on 1st update and all updates after. (It works correctly)


Senario 3 - Edit Status Field.  Change back to 'New' but rename to 'New Complaint'

CSR writes 1st update and all updates after. (It works correctly)


Senario 4 - change Status back to 'New' uncheck default box.

Same symptoms as Senario 1.


I checked all Workflow Rules, deactivated all the rules on complaints at one point.  No change.  I checked triggers, no triggers that should affect complaints at all (at least to my knowledge).


Is 'New' in a status field a reserved word?


I don't think there should be any issue using New as one of the picklist value and defalting it to that.


I just wrote this trigger based on ur scenario:


trigger ComplainTrigger on Complain__c (after update)

List<Complain__c> compalainForWhichToCreateCSR = new List<Complain__c>();
for(Complain__c oldComplain : Trigger.old )
Complain__c newComplain = Trigger.newMap.get(oldComplain.Id);
//just for creating only when the status changes
if(oldComplain.Status__c != newComplain.Status__c)
List<CSR__c> csrToCreate = new List<CSR__c>();
for(Complain__c theComplain : compalainForWhichToCreateCSR)
CSR__c theCsr = new CSR__c();
theCsr.Complain__c = theComplain.Id;

insert csrToCreate;


This seems to work as expected.I have New,Step 1 and Step 2 picklist value on the Statud field on the Custom object Status field.So, when the record gets created status is defaulted to New.And when I change the status to Step 1 from New.CSR record gets created.GOOD.


I hope this helps or else there is something wierd in your org.Did u test in all orgs u have like different sandbox or maybe just your persoanl dev org because ur requirements seems quite straight forward.


Hope it helps.

Geoffrey CGeoffrey C

Thanks for the reply.  I recently started at my company in Nov., and I am taking over Administration of an  instance of SDFC that was that was implemented in 2007.  So there could be something that I don't know about.  but here is my code.  (I'm not a developer but I had some programming schooling back in the late 90s so forgive me if I'm slow.  I just researched and put this together.)



trigger Complaint_Status_Record_Insert on Complaint__c (after update) {
    //Assign the context before and after the change into a Map
    Map<Id, Complaint__c> newComplaintMap = Trigger.newMap;
    Map<Id, Complaint__c> oldComplaintMap = Trigger.oldMap;

    //Loop through the map
    for(Id ComplaintId:newComplaintMap.keySet()){
        Complaint__c myNewStatus = newComplaintMap.get(ComplaintId);
        Complaint__c myOldStatus = oldComplaintMap.get(ComplaintId);
        if (myNewStatus.Previous_Complaint_Status__c <> myOldStatus.Previous_Complaint_Status__c){
            list <Complaint_Status_Record__c> AddCSR = new list <Complaint_Status_Record__c> ();
                for ( Complaint__c C : Trigger.new) {
                    AddCSR.add(new Complaint_Status_Record__c(
                        Complaint__c = c.Id,
                        Status_Change_Date__c = date.today(),               
                        Status_Change__c = c.Complaint_Status__c,
                        Previous_Status__c = c.Previous_Complaint_Status__c,
                        Days_In_Previous_Status__c = c.Days_In_Previous_Status__c)); 
        insert AddCSR;



Thanks Again,





It looks like you only have after update and not after insert.  That would explain why it doesn't execute after the initial insert / record creation..

trigger Complaint_Status_Record_Insert on Complaint__c (after insert, after update) {




Geoffrey CGeoffrey C



Then why does my other scenarios work besides the 1st and last that starts with 'New'?


BTW I don't need to create a record upon creation.  Just when teh status is changed.


Thanks for looking at the code,