function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rajesh k 10rajesh k 10 

How can i check map Condition?

Hi,
       Using vf page I calculated 
<apex:column headerValue="Total">
                         <apex:outputtext value="$ {!IF(Inpitem.includedProduct.Quantity__c > 0 , Inpitem.includedProduct.Quantity__c * ProductidToPricebookEntry[Inpitem.includedProduct.Product__c], 0)}">
                           <apex:variable var="grandTotal" value="{!grandTotal + (Inpitem.includedProduct.Quantity__c * ProductidToPricebookEntry[Inpitem.includedProduct.Product__c])}" />
                        </apex:outputtext>
                        </apex:column>

In controller i constructed map like below
 
for (PricebookEntry pricBkEntry: [SELECT Product2Id, Pricebook2Id, UnitPrice FROM PriceBookEntry WHERE Product2Id IN: productids AND Pricebook2Id = : pricebookid AND CurrencyIsoCode = 'USD']) {
                Decimal Listprice = pricBkEntry.UnitPrice;
                ProductidToPricebookEntry.put(pricBkEntry.Product2Id, Listprice);
            }

I was getting some times Map Key not Exist(It show in like 01tD000000108Mw(ProductId) with visualforce page culcuation).How can i chaeck Map Condition here 

help me...
goabhigogoabhigo
Hi Rajesh,

I am afraid there is no direct way to check if the map has the key, since we cannot use containsKey() method inside VF page. However, you can use something like this:

Controller:

public Boolean getCheckMapForKey(){
    return ProductidToPricebookEntry.containsKey(keyToCheck); // keyToCheck is a string which will be passed from VF page
}

VF page:
<apex:column headerValue="Total">
     <apex:outputtext value="$ {!IF(Inpitem.includedProduct.Quantity__c > 0 , Inpitem.includedProduct.Quantity__c * ProductidToPricebookEntry[Inpitem.includedProduct.Product__c], 0)}" rendered="{!CheckMapForKey}">
          <apex:variable var="grandTotal" value="{!grandTotal + (Inpitem.includedProduct.Quantity__c * ProductidToPricebookEntry[Inpitem.includedProduct.Product__c])}" />
          <apex:param name="keyToCheck" value="{!Inpitem.includedProduct.Product__c}"
      </apex:outputtext>
</apex:column>

There are various other ways discussed here (http://salesforce.stackexchange.com/questions/15748/can-we-check-if-a-key-exists-in-a-map-in-vf-page).

--
Abhi

If my answer helps to solve the issue/problem/doubt, please mark it as Best Answer; so that people who are stuck in the similar issue get benefitted.