+ Start a Discussion
Irish2013Irish2013 

Test class for the below code

HI please help me on this...

 

Public void populateSharingItems(Order_Line_Item__c oli){
                String CPQItem='';
                if(oli.CPQItem__c.contains('.'))
                    CPQItem =  oli.CPQItem__c.substring(0,oli.CPQItem__c.indexOf('.'));
                sharedServPathIdSet.add(oli.Parent_Path_Instance_ID__c);
                sharedServPathIdSet.add(oli.Path_Instance_Id__c);

                if(sharingPathNParentPathMap.containsKey(oli.Path_Instance_Id__c))
                    sharingPathNParentPathMap.get(oli.Path_Instance_Id__c).add(oli.Parent_Path_Instance_ID__c);
                else{
                    Set<String> parentPathIdSet = new Set<String>();
                    parentPathIdSet.add(oli.Parent_Path_Instance_ID__c);
                    sharingPathNParentPathMap.put(oli.Path_Instance_Id__c, parentPathIdSet);
                }
                if (mainParentOliMap.containsKey(oli.ParentOrder__c+'-'+CPQItem)){
                    Order_Line_Item__c mainOli = mainParentOliMap.get(oli.ParentOrder__c+'-'+CPQItem);
                    String mainParentServiceId='';
                    if(mainOli.Path_Instance_Id__c != null)
                        mainParentServiceId = mainOli.Master_Service_ID__c!=null ? mainOli.Master_Service_ID__c: mainOli.Primary_Service_ID__c;
                    else if(iplMainParentMap.containsKey(mainOli.id))
                        mainParentServiceId = iplMainParentMap.get(mainOli.id).Master_Service_ID__c!=null ? iplMainParentMap.get(mainOli.id).Master_Service_ID__c : iplMainParentMap.get(mainOli.id).Primary_Service_ID__c;

                    if(mainParentServiceId != '')
                        sharingPathNMainParentPathMap.put(oli.Path_Instance_Id__c+'-'+oli.Parent_Path_Instance_ID__c, mainParentServiceId);
                }
    }

 

harshasfdcharshasfdc

Hi,

 

in test class create a new instance for this  as shown

 

classname.populateSharingItems obj=new classname.populateSharingItems(oil);

 

Thanks,

Harsha

Rajesh SriramuluRajesh Sriramulu

Hi,

 

Classname cls = new classname();

insert one Order_Line_Item__c record.

Order_Line_Item__c olii = new Order_Line_Item__c();

olii.fieldname=''';

.

.

 

insert olii;

 

and call the method like this

 

cls.populateSharingItems(olii);

 

Regards,

Rajesh.