1

This below methods returns all the Market__c value when queried against all discountSchedule ID's.

Suppose i having 4 Id's in discountSchedule variable . If all the 4'ids are having same Market__c value then return Market__c else not..

Apex Class

public void updateMarketOptions() {
    marketOptions.clear();
    for (Custom_Package__c cp1 : [select Id, Market__c, state__c,First_Issue__c,Last_Issue__c,Circulation__c,Space_Unit__c ,Space_Discount__c, Per_Unit_Open_Rate__c from Custom_Package__c where Id in :discountSchedule  order by Market__c ]) {
        marketOptions.add(new SelectOption(cp1.Id, cp1.Market__c));
    }
}
  • Please re-phrase your question. Its not clear what you want to achieve. – Santanu Halder Nov 10 '15 at 9:53
  • Hi Santanu.. Can u chk now plzz.. – hellraizer Nov 10 '15 at 9:59
0

What a weird requirement! anyway! Here is what you need to do

public void updateMarketOptions() {
            String matchMarket;
            String id;
            Boolean firstCount = true;
            Boolean allMatched = true;
            marketOptions.clear();
            for (Custom_Package__c cp1 : [select Id, Market__c, state__c,First_Issue__c,Last_Issue__c,Circulation__c,Space_Unit__c ,Space_Discount__c, Per_Unit_Open_Rate__c from Custom_Package__c where Id in :discountSchedule  order by Market__c ]) {
                if(firstCount){
                   matchMarket = cp1.Market__c;
                   id = cp1.Id;
                   firstCount = false;
                }else{
                   if(!matchMarket.equalsIgnoreCase(cp1.Market__c)){
                        allMatched = false;
                        break;
                   }
                }
            }
if(allMatched)
  marketOptions.add(new SelectOption(Id, matchMarket));
}  
  • Hi.. I am getting error - Compile Error: Variable does not exist: cp1.Id – hellraizer Nov 10 '15 at 10:18
  • Oh! Rectified. Lets say there are 4 records. Now the code will add the first of the 4 records if all matched. – Santanu Halder Nov 10 '15 at 10:28
  • Hi.. Its not working..Suppose I am selecting 1st record market is populating..If i select another record whose market is same..Then it is not appearing...Can u please check.. – hellraizer Nov 10 '15 at 11:21
  • Suppose, records are {record1,Market1}, {record2,Market1}, {record3,Market3}, What SHOULD be added to marketOption list? – Santanu Halder Nov 10 '15 at 11:26
  • according to the value u showed nothing.. Only if the values are {record1,Market1}, {record2,Market1}, {record3,Market1} .. Then add it to marketOption list... – hellraizer Nov 10 '15 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.