function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Parth SrivastavaParth Srivastava 

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
Vivek S 42Vivek S 42
Hi, 

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
Parth SrivastavaParth Srivastava
Thanks  Vivek S 42 for this nice update.
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.