You need to sign in to do that
Don't have an account?
Amit Jadhav 13
i need a help on test class
public with sharing class OpportunitylistViewCom { @AuraEnabled public static List<OpportunityLineItem> getOpportunityLineItem(Id accountId,String sortField, boolean isAsc){ String query = 'Select id,Opportunity.Name,Opportunity.Account.name,Opportunity.RecordType.Name,Opportunity.type,Opportunity.Amount,Opportunity.StageName,Opportunity.Parent_Asset__r.InstallDate,Product_Name__c,UnitPrice,TotalPrice,ListPrice,End_Date__c,Related_To__c '; query += 'From OpportunityLineItem where Opportunity.AccountId =:accountId'; if (sortField != '') { query += ' order by ' + sortField; if (isAsc) { query += ' asc'; } else { query += ' desc'; } } list <OpportunityLineItem> oppList1; try { oppList1 = Database.query(query); List < OpportunityLineItem > oppList = new List < OpportunityLineItem > (); for (OpportunityLineItem c: oppList1) { oppList.add(c); } return oppList; } catch (Exception ex) { // for handle Exception return null; } } @AuraEnabled public static list < Attachment > fetchopportunity(Id accountId) { set<ID> oppIDs = new set<ID>(); for(Opportunity opp :[Select id from opportunity where AccountId=:accountId]){ oppIDs.add(opp.id); } list < Attachment > returnoppList = new List <Attachment> (); List < Attachment > lstopp = [select id,name,LastModifiedDate,CreatedBy.name,Parent.Name, Owner.Name, BodyLength from Attachment where ParentId IN:oppIDs]; for (Attachment c: lstopp) { returnoppList.add(c); } return returnoppList; } }
Create a test class
1. insert an account
2.insert opportunity
3.insert Opportunity lineitem and relate to to above opportunity
4.Call the getOpportunityLineItem method by providing all the parameters
5.insert an attachment with parentid as above opportunity id.
Please refer below link which might help you in this
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html
Hope this helps you
Let me know if this helps you. Kindly mark it as solved so that it may help others in future.
Thanks and Regards
I hope you are doing well .....!!
Please use the below code: It Cover 80% you can modified it as per your requirement and make sure you put all required field while inserting the record in test class.
Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.
Thanks & Regards,
Foram Rana