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
Admin User 10568Admin User 10568 

Exclude fields values based on picklist value SOQL

Hi, 

Exclude fields values based on picklist value SOQL. 

I have a picklist for status. Anything without a status of 'available' I would like to exclude certain fields (not all). 

Any help would be very welcomed and appreciated. 

I'm working from here:

SELECT Id,name,Property_Level__c,Price_List_Property_Name__c,REPRO__Type__c,REPRO__Bdr__c,REPRO__Bth__c,REPRO__Study__c,REPRO__Internal_Size__c,REPRO__External_Size__c,REPRO__Car__c,REPRO__List_Price__c, REPRO__Status__c from REPRO__Property__c WHERE REPRO__Status__c= ('Available')  EXCLUDES ('REPRO__Status__c')

Many thanks, 
Alex
Best Answer chosen by Admin User 10568
Admin User 10568Admin User 10568
After more research. 

The solution was to write the conditions into the APEX/HTML table. 

For example:

 <apex:column headerValue="List Price" style="{!IF ((onc.REPRO__Status__c !='Available'),"background-color: #A9A9A9;","")}" >
                    <apex:outputLabel value="{!onc.REPRO__List_Price__c}" rendered="{onc.REPRO__Status__c ='Available'}"  />
                        <apex:outputField value="{!onc.REPRO__List_Price__c}" rendered="{!onc.REPRO__Status__c = 'Available'}"  />
                            <apex:outputLabel value="Reserved" rendered="{!onc.REPRO__Status__c != 'Available'}"  />
                                </apex:column> 

If the status isn't available it renders grey and shows the hardcoded value "reserved". Otherwise, the data from the map is rendered.

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi,
Please find the solution. "Exclude fields values based on picklist value SOQL"

You can query Like this to exclude Fields

1. select id,stagename from Opportunity where stagename not IN('Qualification','Value Proposition')

2. select id,stagename from Opportunity where stagename not IN('Qualification','Value Proposition') and stagename='Prospecting'

3.select id,stagename  from Opportunity where stagename='Qualification' 
i.e these exclude all except Qualification.

If you find this solution is helpful for you then please mark it as Best Answer.

Thank You

Admin User 10568Admin User 10568
Thanks, Suraj. 

I'm using the SOQL to query data for an apex table. 

I would like to exclude other objects/fields in the apex table based on the status picklist value. For example if a property in my table has the status of settled, the table would show only the property name and status. Otherwise, if the status picklilst value is available, all object information would be shown in the table.

Hope this makes more sense.
Admin User 10568Admin User 10568
After more research. 

The solution was to write the conditions into the APEX/HTML table. 

For example:

 <apex:column headerValue="List Price" style="{!IF ((onc.REPRO__Status__c !='Available'),"background-color: #A9A9A9;","")}" >
                    <apex:outputLabel value="{!onc.REPRO__List_Price__c}" rendered="{onc.REPRO__Status__c ='Available'}"  />
                        <apex:outputField value="{!onc.REPRO__List_Price__c}" rendered="{!onc.REPRO__Status__c = 'Available'}"  />
                            <apex:outputLabel value="Reserved" rendered="{!onc.REPRO__Status__c != 'Available'}"  />
                                </apex:column> 

If the status isn't available it renders grey and shows the hardcoded value "reserved". Otherwise, the data from the map is rendered.
This was selected as the best answer