You need to sign in to do that
Don't have an account?
sreenath reddy 21
Hi all,This is the question asked in interview, how to solve it, please help me
trigger creation Help
Hi all,This is the question asked in interview, how to solve it, please help me
Please try like below :
Thanks,
Maharajan.C
All Answers
Please try like below :
Thanks,
Maharajan.C
Small changes,
trigger CreateRecord on Company__c (after insert) {
set<string> prodSet = new set<string>();
Map<String,Id> prodMap = new Map<String,Id>();
List<Company_Product_Relationship__c> cprList = new List<company_Product_Relationship__c>();
for(company__c comp : Trigger.New){
if(comp.product__c != null){
prodSet.addAll(comp.product__c.split(';'));
}
}
for(product__c prod : [Select Id,Name from product__c where Name IN: prodSet ]){
prodMap.put(prod.Name, prod.Id);
}
for(company__c comp : Trigger.New){
if(comp.product__c != null){
for(String str : comp.product__c.split(';')){
company_Product_Relationship__c cpr = new company_Product_Relationship__c(company__c = comp.Id, product__c = prodMap.get(str));
cprList.add(cpr);
}
}
}
if(!cprList.IsEmpty())
insert cprList;
}