You need to sign in to do that
Don't have an account?
Divya Samudrala 4
Hi Everyone,
I need test class for my trigger which copies details from obj1(Loaner Request Form) to obj2(Equipment Request) after insert on obj1(Loaner Request form).Kinldy help me on this one.Thanks in advance.
trigger InsertToEquipmentRequest on Loaner_Requests_Form__c (after insert) {
List <ELTON__Equipment_Request__c> EQRINSERT = new List <ELTON__Equipment_Request__c>();
Map<Id,List<String>> mapEquipmentTypes = new Map<Id,List<String>>();
Set<String> setType = new Set<String>();
Map<String,Id> mapEquipmentType = new Map<String,Id>();
for (Loaner_Requests_Form__c LRF:Trigger.new)
{
List<String> lstEquipmentTypes = LRF.Equipment_Type_Multi__c.split(';');
mapEquipmentTypes.put(LRF.id,lstEquipmentTypes);
for(String s : lstEquipmentTypes){
setType.add(s);
}
//setType.add(LRF.Equipment_Type__c);
}
System.debug('Equipment TYpe = ' + setType);
If(setType != Null && !setType.isEmpty())
{
for(ELTON__Equipment_Type__c e : [Select Id,name from ELTON__Equipment_Type__c where Name In :setType])
{
mapEquipmentType.put(e.name,e.id);
}
}
System.debug('mapEquipmentType = ' +mapEquipmentType);
for (Loaner_Requests_Form__c LRF:Trigger.new)
{
for(String s :mapEquipmentTypes.get(LRF.Id)) {
System.debug('Equipment TYpe 1 = ' +LRF.Equipment_Type__c);
ELTON__Equipment_Request__c EQR = new ELTON__Equipment_Request__c ();
EQR.Full_Name__c= LRF.Full_Name__c;
EQR.Department__c= LRF.Department__c;
EQR.Office_Location__c= LRF.Office_Location__c;
EQR.Mission_Name__c= LRF.Mission_Name__c;
EQR.Location__c= LRF.Travel_Location__c;
EQR.ELTON__Request_Start_Date__c= LRF.Travel_Start_Date__c;
EQR.ELTON__Request_Return_Date__c= LRF.Travel_End_Date__c;
EQR.Request_Sent_By__c= LRF.Request_Sent_By__c;
EQR.Requesting_for__c= LRF.Requesting_for__c;
EQR.ELTON__User__c= LRF.Requesting_for__c;
EQR.Requested_User__c= LRF.Loaner_Requester_Name__c;
EQR.Pick_up_Location__c= LRF.Pick__c;
EQR.Name__c= LRF.Name__c;
EQR.Email_Address__c= LRF.Email_Address__c;
EQR.Date__c= LRF.Requested_Date__c;
EQR.Phone__c= LRF.Phone__c;
EQR.ELTON__Request_Note__c=LRF.Note__c;
EQR.Equipment_Type_Multi__c =LRF.Equipment_Type_Multi__c;
//EQR.ELTON__Equipment_Type__c=mapEquipmentType.get(LRF.Equipment_Type__c);
EQR.ELTON__Equipment_Type__c=mapEquipmentType.get(s);
EQRINSERT.add(EQR);
}
}
insert EQRINSERT ;
}
Test class for after insert event
Hi Everyone,
I need test class for my trigger which copies details from obj1(Loaner Request Form) to obj2(Equipment Request) after insert on obj1(Loaner Request form).Kinldy help me on this one.Thanks in advance.
trigger InsertToEquipmentRequest on Loaner_Requests_Form__c (after insert) {
List <ELTON__Equipment_Request__c> EQRINSERT = new List <ELTON__Equipment_Request__c>();
Map<Id,List<String>> mapEquipmentTypes = new Map<Id,List<String>>();
Set<String> setType = new Set<String>();
Map<String,Id> mapEquipmentType = new Map<String,Id>();
for (Loaner_Requests_Form__c LRF:Trigger.new)
{
List<String> lstEquipmentTypes = LRF.Equipment_Type_Multi__c.split(';');
mapEquipmentTypes.put(LRF.id,lstEquipmentTypes);
for(String s : lstEquipmentTypes){
setType.add(s);
}
//setType.add(LRF.Equipment_Type__c);
}
System.debug('Equipment TYpe = ' + setType);
If(setType != Null && !setType.isEmpty())
{
for(ELTON__Equipment_Type__c e : [Select Id,name from ELTON__Equipment_Type__c where Name In :setType])
{
mapEquipmentType.put(e.name,e.id);
}
}
System.debug('mapEquipmentType = ' +mapEquipmentType);
for (Loaner_Requests_Form__c LRF:Trigger.new)
{
for(String s :mapEquipmentTypes.get(LRF.Id)) {
System.debug('Equipment TYpe 1 = ' +LRF.Equipment_Type__c);
ELTON__Equipment_Request__c EQR = new ELTON__Equipment_Request__c ();
EQR.Full_Name__c= LRF.Full_Name__c;
EQR.Department__c= LRF.Department__c;
EQR.Office_Location__c= LRF.Office_Location__c;
EQR.Mission_Name__c= LRF.Mission_Name__c;
EQR.Location__c= LRF.Travel_Location__c;
EQR.ELTON__Request_Start_Date__c= LRF.Travel_Start_Date__c;
EQR.ELTON__Request_Return_Date__c= LRF.Travel_End_Date__c;
EQR.Request_Sent_By__c= LRF.Request_Sent_By__c;
EQR.Requesting_for__c= LRF.Requesting_for__c;
EQR.ELTON__User__c= LRF.Requesting_for__c;
EQR.Requested_User__c= LRF.Loaner_Requester_Name__c;
EQR.Pick_up_Location__c= LRF.Pick__c;
EQR.Name__c= LRF.Name__c;
EQR.Email_Address__c= LRF.Email_Address__c;
EQR.Date__c= LRF.Requested_Date__c;
EQR.Phone__c= LRF.Phone__c;
EQR.ELTON__Request_Note__c=LRF.Note__c;
EQR.Equipment_Type_Multi__c =LRF.Equipment_Type_Multi__c;
//EQR.ELTON__Equipment_Type__c=mapEquipmentType.get(LRF.Equipment_Type__c);
EQR.ELTON__Equipment_Type__c=mapEquipmentType.get(s);
EQRINSERT.add(EQR);
}
}
insert EQRINSERT ;
}
Please try below code: Let me know if you still face the issues, or contact me via email: gauravgarg.nmim@gmail.com, skype: gaurav62990
Thanks,
Gaurav
All Answers
Please try below code: Let me know if you still face the issues, or contact me via email: gauravgarg.nmim@gmail.com, skype: gaurav62990
Thanks,
Gaurav
Thank you so much..