For Salesforce CRM online Training please contact :+91 9964773322 or +91 9393934143. Website : https://www.salesforcestart.com/
Tuesday, 15 November 2016
Test class for product and pricebook
Test class for product and pricebook:
Product2 prod = new Product2(Name = 'Laptop X200',
Family = 'Hardware');
insert prod;
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPrice = new PricebookEntry(
Pricebook2Id = pricebookId, Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true);
insert standardPrice;
Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
PricebookEntry customPrice = new PricebookEntry(
Pricebook2Id = customPB.Id, Product2Id = prod.Id,
UnitPrice = 12000, IsActive = true);
insert customPrice;
List<PricebookEntry> pbez = [SELECT ID, Product2Id, Pricebook2.isStandard, Pricebook2.isActive, isActive FROM PricebookEntry];
system.debug(pbez[0].Pricebook2.isStandard);
system.debug(pbez[0].Pricebook2.isActive);
Product2 prod = new Product2(Name = 'Laptop X200',
Family = 'Hardware');
insert prod;
Id pricebookId = Test.getStandardPricebookId();
PricebookEntry standardPrice = new PricebookEntry(
Pricebook2Id = pricebookId, Product2Id = prod.Id,
UnitPrice = 10000, IsActive = true);
insert standardPrice;
Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
insert customPB;
PricebookEntry customPrice = new PricebookEntry(
Pricebook2Id = customPB.Id, Product2Id = prod.Id,
UnitPrice = 12000, IsActive = true);
insert customPrice;
List<PricebookEntry> pbez = [SELECT ID, Product2Id, Pricebook2.isStandard, Pricebook2.isActive, isActive FROM PricebookEntry];
system.debug(pbez[0].Pricebook2.isStandard);
system.debug(pbez[0].Pricebook2.isActive);
test class best practices in salesforce
Test class best practices in sales-force:
• we need to use System.assert / System.assertEquals in the test. How would you know you are getting what is expected from the test? There have to be assert statements.
• we need to avoid @isTest(seeAlldata = true) ?
we have to setup our own data for testing purpose and should not rely on the Org data.
• Provide a description of what you are test is doing(comments).
• we need have setup method for all your data creation.
• we should test for both positive and negative scenarios.
• Tests are run as System Administrator only, is this how we do in the real system also? If not test users needs to be created and by using System.runAs () it has to tested as appropriate.
• we should have only what exactly you are testing in between Test.StartTest() and Test.Stoptest().
Following are applicable for all the test classes.
• The Ideal test class should be somewhat like this
@isTest
public class nameOfTestClass {
// any statics you want to define
// Have your setup methods defined here
/**
* Comments for the test method1
*
**/
static testMethod void testNameOfTheMethod1(){
// All the set up should be here
test.startTest();
// only what you want to test should be here.
test.stopTest();
}
/**
* Comments for the test method2
*
**/
static testMethod void testNameOfTheMethod2(){
// All the set up should be here
test.startTest();
// only what you want to test should be here.
test.stopTest();
}
}
Test Class Best practises |
Apex Exception Email
Apex Exception Email:
1.Actually the 'Send Apex Warning Emails' settings on the User record only controls whether or not you get Apex warning emails every time that an Apex scrip surpasses more than 50% of any governor limit.
2.Runtime exception messages (which is what the "Developer script execution" emails are about) always get sent to the 'Last Modified By' user of the Apex class that generates the exception.
3.The only way to disable those emails is to have another user update the Apex class(es) in question. Marking your user record as Inactive in the Org might also work, but I'm not sure.
4.UPDATE:
This is possible now with the Winter 16 release. Under Setup go to "Apex Exception Email" to specifiy what email(s) you want to receive error messages. Here is an exceprt from the release notes:
Subscribe to:
Posts (Atom)
Complete Salesforce CPQ training Free videos
Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...
-
Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...
-
Salesforce advanced admin certification dumps More Videos: Salesforce advanced admin certification dumps
-
External ID This is a field that usually references an ID from another (external) system. For instance, if the customer has an Oracle Fi...