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 

Compile Error: Method does not exist or incorrect signature: [Id].size() at line 9 column 43

trigger EmployeeInformationTrigger on Employe_Infrmation__c (before delete) {
        
            Map<Id,Employe_Infrmation__c> naMap = new Map<Id,Employe_Infrmation__c>([SELECT Id,DepartMt__r.Id FROM 
                
                Employe_Infrmation__c where Id in:trigger.oldMap.keyset()]);
        
                     for(Employe_Infrmation__c se:trigger.old){
                     
                     if (naMap.get(se.Id).DepartMt__r.Id.size()>0)
                     
                     se.addError('jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj');
                     }
SRKSRK
 if (naMap.get(se.Id).DepartMt__r.Id.size()>0)

so when you pass a Employe_Infrmation__c  id in map named as naMap it will return you the object of Employe_Infrmation__c not the list of Employe_Infrmation__c

.size() is a method of list if you want to check for null do this 

 if (naMap.get(se.Id).DepartMt__r != null)


Also you are doing naMap.get(se.Id) without check that map contains se id or not its not correct so it should be like this
if(naMap.containskey(se.Id))
{
       if (naMap.get(se.Id).DepartMt__r != null)
}
Class slaesforceClass slaesforce
helo sir 
thanks for given ..but am writing child object field lookup relations .... 
my requirement is i want to deletd tha child object i wonte be deleted ......some valiadation trigger will appear..
 
SRKSRK

can you please explane ot bit more it will be more helpfull i belive

You want to delete a child record 

 

say there is a record A1 which have 3 child B1 B2 and B3 
so in want case or condtion you want the chields to be deleted 

Class slaesforceClass slaesforce
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');
  }
  }
  }
ravi shankar 144ravi shankar 144
public class Temperat {
    public static Decimal FahrenheitToCelsius(Decimal fh){
        Decimal cs = (fh - 32) * 5/9;
        system.debug('cs;+cs');
                     return cs.setScale(2);
    }

}
I am beginner and I am trying this to execute. I got this code from some forum, but when I am trying to execute it says Method does not exist. why