global class CustomIterable
implements Iterator<ProductMaster__c>{
List<ProductMaster__c> pms{get; set;}
Integer i {get; set;}
public CustomIterable(){
pms =
[SELECT
Id,
Name,
Active__c ,
ValidPeriod__c
FROM
ProductMaster__c
WHERE
Active__c = true
];
i = 0;
}
global boolean hasNext(){
if(i >= pms.size()) {
return false;
} else {
return true;
}
}
global ProductMaster__c next(){
if(i == 3){return null;}
i++;
return pms[i-1];
}
}