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
Chuck HarveyChuck Harvey 

Trigger will not create a new record

The trigger I created is saving and running but it does not create  a new record.  I am putting information in a custom object called Customer Fact Sheet and moving the data into Status Report.  In the developer console does not show problems.  Does anyone see a prolem with the trigger?

Customer_Fact_Sheet__c = Source object
Status_Report__c = Target object

trigger InsertStatusReport on Customer_Fact_Sheet__c  (after insert)
{  for (Customer_Fact_Sheet__c cfs : Trigger.new)
        String cid = cfs.
{try{    Status_Report__c sta = new Status_Report__c();
        // Insert new Status record
        system.debug(cfs.Project_c__c);
        sta.Status_Unique_ID__c = '12a';
        sta.Project__c = cfs.Project_c__c;
     insert sta;
   }
 catch (Exception e) {system.debug('Exception'+e);}
   }
}
 
Harold Crouse 8Harold Crouse 8

Hi,
First you need to bulkify your trigger.  Second you don't have brackets around your for(Customer_FAct_Sheet__c cfs: TriggerNew)
  So your loop is only performing the first line String cid = cfs;
Try this code:

trigger InsertStatusReport on Customer_Fact_Sheet__c  (after insert)

    list<Status_Report__c> listSTA = new List<Status_Report__c>();
     for (Customer_Fact_Sheet__c cfs : Trigger.new){ 
          String cid = cfs.
          Status_Report__c sta = new Status_Report__c();
          // Insert new Status record
            system.debug(cfs.Project_c__c);
            sta.Status_Unique_ID__c = '12a';
            sta.Project__c = cfs.Project_c__c;
           listInsertSTA.add(sta);
    }
try{
     insert listInsertSTA;
  }
 catch (Exception e) {
      system.debug('Exception'+e);
   }

 
Chuck HarveyChuck Harvey
Thank you for the quick response.   I ran the code and in the Developer Console is looks like it ran properly but no insert.
Event : DML_BEGIN   Details:  [14]Op:Insert|Status_report_c|Rows:1
 
Harold Crouse 8Harold Crouse 8
I would add a debug statement right before the Insert statement to see if it's firing.  After you do can you post the entire debug log and the code the way you have it now?
Chuck HarveyChuck Harvey
Thank you,  The new code worked.  The code was running but I did not see it in the Status Report until I refreshed Status Report view.