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
Class slaesforceClass slaesforce 

in this code insert is working update is not working please suggest me a small thing is missing

trigger EmployeeInformation on Employe_Infrmation__c (before insert,before update) {

    set<string> gh=new set<string>();
      
    for(Employe_Infrmation__c hh:trigger.new){
    
    if(trigger.IsInsert||(trigger.IsUpdate && hh.Name!=trigger.oldMap.get(hh.Id).Name))
    
    gh.add(hh.Name);
    
}

    set<string> jh =new set <string>();
    
    for(Employe_Infrmation__c hh:[select Name from Employe_Infrmation__c where Name in:gh]){
    
    jh.add(hh.Name);
  }
  
  
  for(Employe_Infrmation__c hh:trigger.new){
  
  if(trigger.IsInsert||(trigger.IsUpdate && hh.Name!=trigger.oldMap.get(hh.Id).Name)){
  
  if(jh.contains(hh.Name))
  
  hh.adderror('Duplicate values');
  }
  }
  }
Abhishek_DEOAbhishek_DEO
Which part is not working? On looking into the code, it seems you are showing an error message on entering the duplicate name.Code seems fine..
AnupPrakash_AlgoworksAnupPrakash_Algoworks
Are you Updating the Name  And Validating?
Class slaesforceClass slaesforce
I task is duplicate name not enterd before the insert and before the update name should not change
Abhishek_DEOAbhishek_DEO
So in case of update, are you not getting error message "Duplicate values" on entering the duplicate name? I do not see any issue with code probably someone else can find. Code will show error only when your prev and entered value is different and entered value already exists in system
Class slaesforceClass slaesforce
thanks abhishek

 
Waqar Hussain SFWaqar Hussain SF
trigger EmployeeInformation on Employe_Infrmation__c (before insert,before update) {
    
	set<string> allNames =new set <string>();
    for(Employe_Infrmation__c emp1:[select Name from Employe_Infrmation__c]){
		allNames.add(emp1.Name);
	}
    
	if (trigger.isInsert()){
		for(Employe_Infrmation__c emp2:trigger.new){
			if(!allNames.add(emp2.Name)){
				emp2.adderror('This employee already exist, duplicate Record.');
			}
		}
	}
	
	if (trigger.isupdate()){
		for(Employe_Infrmation__c emp3:trigger.new){
			if(emp3.Name != trigger.oldMap.get(emp3.Id).Name){
				emp3.addError('You can not change the name of the record.');
			}
		}
	}

}
Class slaesforceClass slaesforce
HI VICKEY:-
 sorry fo dealy respond some little bussy ...thanks for suggestion...
Class slaesforceClass slaesforce
trigger Account on Account (after update) {
set<id> fire =new set<id>();
for(Account hg:trigger.new){
    if(hg.BillingStreet !=trigger.oldMap.get(hg.id)||hg.BillingCity!=trigger.oldMap.get(hg.id)||hg.BillingState/Province!=trigger.get(hg.id)||hg.BillingZip/PostalCode!=trigger.oldMap.get(hg.id)){
        fire.add(hg.id);
}
}
list<contact> cnt;
if(fire.size()>0){
  cnt=[SELECT name,AccountId FROM Contact where AccountId in:fire];
  }
  if(cnt!=null){
list<Contact>contr=new list<contact>();
for(contact von:cnt){
     von.otherStreet=trigger.newMap.get(von.id).BillingStreet;
     von.otherStreet=trigger.newMap.get(von.id).BillingCity;
     von.otherStreet=trigger.newMap.get(von.id).BillingState/Province;
     von.otherStreet=trigger.newMap.get(von.id).BillingZip/PostalCode;
     contr.add(von.id);
 }
 if(contr.size()>0){
 update.contr;
 }
 }
 }


ERROR WILL COME:----thats rror: Compile Error: Variable does not exist: Province at line 4 column 113 
Class slaesforceClass slaesforce
YYYS  problem is slove a small mistake thats order if arrange and 
contr.add(von); that one 

 
Class slaesforceClass slaesforce
system .null.pointer exception how to slove it
Class slaesforceClass slaesforce
trigger AccountTrigger on Account (after update) {
set<Id> fire =new set<Id>();
for(Account hg:trigger.new){
    if(hg.BillingStreet != trigger.oldMap.get(hg.Id).BillingStreet || hg.BillingCity != trigger.oldMap.get(hg.Id).BillingCity || hg.BillingState != trigger.oldMap.get(hg.Id).BillingState || hg.BillingPostalCode != trigger.oldMap.get(hg.Id).BillingPostalCode || hg.BillingCountry != trigger.oldMap.get(hg.Id).BillingCountry) {         
             fire.add(hg.Id);
}
}
list<Contact> cnt;
if(fire.size()>0){
  cnt=[SELECT name,AccountId FROM Contact where AccountId in:fire];
  }
  if(cnt!=null){
list<Contact> contr=new list<Contact>();
for(contact von:cnt){
       von.otherStreet=trigger.newMap.get(von.Id).BillingStreet;
     von.otherCity=trigger.newMap.get(von.Id).BillingCity;
         von.otherState=trigger.newMap.get(von.Id).BillingState;
             von.otherpostalCode=trigger.newMap.get(von.Id).BillingPostalCode;
     von.othercountry=trigger.newMap.get(von.Id).BillingCountry;
          contr.add(von);
                    
 }
 if(contr.size()>0){
     update contr;
 }
 }
 }
Waqar Hussain SFWaqar Hussain SF
trigger AccountTrigger on Account (after update) {
set<Id> fire =new set<Id>();
for(Account hg:trigger.new){
    if(hg.BillingStreet != trigger.oldMap.get(hg.Id).BillingStreet || hg.BillingCity != trigger.oldMap.get(hg.Id).BillingCity || hg.BillingState != trigger.oldMap.get(hg.Id).BillingState || hg.BillingPostalCode != trigger.oldMap.get(hg.Id).BillingPostalCode || hg.BillingCountry != trigger.oldMap.get(hg.Id).BillingCountry) {         
             fire.add(hg.Id);
}
}
list<Contact> cnt;
if(fire.size()>0){
  cnt=[SELECT name,AccountId FROM Contact where AccountId in:fire];
  }
  if(cnt.size()>0){
list<Contact> contr=new list<Contact>();
for(contact von:cnt){
       von.otherStreet=trigger.newMap.get(von.Id).BillingStreet;
     von.otherCity=trigger.newMap.get(von.Id).BillingCity;
         von.otherState=trigger.newMap.get(von.Id).BillingState;
             von.otherpostalCode=trigger.newMap.get(von.Id).BillingPostalCode;
     von.othercountry=trigger.newMap.get(von.Id).BillingCountry;
          contr.add(von);
                    
 }
 if(contr.size()>0){
     update contr;
 }
 }
 }