• Rohan Chadha
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi All,

Urgent help needed.!!
Detail Page
I am new to salesforce  and  need some help in writing the test class for below Trigger. This trigger is validating the duplicate records.

Request you to please help me in writing the test class for this.

Below Customer and Username are lookup field. Here i would like to test for single and bilk records.

Request you to please provide me the test class.




 
trigger duplicat on Ticket__c(before insert,before update)
 {
    list<string> cust = new list<string>();
    list<string> usernme =new list<string>();
    list<string> email= new list<string>();

for(Ticket__c a:Trigger.new)
    {
    cust.add(a.Customer);
   usernme.add(a.username);
    email.add(a.email-id);

    }

 List<Ticket__c>  tickt1 =[select User_Name__c,Customer__c,Start_Date__c, End_Date__c from Ticket__c where User_Name__c=:usernme and Customer__c=:a.cust];

if(tickt1.size()>0)   
for(Ticket__c a:Trigger.new)
        {
        for(Ticket__c tickt1 )
               {                
                 if(b.Start_Date__c  tickt1.Start_Date__c || b.Start_Date__c <=tickt1 .End_Date__c ||
                b.End_Date__c >=tickt1 .Start_Date__c || b.End_Date__c <=tickt1 .End_Date__c )

                a.adderror('You cannot create a duplicate Ticket.');
                }
        }
}

 
Hi All,

Urgent help Needed!!
I need your help since i am new to salesforce.

Actually the issue is that i have written one trigger to validate the duplicate record creation for a perticular object but it is throwing the validation even when you are trying to edit the existing record.

Kindly sugest me the solution or please guide me if it is a valid scenario.

The trigger which i have written is
trigger duplicat on Ticket__c(before insert,before update)
 {
    list<string> cust = new list<string>();
    list<string> usernme =new list<string>();
    list<string> email= new list<string>();

for(Ticket__c a:Trigger.new)
    {
    cust.add(a.Customer);
   usernme.add(a.username);
    email.add(a.email-id);

    }

List<Work_Order_Rate__c> WOR =  List<Ticket__c> tickt1 =[select User_Name__c,Customer__c,Start_Date__c, End_Date__c from Ticket__c where User_Name__c=:usernme and Customer__c=:a.cust];

if(WOR.size()>0)   
for(Ticket__c a:Trigger.new)
        {
        for(Ticket__c b:WOR )
               {                
                 if(b.Start_Date__c  tickt1.Start_Date__c || b.Start_Date__c <=tickt1 .End_Date__c ||
                b.End_Date__c >=tickt1 .Start_Date__c || b.End_Date__c <=tickt1 .End_Date__c )

                a.adderror('You cannot create a duplicate Ticket.');
                }
        }
}

Regards,
Rohan

Hi All,

I am new to salesforce and have  requirment to prevent user to create duplicate record and it should work for bulkyfication as well.

Please find the screenshot bellow of the Ticket Object detail page. The requirement is that there should be validation if user try to create duplicate records for same(Customer,username,email-id) and withing the period of Start date & End Date.

  • You can create the duplicate records if the start date & End date is before or after the existing record.
  • Key Values to check duplicacy is Username, Customer and Email Id.
  • It should support bulkyfication.

Kindly help with the code.


User-added image

Hi All,

Urgent help Needed!!
I need your help since i am new to salesforce.

Actually the issue is that i have written one trigger to validate the duplicate record creation for a perticular object but it is throwing the validation even when you are trying to edit the existing record.

Kindly sugest me the solution or please guide me if it is a valid scenario.

The trigger which i have written is
trigger duplicat on Ticket__c(before insert,before update)
 {
    list<string> cust = new list<string>();
    list<string> usernme =new list<string>();
    list<string> email= new list<string>();

for(Ticket__c a:Trigger.new)
    {
    cust.add(a.Customer);
   usernme.add(a.username);
    email.add(a.email-id);

    }

List<Work_Order_Rate__c> WOR =  List<Ticket__c> tickt1 =[select User_Name__c,Customer__c,Start_Date__c, End_Date__c from Ticket__c where User_Name__c=:usernme and Customer__c=:a.cust];

if(WOR.size()>0)   
for(Ticket__c a:Trigger.new)
        {
        for(Ticket__c b:WOR )
               {                
                 if(b.Start_Date__c  tickt1.Start_Date__c || b.Start_Date__c <=tickt1 .End_Date__c ||
                b.End_Date__c >=tickt1 .Start_Date__c || b.End_Date__c <=tickt1 .End_Date__c )

                a.adderror('You cannot create a duplicate Ticket.');
                }
        }
}

Regards,
Rohan

Hi All,

I am new to salesforce and have  requirment to prevent user to create duplicate record and it should work for bulkyfication as well.

Please find the screenshot bellow of the Ticket Object detail page. The requirement is that there should be validation if user try to create duplicate records for same(Customer,username,email-id) and withing the period of Start date & End Date.

  • You can create the duplicate records if the start date & End date is before or after the existing record.
  • Key Values to check duplicacy is Username, Customer and Email Id.
  • It should support bulkyfication.

Kindly help with the code.


User-added image