You need to sign in to do that
Don't have an account?
Please tell me how to write Test class for this trigger
trigger Incr on Service1__c (before insert) {
Increment__c incr=new Increment__c(name='Service1__c', In_Guarantee__c=1001, Out_of_Guarantee__c=2001, etc__c=3001);
for(Increment__c inc:[select id, name, In_Guarantee__c, Out_of_Guarantee__c, etc__c from Increment__c where name='Service1__c'])
incr=inc;
for(Service1__c ser:Trigger.new)
{
if(ser.Status__c=='In Guarantee')
{
ser.S_No__c=Integer.valueOf(incr.In_Guarantee__c++);
}
if(ser.Status__c=='Out of Guarantee')
{
ser.S_No__c=Integer.valueOf(incr.Out_of_Guarantee__c++);
}
if(ser.Status__c=='etc')
{
ser.S_No__c=Integer.valueOf(incr.etc__c++);
}
}
upsert incr;
}
Hi Nitin,
Below is the Test class For your Trigger.
Test Class
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
All Answers
Hi Nitin,
Below is the Test class For your Trigger.
Test Class
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
Hitesh,
Just to know, since in this trigger SOQL has been written within for loop.
Will it hit the governor limit?
trigger Incr on Service1__c (before insert) {
Increment__c incr=new Increment__c(name='Service1__c', In_Guarantee__c=1001, Out_of_Guarantee__c=2001, etc__c=3001);
for(Increment__c inc:[select id, name, In_Guarantee__c, Out_of_Guarantee__c, etc__c from Increment__c where name='Service1__c'])
incr=inc;
for(Service1__c ser:Trigger.new)
{
if(ser.Status__c=='In Guarantee')
{
ser.S_No__c=Integer.valueOf(incr.In_Guarantee__c++);
}
if(ser.Status__c=='Out of Guarantee')
{
ser.S_No__c=Integer.valueOf(incr.Out_of_Guarantee__c++);
}
if(ser.Status__c=='etc')
{
ser.S_No__c=Integer.valueOf(incr.etc__c++);
}
}
upsert incr;
}
Hi Kaity,
The SOQL has not been Written within for Loop.
It has been used instead of List variable.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/
ohkkkk...
Thanks Hitesh.