• vishalk
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies

here i want all websites names in which front will like www.google.com%

example

www.google.com

or

www.google.com/home

 

 

system.debug('#################query==='+[Select Website_Address__c From Employement_Website__c WHERE Website_Address__c LIKE  :UpdtSiteName+'%'  IN :UpdtSiteName]);

//here UpdtSiteName is a set

 

 

I trying to create a trigger to prevent duplicate website but its no working properly

 

 

trigger PreventDuplicateWebSite on Employement_Website__c (before insert,before update){
Map<String,Employement_Website__c> SiteMap=new Map<String,Employement_Website__c>();
Map<String,Employement_Website__c> SiteMapNew=new Map<String,Employement_Website__c>();
Set<string> SiteName;
Set<string> UpdtSiteName=new Set<string>();
for(Employement_Website__c colgObj:Trigger.new){
if((Trigger.isInsert
|| (colgObj.Website_Address__c!= Trigger.OldMap.get(colgObj.Id).Website_Address__c))){
if (SiteMap.ContainsKey(colgObj.Website_Address__c)){
colgObj.Website_Address__c.addError('This Website Name is Already Exist');
}
else
SiteMap.put(colgObj.Website_Address__c,colgObj);
}
}
SiteName=SiteMap.KeySet();
system.debug('#################SiteName==='+SiteName);
for(string front:SiteName){
String[] front1= front.split('\\.');
system.debug('#################front1==='+front1);
if(front1[0]=='www'||front1[0]=='http://www'||front1[0]=='https://www'){
if (front1[0]=='www'){
string f='http://'+front;
UpdtSiteName.add(f);
SiteMapNew.put(f,SiteMap.get(front));
}
else{
UpdtSiteName.add(front);
SiteMapNew.put(front,SiteMap.get(front));
}
}
else{
String frontNew='http://www.'+front;
UpdtSiteName.add(frontNew);
SiteMapNew.put(frontNew,SiteMap.get(front));
}
}
system.debug('#################UpdtSiteName==='+UpdtSiteName);
system.debug('#################query==='+[Select Website_Address__c From Employement_Website__c Where Website_Address__c In:UpdtSiteName ]);

for(Employement_Website__c clg : [Select Website_Address__c From Employement_Website__c Where Website_Address__c In :UpdtSiteName]){
system.debug('#################clg ==='+clg );
Employement_Website__c newColg = SiteMapNew.get(clg.Website_Address__c);
newColg.Website_Address__c.addError('This WebSite is Already Exist');
}
}