• Vishal Thube
  • NEWBIE
  • 25 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

I Have to show Duration hour between two date time field

     First Date – Second Date = Hours:Minutes

I Have to show Duration hour between two date time field

     First Date – Second Date = Hours:Minutes

I have a parent object and child object, in which a parent record shouldn't have duplicate child records.the following trigger is working fine but it is checking only the records in the database.

But my issue is? user is inserting two duplicate records at a time using .csv file and since my trigger is only validating the records in the database.
hence these duplicate records are also getting inserted.

How can I check duplicate in the .csv file itself ? or how to overcome this issue.

Can any one help me on this.
Trigger:
trigger BeatNameDuplicateCheck on Beat_TSE_Mapping__c (before insert, before update) {
        set<Id>TSEID= new set<ID>();
        set<string>bitname=new set<string>();
        map<string,Beat_TSE_Mapping__c> bitmap= new map<string,Beat_TSE_Mapping__c> ();
               for(Beat_TSE_Mapping__c beat:Trigger.new)
        {
            TSEID.add(beat.TSE_Code__c);
            bitname.add(beat.Beat_Name__c); 
        }
        if (!TSEID.isEmpty() ){
             List<Beat_TSE_Mapping__c> TSElist=new List<Beat_TSE_Mapping__c>();
        TSElist=[select id,Beat_Name__c,TSE_Code__c from Beat_TSE_Mapping__c where Beat_Name__c In: bitname and TSE_Code__c In: TSEID];
                       
        if (TSElist.size()>0) {
            for(Beat_TSE_Mapping__c beat:TSElist)
            {
              bitmap.put(beat.Beat_Name__c, beat);
            }     
        } 
                  }
        for (Beat_TSE_Mapping__c beat:Trigger.new)
                    {
            If (bitmap.containsKey(beat.Beat_Name__c ))
            {
                beat.Beat_Name__c.AddError('Beat Name Already Exist. Please try with another BeatName. ');
           }
        } 
}
Hi,
Below is my code for the trigger for  duplicate prevention on the account . It works well, but if I have 50k records this impacts scalability and not feasible.
So please any one can help to code in better way.
thanks in advance.
trigger AccountDuplicate on Account (before insert) {
 List<Account> dup = new List<Account>();
 dup = [Select id, Name from Account];
 for(Account a:Trigger.New){
 for(Account a1:dup){
 if(a.Name==a1.Name){
 a.Name.addError('Name already Exist ');
 }
 }
 }   
 }

HI All,

 

How to create a fomula field for my age field ? It will be calculated by using the Date_of_Birth__c field. I have a fomula.

 

IF(MONTH(TODAY())>MONTH(DOB_API),YEAR(TODAY())-YEAR(DOB_API),IF(AND(MONTH(TODAY())=MONTH(DOB_API),DAY(TODAY())>=DAY(DOB_API)),YEAR(TODAY())-YEAR(DOB_API),(YEAR(TODAY())-YEAR(DOB_API))-1))  

 That's from Ankit's blog. But I don't know how to use it and where to use it.

 

Thanks in Advance