You need to sign in to do that
Don't have an account?
Jo Higgerson
Trigger causes incident ID to increment more than 1
I have a trigger that works fine, it populates the fields it was designed to populate but when it run before insert it causes the id number to increment more than 1. Below is my trigger code:
trigger ICNFill on BMCServiceDesk__Incident__c (before insert, before update) {
List<BMCServiceDesk__Incident__c> ICNIncident = Trigger.new;
String CircNo = ICNIncident[0].ICN_Circuit_No__c;
if(String.isNotBlank(CircNo)) {
Integer len;
len = CircNo.length();
if(len > 0) {
List<BMCServiceDesk__BMC_BaseElement__c> ICNList = [Select ICN_Channel_No__c,
ICN_Circuit_Status__c,
ICN_Circuit_Type__c,
ICN_Site_Business_Phone__c,
ICN_Cell_Phone__c,
ICN_Operation_Hours__c,
ICN_Managed_By__c,
ICN_Org_Name__c,
ICN_Rate_Limit_Amount__c,
ICN_Router_Interface__c,
ICN_Router_Name__c,
ICN_Site_Address__c,
ICN_Site_City__c,
ICN_Site_ID__c,
ICN_Site_Name__c,
ICN_Site_Phone__c,
ICN_Site_Zip_Code__c,
ICNZendRTC__c,
ICNZendMSA__C,
ICN_Parent_Circuit__c,
ICNAendRTC__c,
ICNAendMSA__c,
ICN_Comments__c,
ICN_First_Name__c,
ICN_Last_Name__c,
ICN_MLPP_MFR_VLAN_No__c
from BMCServiceDesk__BMC_BaseElement__c where ID = :CircNo];
ICNIncident[0].ICN_Channel_No__c = ICNList[0].ICN_Channel_No__c;
ICNIncident[0].ICN_Circuit_Status__c = ICNList[0].ICN_Circuit_Status__c;
ICNIncident[0].ICN_Contact_Business_Phone__c = ICNList[0].ICN_Site_Business_Phone__c;
ICNIncident[0].ICN_Contact_Cell_Phone__c = ICNList[0].ICN_Cell_Phone__c;
ICNIncident[0].ICN_Managed_By__c = ICNList[0].ICN_Managed_By__c;
ICNIncident[0].ICN_Org_Name__c = ICNList[0].ICN_Org_Name__c;
ICNIncident[0].ICN_Rate_Limit_Amount__c = ICNList[0].ICN_Rate_Limit_Amount__c;
ICNIncident[0].ICN_Router_Interface__c = ICNList[0].ICN_Router_Interface__c;
ICNIncident[0].ICN_Router_Name__c = ICNList[0].ICN_Router_Name__c;
ICNIncident[0].ICN_Site_Address1__c = ICNList[0].ICN_Site_Address__c;
ICNIncident[0].ICN_Site_City__c = ICNList[0].ICN_Site_City__c;
ICNIncident[0].ICN_Site_ID__c = ICNList[0].ICN_Site_ID__c;
ICNIncident[0].ICN_Site_Name__c = ICNList[0].ICN_Site_Name__c;
ICNIncident[0].ICN_Site_Phone__c = ICNList[0].ICN_Site_Phone__c;
ICNIncident[0].ICN_Site_Zip_Code__c = ICNList[0].ICN_Site_Zip_Code__c;
ICNIncident[0].ICNZendRTC__c = ICNList[0].ICNZendRTC__c;
ICNIncident[0].ICNZendMSA__c = ICNList[0].ICNZendMSA__c;
ICNIncident[0].ICNAendRTC__c = ICNList[0].ICNAendRTC__c;
ICNIncident[0].ICNAendMSA__c = ICNList[0].ICNAendMSA__c;
ICNIncident[0].ICN_Parent_Circuit__c = ICNList[0].ICN_Parent_Circuit__c;
ICNIncident[0].ICNSite_Contact_First_Name__c = ICNList[0].ICN_First_Name__c;
ICNIncident[0].ICNSite_Contact_Last_Name__c = ICNList[0].ICN_Last_Name__c;
ICNIncident[0].ICN_Circuit_Type__c = ICNList[0].ICN_Circuit_Type__c;
ICNIncident[0].ICNMLPP_MFR_VLAN_No__c = ICNList[0].ICN_MLPP_MFR_VLAN_No__c;
ICNIncident[0].ICN_Comments__c = ICNList[0].ICN_Comments__c;
}
}
}
Any help would be greatly appreciated. I'm new at this!!
trigger ICNFill on BMCServiceDesk__Incident__c (before insert, before update) {
List<BMCServiceDesk__Incident__c> ICNIncident = Trigger.new;
String CircNo = ICNIncident[0].ICN_Circuit_No__c;
if(String.isNotBlank(CircNo)) {
Integer len;
len = CircNo.length();
if(len > 0) {
List<BMCServiceDesk__BMC_BaseElement__c> ICNList = [Select ICN_Channel_No__c,
ICN_Circuit_Status__c,
ICN_Circuit_Type__c,
ICN_Site_Business_Phone__c,
ICN_Cell_Phone__c,
ICN_Operation_Hours__c,
ICN_Managed_By__c,
ICN_Org_Name__c,
ICN_Rate_Limit_Amount__c,
ICN_Router_Interface__c,
ICN_Router_Name__c,
ICN_Site_Address__c,
ICN_Site_City__c,
ICN_Site_ID__c,
ICN_Site_Name__c,
ICN_Site_Phone__c,
ICN_Site_Zip_Code__c,
ICNZendRTC__c,
ICNZendMSA__C,
ICN_Parent_Circuit__c,
ICNAendRTC__c,
ICNAendMSA__c,
ICN_Comments__c,
ICN_First_Name__c,
ICN_Last_Name__c,
ICN_MLPP_MFR_VLAN_No__c
from BMCServiceDesk__BMC_BaseElement__c where ID = :CircNo];
ICNIncident[0].ICN_Channel_No__c = ICNList[0].ICN_Channel_No__c;
ICNIncident[0].ICN_Circuit_Status__c = ICNList[0].ICN_Circuit_Status__c;
ICNIncident[0].ICN_Contact_Business_Phone__c = ICNList[0].ICN_Site_Business_Phone__c;
ICNIncident[0].ICN_Contact_Cell_Phone__c = ICNList[0].ICN_Cell_Phone__c;
ICNIncident[0].ICN_Managed_By__c = ICNList[0].ICN_Managed_By__c;
ICNIncident[0].ICN_Org_Name__c = ICNList[0].ICN_Org_Name__c;
ICNIncident[0].ICN_Rate_Limit_Amount__c = ICNList[0].ICN_Rate_Limit_Amount__c;
ICNIncident[0].ICN_Router_Interface__c = ICNList[0].ICN_Router_Interface__c;
ICNIncident[0].ICN_Router_Name__c = ICNList[0].ICN_Router_Name__c;
ICNIncident[0].ICN_Site_Address1__c = ICNList[0].ICN_Site_Address__c;
ICNIncident[0].ICN_Site_City__c = ICNList[0].ICN_Site_City__c;
ICNIncident[0].ICN_Site_ID__c = ICNList[0].ICN_Site_ID__c;
ICNIncident[0].ICN_Site_Name__c = ICNList[0].ICN_Site_Name__c;
ICNIncident[0].ICN_Site_Phone__c = ICNList[0].ICN_Site_Phone__c;
ICNIncident[0].ICN_Site_Zip_Code__c = ICNList[0].ICN_Site_Zip_Code__c;
ICNIncident[0].ICNZendRTC__c = ICNList[0].ICNZendRTC__c;
ICNIncident[0].ICNZendMSA__c = ICNList[0].ICNZendMSA__c;
ICNIncident[0].ICNAendRTC__c = ICNList[0].ICNAendRTC__c;
ICNIncident[0].ICNAendMSA__c = ICNList[0].ICNAendMSA__c;
ICNIncident[0].ICN_Parent_Circuit__c = ICNList[0].ICN_Parent_Circuit__c;
ICNIncident[0].ICNSite_Contact_First_Name__c = ICNList[0].ICN_First_Name__c;
ICNIncident[0].ICNSite_Contact_Last_Name__c = ICNList[0].ICN_Last_Name__c;
ICNIncident[0].ICN_Circuit_Type__c = ICNList[0].ICN_Circuit_Type__c;
ICNIncident[0].ICNMLPP_MFR_VLAN_No__c = ICNList[0].ICN_MLPP_MFR_VLAN_No__c;
ICNIncident[0].ICN_Comments__c = ICNList[0].ICN_Comments__c;
}
}
}
Any help would be greatly appreciated. I'm new at this!!
https://developer.salesforce.com/page/Best_Practice%3A_Bulkify_Your_Code
For your problem, you need to understand the order of execution. when inserting the record, the triger might be called multiple time (One for Insert and One for any field update you have (using workflow rule etc)). you could try avoiding recursive run. have a look at the below link
https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US