You need to sign in to do that
Don't have an account?

Please help me to write a trigger on lead with given requirement.
If we have one related custom object(Folder) on lead which has industry picklist different values. We create custom setting and different records of custom setting and now one field checkbox -isactive.if industry value = technology on Folder object, records should be created automatically with name of custom setting values where checkbox true and industry value should be associated with records
Based on my understanding on creation of folder record on some value basis you are trying to insert records on lead with values you have predefined in custom setttings based on their activeness. Based on this assumption please see the below code which will help you to build the total logic suiting your requirement.
trigger folerobject on Folder__c (after insert){
if(Trigger.isInsert && Trigger.isAfter){
List<Lead> leadLst = new List<Lead>();
for(Folder__c fld: Trigger.new){
if(fld.Industry__c == 'Technology'){
List<CustomSettingsObject> csRecrds = CustomSettingsObject.getall().values();
for(CustomSettingsObject cb: csRecrds){
if(cb.isActive__c){
Lead ld = new Lead();
ld.name=cb.Name__c;
ld.Industry=fld.Industry__c;
leadLst.add(ld);
}
}
}
}
if(leadLst.size()>0){
insert leadLst;
}
}
}
Thanks,
Vivek
But my trigger will be on lead object and events will be after insert and before update.
Now i want to create Records of Folder object automatically when lead.industry = folder.industry.
Now the name of Records will be name of custom setting records.
Lastly these records should be visible on related list of lead object.Please Suggest best approach and send your contact if possible.