You need to sign in to do that
Don't have an account?
Remove www. http:// or https:// in Trigger
Greetings. I was hoping to gain some assistance with my Trigger. In the current stated the Trigger works; however, I want to account for the various formats of a website, i.e. www. or http:// or https://.
Right now I am able to strip off the www. but I cannot figure out how to incorporate code to handle the other options. Can anybody provide assistance?
Right now I am able to strip off the www. but I cannot figure out how to incorporate code to handle the other options. Can anybody provide assistance?
trigger FindDomain on Lead (before insert, before update) { // Populate list with of substring of company removing http(s):// or www. List<String> leadStr = new List<String>(); for (Lead newLead : Trigger.new) { if(newLead.Website != NULL) { String s = newLead.Website.removeStartIgnoreCase('www.'); leadStr.add(s); System.debug(leadStr); } } List<Domain__c> domains = [SELECT Id,Name FROM Domain__c WHERE Name IN :leadStr]; System.debug(domains); Map<String, Id> domainToLead = new Map<String, Id>(); for (Domain__c dom : domains) { domainToLead.put(dom.Name, dom.Id); System.debug(domainToLead); } for (Lead l : Trigger.new) { if (l.Website != NULL) { l.Domain__c = domainToLead.get(l.Website.removeStartIgnoreCase('www.')); } else { l.Domain__c = NULL; } } }
Please use below code in your trigger.
Please like and mark best answer if this helps to you.
All Answers
Please use below code in your trigger.
Please like and mark best answer if this helps to you.
Thank you that worked. I appreciate your help.
Please like and mark best answer.
Thanks