You need to sign in to do that
Don't have an account?
Soundar Rajan Ponpandi
Test Class Coverage Issue - Nintex Drawloop Part
Hello Dears,
I am facing one challanges while covering a test class. I am refering a nintext drawloop part in a method that is not passing a parameter correctly.
I am not sure either i am doing a mistake or bydefault it's not passing the parameter. Can you please look at this and help me to achieve the way.
Test Class
Actual Method
Here the object name is empty, How can i pass the relevant parameter here ?
for (string objectName : requestInfo.GetObjectNames()) { ..}
Thanks in advance,
Soundar Rajan P.
I am facing one challanges while covering a test class. I am refering a nintext drawloop part in a method that is not passing a parameter correctly.
I am not sure either i am doing a mistake or bydefault it's not passing the parameter. Can you please look at this and help me to achieve the way.
Test Class
@isTest public class fetchDataforDrawLoop_Test { @isTest Public static void codeCoverage(){ TestDataUtility TDFObj = new TestDataUtility(); List<User> users = TestDataUtility.createUsers('System Administrator'); List<Account> companyAccounts = TestDataUtility.createAccounts(1,'ICC'); List<Contact> companyContacts = TestDataUtility.createContactRecords(companyAccounts); List<HexaBPM__SR_Template__c> SRTemplates = TestDataUtility.createSRTemplateRecords(); List<HexaBPM__SR_Steps__c> SRSteps = TestDataUtility.createSRSteps(SRTemplates); List<HexaBPM__Service_Request__c> rmSRList = TestDataUtility.createServiceRequests(1,companyAccounts,'Add_Remove_Board_Member_Trustee'); List<Amendment__c> rmAmendments = TestDataUtility.createAmendmentsForSR(rmSRList); HexaBPM__SR_Doc__c SRDOC = new HexaBPM__SR_Doc__c(); SRDOC.HexaBPM__Customer__c = companyAccounts[0].Id; SRDOC.HexaBPM__Service_Request__c = rmSRList[0].Id; insert SRDOC; Loop.ExternalData.QueryRequestInfo extData = new Loop.ExternalData.QueryRequestInfo(); extData.RecordId = rmSRList[0].Id; Account acc = new Account(); Contact con = new Contact(); con.AccountId = acc.Id; Test.startTest(); fetchDataforDrawLoop controller = new fetchDataforDrawLoop(); controller.describeObjects(new List<string>{'relDirSec', 'relUBO', 'relSh', 'nomRelLnks', 'trustRelLnks', 'nomDirRelLnks', 'trustUBORelLnks', 'nomUBORelLnks','trustUBORelLnks'}); controller.getChildRelationships('relSh'); controller.getGlobalDescribe(); controller.getFieldValue((Sobject)acc, 'Name'); controller.query(extData); // Here I need a solution Test.stopTest(); } }
Actual Method
public Loop.ExternalData.QueryResultSet query(Loop.ExternalData.QueryRequestInfo requestInfo) { // Provide data for each object in requestInfo.GetObjectNames() Id srDocId = requestInfo.RecordId; Id custId; List<HexaBPM__SR_Doc__c> srDocLst = [SELECT HexaBPM__Customer__c FROM HexaBPM__SR_Doc__c WHERE Id = :srDocId LIMIT 1]; if(srDocLst != null && srDocLst.size() > 0){ custId = srDocLst[0].HexaBPM__Customer__c; } // Declare the variable to be returned. Loop.ExternalData.QueryResultSet queryResultSet = new Loop.ExternalData.QueryResultSet(); Loop.ExternalData.QueryResult rels; Loop.ExternalData.QueryResult relLnksNom; Loop.ExternalData.QueryResult relLnksTrust; List<String> relfields = new List<string>(); Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.RAK_Relationship__c.Fields.getMap(); for (string fieldKey : fieldMap.keySet()) { relfields.add(fieldKey); } List<String> relLnkfields = new List<string>(); fieldMap = Schema.SObjectType.Relationship_Link__c.Fields.getMap(); for (string fieldKey : fieldMap.keySet()) { relLnkfields.add(fieldKey); } List<String> shDetailFields = new List<String>(); fieldMap = Schema.SObjectType.Shareholder__c.Fields.getMap(); for (string fieldKey : fieldMap.keySet()) { shDetailFields.add(fieldKey); } List<String> relLnkFieldsFinal = new List<String>(); relLnkFieldsFinal.addAll(relLnkfields); relLnkFieldsFinal.add('relRef'); String uniqueComb; List<string> recordValues; List<String> roleLst; Set<String> passNationSet,accNameSet,regNumberSet,nameregNoSet; system.debug('Line 167: requestInfo.GetObjectNames() *** ' + requestInfo.GetObjectNames()); //Here ObjectName is empty for (string objectName : requestInfo.GetObjectNames()) { if (objectName == 'relSh'){ relLnksNom = new Loop.ExternalData.QueryResult('nomRelLnks', relLnkFieldsFinal); relLnksTrust = new Loop.ExternalData.QueryResult('trustRelLnks', relLnkFieldsFinal); string query = string.format( 'SELECT {0} , (SELECT {1} FROM Shareholders__r WHERE Status__c = \'Active\') FROM RAK_Relationship__c WHERE RAK_Subject_Account__c = :custId AND Status__c = \'Active\' AND Type__c = \'Shareholder\'', new List<string>{ string.join(relfields, ','), string.join(shDetailFields, ',')} ); rels = new Loop.ExternalData.QueryResult('relSh', new List<String>{'Id','name','address','shareDetails','startDate','roles'}); passNationSet = new Set<String>(); accNameSet = new Set<String>(); regNumberSet = new Set<String>(); nameregNoSet = new Set<String>(); for (SObject record : Database.query(query)) { // Store the values (as strings) from the record in the same order of the fields defined in the QueryResult instance recordValues = new List<string>(); roleLst = new List<String>(); roleLst.add('Shareholder'); RAK_Relationship__c relRec = (RAK_Relationship__c)record; uniqueComb = ''; if(relRec.RAK_Type_of_Shareholder__c == 'Individual Shareholder' && String.isNotBlank(relRec.Nationality_PassportNo__c)){ uniqueComb = relRec.Nationality_PassportNo__c; passNationSet.add(relRec.Nationality_PassportNo__c); }else if(relRec.RAK_Type_of_Shareholder__c == 'Corporate Shareholder' && String.isNotBlank(relRec.Account_Name__c) && String.isNotBlank(relRec.Registration_Number__c)){ uniqueComb = relRec.Account_Name__c+relRec.Registration_Number__c; accNameSet.add(relRec.Account_Name__c); regNumberSet.add(relRec.Registration_Number__c); nameregNoSet.add(relRec.Account_Name__c+relRec.Registration_Number__c); } if(String.isNotBlank(uniqueComb)){ recordValues.add(uniqueComb); if(relRec.Shareholders__r != null && relRec.Shareholders__r.size() > 0){ recordValues.add(String.valueOf(relRec.Shareholders__r[0].RAK_Shareholder_Name__c)); recordValues.add(String.valueOf(relRec.Shareholders__r[0].Shareholder_Contact_Address__c)); recordValues.add(String.valueOf(relRec.Shareholders__r[0].No_Of_Shares__c)); recordValues.add(String.valueOf(relRec.Shareholders__r[0].Start_Date__c)); } if(relRec.Is_Nominee__c){ roleLst.add('Nominee Board Member'); } if(relRec.Is_Trustee__c){ roleLst.add('Trustee'); } if(relRec.Is_Nominator__c){ roleLst.add('Nominator'); } if(relRec.Is_Trustor__c){ roleLst.add('Trustor'); } recordValues.add(String.Join(roleLst,',')); rels.rows.add(recordValues); } } }else if (objectName == 'relDirSec'){ relLnksNom = new Loop.ExternalData.QueryResult('nomDirRelLnks', relLnkFieldsFinal); relLnksTrust = new Loop.ExternalData.QueryResult('trustDirRelLnks', relLnkFieldsFinal); string query = string.format( 'SELECT {0} FROM RAK_Relationship__c WHERE RAK_Subject_Account__c = :custId AND Status__c = \'Active\' AND Type__c IN (\'Board of Director\',\'Secretary\') ORDER BY Type__c ASC', new List<string>{ string.join(relfields, ',')} ); rels = new Loop.ExternalData.QueryResult('relDirSec', new List<String>{'Id','name','address','startDate','roles'}); passNationSet = new Set<String>(); accNameSet = new Set<String>(); regNumberSet = new Set<String>(); nameregNoSet = new Set<String>(); Map<String,List<string>> recMap = new Map<String,List<string>>(); for (SObject record : Database.query(query)) { // Store the values (as strings) from the record in the same order of the fields defined in the QueryResult instance recordValues = new List<string>(); roleLst = new List<String>(); RAK_Relationship__c relRec = (RAK_Relationship__c)record; uniqueComb = ''; if(relRec.RAK_Type_of_Shareholder__c == 'Individual Shareholder' && String.isNotBlank(relRec.Nationality_PassportNo__c)){ uniqueComb = relRec.Nationality_PassportNo__c; if(relRec.Type__c == 'Secretary' && recMap.containsKey(uniqueComb) && recMap.get(uniqueComb) != null){ recMap.get(uniqueComb)[4] = recMap.get(uniqueComb)[4] + ',Secretary'; continue; } recordValues.add(uniqueComb); recordValues.add(String.valueOf(relRec.Last_Name__c)); if(relRec.Type__c == 'Board of Director'){ passNationSet.add(relRec.Nationality_PassportNo__c); } }else if(relRec.RAK_Type_of_Shareholder__c == 'Corporate Shareholder' && String.isNotBlank(relRec.Account_Name__c) && String.isNotBlank(relRec.Registration_Number__c)){ uniqueComb = relRec.Account_Name__c+relRec.Registration_Number__c; if(relRec.Type__c == 'Secretary' && recMap.containsKey(uniqueComb) && recMap.get(uniqueComb) != null){ recMap.get(uniqueComb)[4] = recMap.get(uniqueComb)[4] + ',Secretary'; continue; } recordValues.add(uniqueComb); recordValues.add(String.valueOf(relRec.Account_Name__c)); if(relRec.Type__c == 'Board of Director'){ accNameSet.add(relRec.Account_Name__c); regNumberSet.add(relRec.Registration_Number__c); nameregNoSet.add(relRec.Account_Name__c+relRec.Registration_Number__c); } } if(String.isNotBlank(uniqueComb)){ recordValues.add(String.valueOf(relRec.RAK_Contact_Address__c)); recordValues.add(String.valueOf(relRec.RAK_Start_Date__c)); if(relRec.Type__c == 'Board of Director'){ roleLst.add('Board of Director'); if(relRec.Is_Nominee__c){ roleLst.add('Nominee Board Member'); } if(relRec.Is_Trustee__c){ roleLst.add('Trustee'); } if(relRec.Is_Nominator__c){ roleLst.add('Nominator'); } if(relRec.Is_Trustor__c){ roleLst.add('Trustor'); } }else if(relRec.Type__c == 'Secretary'){ roleLst.add('Secretary'); } recordValues.add(String.Join(roleLst,',')); recMap.put(uniqueComb, recordValues); } } if(recMap.size() > 0){ for(List<String> val : recMap.values()){ rels.rows.add(val); } } }else if (objectName == 'relUBO'){ relLnksNom = new Loop.ExternalData.QueryResult('nomUBORelLnks', relLnkFieldsFinal); relLnksTrust = new Loop.ExternalData.QueryResult('trustUBORelLnks', relLnkFieldsFinal); string query = string.format( 'SELECT {0} FROM RAK_Relationship__c WHERE RAK_Subject_Account__c = :custId AND Status__c = \'Active\' AND Type__c IN (\'UBO\')', new List<string>{ string.join(relfields, ',')} ); rels = new Loop.ExternalData.QueryResult('relUBO', new List<String>{'Id','name','address','ownership','startDate','roles'}); passNationSet = new Set<String>(); accNameSet = new Set<String>(); regNumberSet = new Set<String>(); nameregNoSet = new Set<String>(); for (SObject record : Database.query(query)) { // Store the values (as strings) from the record in the same order of the fields defined in the QueryResult instance recordValues = new List<string>(); roleLst = new List<String>(); RAK_Relationship__c relRec = (RAK_Relationship__c)record; uniqueComb = ''; if(relRec.RAK_Type_of_Shareholder__c == 'Individual Shareholder' && String.isNotBlank(relRec.Nationality_PassportNo__c)){ uniqueComb = relRec.Nationality_PassportNo__c; recordValues.add(uniqueComb); recordValues.add(String.valueOf(relRec.Last_Name__c)); passNationSet.add(relRec.Nationality_PassportNo__c); } if(String.isNotBlank(uniqueComb)){ recordValues.add(String.valueOf(relRec.RAK_Contact_Address__c)); recordValues.add(String.valueOf(relRec.Nature_of_Ownership__c)); recordValues.add(String.valueOf(relRec.RAK_Start_Date__c)); roleLst.add('UBO'); if(relRec.Is_Nominee__c){ roleLst.add('Nominee Board Member'); } if(relRec.Is_Trustee__c){ roleLst.add('Trustee'); } if(relRec.Is_Nominator__c){ roleLst.add('Nominator'); } if(relRec.Is_Trustor__c){ roleLst.add('Trustor'); } recordValues.add(String.Join(roleLst,',')); rels.rows.add(recordValues); } } } } if(passNationSet.size() > 0 || nameregNoSet.size() > 0){ relLnkfields.add('Trustee_Nominee__r.Nationality_PassportNo__c'); relLnkfields.add('Trustee_Nominee__r.Account_Name__c'); relLnkfields.add('Trustee_Nominee__r.Registration_Number__c'); relLnkfields.add('Trustor_Nominator__r.Nationality_PassportNo__c'); relLnkfields.add('Trustor_Nominator__r.Account_Name__c'); relLnkfields.add('Trustor_Nominator__r.Registration_Number__c'); string lnkQuery = string.format( 'SELECT {0} FROM Relationship_Link__c WHERE Account__c = :custId AND Is_Active__c = TRUE AND (Trustee_Nominee__r.Nationality_PassportNo__c IN :passNationSet OR Trustor_Nominator__r.Nationality_PassportNo__c IN :passNationSet OR (Trustee_Nominee__r.Account_Name__c IN :accNameSet AND Trustee_Nominee__r.Registration_Number__c IN :regNumberSet) OR (Trustor_Nominator__r.Account_Name__c IN :accNameSet AND Trustor_Nominator__r.Registration_Number__c IN :regNumberSet))', new List<string>{ string.join(relLnkfields, ',')} ); for (SObject record : Database.query(lnkQuery)) { Relationship_Link__c relLnkRec = (Relationship_Link__c)record; recordValues = new List<string>(); if(passNationSet.contains(relLnkRec.Trustee_Nominee__r.Nationality_PassportNo__c) || passNationSet.contains(relLnkRec.Trustor_Nominator__r.Nationality_PassportNo__c) || nameregNoSet.contains(relLnkRec.Trustee_Nominee__r.Account_Name__c+relLnkRec.Trustee_Nominee__r.Registration_Number__c) || nameregNoSet.contains(relLnkRec.Trustor_Nominator__r.Account_Name__c+relLnkRec.Trustor_Nominator__r.Registration_Number__c)){ for (string field : relLnkFieldsFinal) { if(field != 'relRef'){ recordValues.add(getFieldValue(record, field)); } } if(passNationSet.contains(relLnkRec.Trustee_Nominee__r.Nationality_PassportNo__c)){ recordValues.add(relLnkRec.Trustee_Nominee__r.Nationality_PassportNo__c); }else if(nameregNoSet.contains(relLnkRec.Trustee_Nominee__r.Account_Name__c+relLnkRec.Trustee_Nominee__r.Registration_Number__c)){ recordValues.add(relLnkRec.Trustee_Nominee__r.Account_Name__c+relLnkRec.Trustee_Nominee__r.Registration_Number__c); }else if(passNationSet.contains(relLnkRec.Trustor_Nominator__r.Nationality_PassportNo__c)){ recordValues.add(relLnkRec.Trustor_Nominator__r.Nationality_PassportNo__c); }else if(nameregNoSet.contains(relLnkRec.Trustor_Nominator__r.Account_Name__c+relLnkRec.Trustor_Nominator__r.Registration_Number__c)){ recordValues.add(relLnkRec.Trustor_Nominator__r.Account_Name__c+relLnkRec.Trustor_Nominator__r.Registration_Number__c); } if(relLnkRec.Type__c == 'Nominator/Nominee'){ relLnksNom.rows.add(recordValues); }else if(relLnkRec.Type__c == 'Trustor/Trustee'){ relLnksTrust.rows.add(recordValues); } } } } for (string objectName : requestInfo.GetObjectNames()) { if (objectName == 'relSh' || objectName == 'relDirSec' || objectName == 'relUBO') queryResultSet.add(rels); else if (objectName == 'nomRelLnks' || objectName == 'nomDirRelLnks' || objectName == 'nomUBORelLnks') queryResultSet.add(relLnksNom); else if (objectName == 'trustRelLnks' || objectName == 'trustDirRelLnks' || objectName == 'trustUBORelLnks') queryResultSet.add(relLnksTrust); } return queryResultSet; }
Here the object name is empty, How can i pass the relevant parameter here ?
for (string objectName : requestInfo.GetObjectNames()) { ..}
Thanks in advance,
Soundar Rajan P.
Increase code coverage
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
75 %
https://salesforce.stackexchange.com/questions/24165/why-is-75-code-coverage-required-in-salesforce/24167#24167
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.