You need to sign in to do that
Don't have an account?
Will Sun 14
Apex Class deployment from Sandbox to Production help
Hi developers, I need some helps to deploy apex class from Sandbox to Production.. here is my apex class
Please help
public class LightningDataTableController { @AuraEnabled public static List<PricebookEntry> fetchData() { //Query and return list of Contacts id userId = UserInfo.getUserId(); User u = [select id, contactId from User where id = : userId]; id getContactId = u.contactId; List<Contact> cont = new List<Contact>(); cont = [SELECT AccountId, Title, Name, Email FROM Contact Where Id =: getContactId]; String dealerId = ''; if(cont != null && cont.size() > 0){ dealerId = cont[0].AccountId; } List<PricebookEntry> objRecords = [SELECT Product_Category__c, Product_Name__c,ProductCode,UnitPrice,Inventory_Status__c,Inventory_Description__c from PricebookEntry where isActive =true AND Pricebook2.isStandard = false AND Pricebook2.Dealer__c =: dealerId LIMIT 900]; return objRecords; } }I understand that I need to create a test class, but don't know where to start with and not sure how to pass the production Apex test..
Please help
Let me know if this code gives you any coverage
Anudeep
All Answers
You could start by looking at the trailheads and write a test class then call the method in the test class.
Then you can improve the code coverage and deploy the test class to production.
You could make use of following links for reference:
>> https://trailhead.salesforce.com/en/content/learn/modules/apex_testing
>> https://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
Apart from these make sure to follow the best practices so that the test class doesn't break in case if there is any changes going forward.
>> https://www.infallibletechie.com/2018/08/salesfore-apex-test-class-best-pracitces.html
I hope these links would help.
Regards,
Anutej
As these fields are formular fields in the object
Product_Category__c, Product_Name__c,ProductCode,Inventory_Status__c,Inventory_Description__c
Let me know if this code gives you any coverage
Anudeep