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

i am going to write unit test class.but in pagereference method there are if conditions and for loops with lists...even i dont understand how to start the code. i am going to give some sample code ..please write test code for below.thanks in advance
public PageReference AddOptInQuestions (){
List<rfp_question__c> rqlist = new List<rfp_question__c>();
if(UserSelectOptInQ!= null){
if (!setOptInQ.contains(UserSelectOptInQ)){
for(Question_Product__c c: [SELECT Question__r.Id, Question__c, Product__c, Question__r.Question_Text__c, Question__r.type__c,Question__r.Chapter__c, Question__r.Subgroup__c, Product__r.name
FROM Question_Product__c WHERE Question__r.Opt_in_question__c =:true and Question__r.Subgroup__c=:UserSelectOptInQ limit 100]){
RFP_Question__c rq = new RFP_Question__c();
rq.Question__c = c.Question__r.id;
rq.Question_Text__c = c.Question__r.Question_Text__c;
rq.RFP__c = RFPId;
rq.Product__c = c.Product__c;
//rq.Unique_ID__c = RFPId + '-' + c.Question__r.ID;
rq.Type__c = c.Question__r.Type__c;
rq.Subgroup__c = c.Question__r.Subgroup__c;
rq.Chapter__c = c.Question__r.Chapter__c;
rq.ProductName__c = c.Product__r.name;
rq.status__C = 'Active';
selectedOptInQuestions.add(rq);
}
setOptInQ.add(UserSelectOptInQ);
OptInQ.add(UserSelectOptInQ);
}
if(selectedOptInQuestions.size()>0)
upsert selectedOptInQuestions;
}
Integer i;
for(rfp_question__c ri: [select no__c from rfp_question__c where Status__c != 'Removed' and RFP__c=:RFPId and no__c != null order by no__c desc limit 1]){
i = Integer.valueOf(ri.no__c);
}
if (i == null)
i = 0;
List<rfp_question__c> rqlist1 = new List<rfp_question__c>();
for(rfp_question__c rq: [select id, no__c, Question__r.Subgroup__c, Question__r.Type__c, Product__r.name from rfp_question__c
where RFP__c=:RFPId and no__c = null]){
i++;
rq.no__c = i;
rqlist1.add(rq);
}
if(rqlist1.size()>0)
upsert rqlist1;
return null;