You need to sign in to do that
Don't have an account?
Chuck 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);}
}
}
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);}
}
}
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);
}
}
Event : DML_BEGIN Details: [14]Op:Insert|Status_report_c|Rows:1