You need to sign in to do that
Don't have an account?

Test class is not covered the code
Hi Everyone, Following code is not covered in test class, kindly help me to make it works,
queryString = 'SELECT '; for(Schema.FieldSetMember relationshipField :SObjectType.npe4__Relationship__c.FieldSets.Relationship_Field_Set.getFields()) { queryString += relationshipField.getFieldPath()+','; } queryString = queryString .removeEnd(','); queryString += ' FROM npe4__Relationship__c WHERE npe4__Contact__c IN (' + contactIdFilter + ')'; relationshipList= new List<relationshipWrapper>(); relationshipWrapper rel; for(npe4__Relationship__c currRec: Database.query(queryString) ){ rel= new relationshipWrapper(currRec); relationshipList.add(rel); }
<pre>
List<String> relationshipFields = new List<String>();
for ( Schema.FieldSetMember relationshipField :
SObjectType.npe4__Relationship__c.FieldSets.Relationship_Field_Set.getFields() )
{
relationshipFields.add( relationshipField.getFieldPath() );
}
queryString = String.join
( new List<String>
{ 'SELECT'
, String.join( relationshipFields, ',' )
, 'FROM npe4__Relationship__c'
, 'WHERE npe4__Contact__c IN (' + contactIdFilter + ')'
}
, ' '
);
relationshipList = new List<relationshipWrapper>();
for ( npe4__Relationship__c currRec : (List<npe4__Relationship__c>) Database.query( queryString ) )
{
relationshipList.add( new relationshipWrapper( currRec ) );
}
</pre>
To test this, there must be a field set on the npe4__Relationship__c object called "Relationship_Field_Set", and it must have at least one field in it. This is metadata, so you can't create it in your test class. It just has to exist. Your test code must create a Contact record and a npe4__Relationship__c record that looks up to that Contact. You don't show the code that creates "contactIdFilter", so I don't know how to set up the Contact to be included in the filter. If you do this, both loops will execute at least once, and all of the code you posted should be covered. Let me know if you have any more questions.