-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
7Replies
need to check trigger code is right
I check my code coverage of trigger is 100%, apex class is 100%, but need to check my trigger fucntion is correct or not.Plz help.
--------------
trigger:
trigger PenDiscountRangeTrigger on Parker_pen__C(before insert)
{
PenDiscountRangeClass.ApplyDiscount(trigger.new);
}
------
apex class:
public class PenDiscountRangeClass{
public static void ApplyDiscount(list<Parker_pen__C> VarPenList)
{
for(Parker_pen__C VarP: VarPenList)
{
if (VarP.Price__c>=100)
{
VarP.Price__c = VarP.Price__c- 30;
}
else if (VarP.Price__c<100 && VarP.Price__c>= 70)
{
VarP.Price__c= VarP.Price__c- 20;
}
else if (VarP.Price__c<70 && VarP.Price__c>= 40)
{
VarP.Price__c= VarP.Price__c- 10;
}
else if (VarP.Price__c<40)
{
VarP.Price__c= VarP.Price__c- 5;
}
}
}
}
----
Test class:
@isTest
class PenDiscountRangeClassTest {
@isTest
static void ApplyDiscountA()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=101;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(71, VarP2.Price__C);
}
@isTest
static void ApplyDiscountB()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=71;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(51, VarP2.Price__C);
}
@isTest
static void ApplyDiscountC()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=40;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(30, VarP2.Price__C);
}
@isTest
static void ApplyDiscountD()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=30;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(25, VarP2.Price__C);
}
}
--------------
trigger:
trigger PenDiscountRangeTrigger on Parker_pen__C(before insert)
{
PenDiscountRangeClass.ApplyDiscount(trigger.new);
}
------
apex class:
public class PenDiscountRangeClass{
public static void ApplyDiscount(list<Parker_pen__C> VarPenList)
{
for(Parker_pen__C VarP: VarPenList)
{
if (VarP.Price__c>=100)
{
VarP.Price__c = VarP.Price__c- 30;
}
else if (VarP.Price__c<100 && VarP.Price__c>= 70)
{
VarP.Price__c= VarP.Price__c- 20;
}
else if (VarP.Price__c<70 && VarP.Price__c>= 40)
{
VarP.Price__c= VarP.Price__c- 10;
}
else if (VarP.Price__c<40)
{
VarP.Price__c= VarP.Price__c- 5;
}
}
}
}
----
Test class:
@isTest
class PenDiscountRangeClassTest {
@isTest
static void ApplyDiscountA()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=101;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(71, VarP2.Price__C);
}
@isTest
static void ApplyDiscountB()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=71;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(51, VarP2.Price__C);
}
@isTest
static void ApplyDiscountC()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=40;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(30, VarP2.Price__C);
}
@isTest
static void ApplyDiscountD()
{
//create record
Parker_pen__C VarP= New Parker_pen__C();
VarP.Name='Govind';
VarP.Price__c=30;
//insert record
insert VarP;
//trigger called
//add new box with new value
Parker_pen__C VarP2= New Parker_pen__C();
VarP2= [select price__c from Parker_Pen__C where id=: VarP.id];
//check new value is expected value
system.assertEquals(25, VarP2.Price__C);
}
}
- Gauri Gaikwad 13
- August 31, 2022
- Like
- 0
- Continue reading or reply
field are not update after deplyment
i have deployed on production the functionality to update account field on button click.but client is saying field are not updating. how to debug this? and no error in sandbox.
one more , i have deployed some fields to production and those are not visible to end cliednt on page layout, why it is not visibile?
one more , i have deployed some fields to production and those are not visible to end cliednt on page layout, why it is not visibile?
- Gauri Gaikwad 13
- July 11, 2022
- Like
- 0
- Continue reading or reply
How to count number of records in SOSL query
SOSL query: i want to count number of records of .com in account, leads, opportynity object
FIND {.com}, count()
IN ALL FIELDS
RETURNING Opportunity(AccountId), Lead(company),Account(Name)
FIND {.com}, count()
IN ALL FIELDS
RETURNING Opportunity(AccountId), Lead(company),Account(Name)
- Gauri Gaikwad 13
- April 25, 2022
- Like
- 0
- Continue reading or reply
SOQL Query basic
I am trying to run SOQL query
code added in query editor
SELECT
First_Name__c
Experience__c
FROM
Indeed_COm_Job_Form__c
WHERE
Experience__c >1
and i am getting error as : Invalid query: The query has to start with 'FIND' or 'SELECT'.
but i have used SELECT word at beginning
code added in query editor
SELECT
First_Name__c
Experience__c
FROM
Indeed_COm_Job_Form__c
WHERE
Experience__c >1
and i am getting error as : Invalid query: The query has to start with 'FIND' or 'SELECT'.
but i have used SELECT word at beginning
- Gauri Gaikwad 13
- April 19, 2022
- Like
- 0
- Continue reading or reply
datatype error in apex class
hi, i am trying to add trigger & apex code i am getting error as (Error: Compile Error: Invalid type: Pen_c at line 3 column 51).
code in apex class----------------------
Public Class PenClassDemonstration{
public static void ApplyDiscountPen (List< Pen_c >VarPensListNew){
For(Pen_c VarP: VarPensListNew){
if(VarP.Price_c>= 100){
VarP.Price_c= VarP.Price_c- 20;
}
}
}
}
code in apex class----------------------
Public Class PenClassDemonstration{
public static void ApplyDiscountPen (List< Pen_c >VarPensListNew){
For(Pen_c VarP: VarPensListNew){
if(VarP.Price_c>= 100){
VarP.Price_c= VarP.Price_c- 20;
}
}
}
}
- Gauri Gaikwad 13
- April 08, 2022
- Like
- 0
- Continue reading or reply
I am getting error as unexpected token :
//declare a list variable
list<integer> VarEmployeeList= New list<integer> ();
//add values
VarEmployeeList.add(123);
VarEmployeeList.add(1234);
VarEmployeeList.add(1234);
system.debug(VarEmployeeList);
For(VarOneValue: VarEmployeeList)
{
system.debug(VarOneValue);
}
list<integer> VarEmployeeList= New list<integer> ();
//add values
VarEmployeeList.add(123);
VarEmployeeList.add(1234);
VarEmployeeList.add(1234);
system.debug(VarEmployeeList);
For(VarOneValue: VarEmployeeList)
{
system.debug(VarOneValue);
}
- Gauri Gaikwad 13
- March 30, 2022
- Like
- 0
- Continue reading or reply
field are not update after deplyment
i have deployed on production the functionality to update account field on button click.but client is saying field are not updating. how to debug this? and no error in sandbox.
one more , i have deployed some fields to production and those are not visible to end cliednt on page layout, why it is not visibile?
one more , i have deployed some fields to production and those are not visible to end cliednt on page layout, why it is not visibile?
- Gauri Gaikwad 13
- July 11, 2022
- Like
- 0
- Continue reading or reply
How to count number of records in SOSL query
SOSL query: i want to count number of records of .com in account, leads, opportynity object
FIND {.com}, count()
IN ALL FIELDS
RETURNING Opportunity(AccountId), Lead(company),Account(Name)
FIND {.com}, count()
IN ALL FIELDS
RETURNING Opportunity(AccountId), Lead(company),Account(Name)
- Gauri Gaikwad 13
- April 25, 2022
- Like
- 0
- Continue reading or reply
datatype error in apex class
hi, i am trying to add trigger & apex code i am getting error as (Error: Compile Error: Invalid type: Pen_c at line 3 column 51).
code in apex class----------------------
Public Class PenClassDemonstration{
public static void ApplyDiscountPen (List< Pen_c >VarPensListNew){
For(Pen_c VarP: VarPensListNew){
if(VarP.Price_c>= 100){
VarP.Price_c= VarP.Price_c- 20;
}
}
}
}
code in apex class----------------------
Public Class PenClassDemonstration{
public static void ApplyDiscountPen (List< Pen_c >VarPensListNew){
For(Pen_c VarP: VarPensListNew){
if(VarP.Price_c>= 100){
VarP.Price_c= VarP.Price_c- 20;
}
}
}
}
- Gauri Gaikwad 13
- April 08, 2022
- Like
- 0
- Continue reading or reply