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
Natasha AliNatasha Ali 

How to add a boolean variable to the apex class

Hi,
I have the following controller and need to add a criteris: AND 
Post_Ad__c = TRUE

How do I go about doing this?
public class OpportunityController {
    
    public List<Opportunity> opp {get;set;}

    public OpportunityController() {
        opp = [SELECT Id, Name, CreatedDate, Pathway__c, StageName, Placement__c, LDN_Company__c, Description, Job_Title__c, CloseDate, 
        NextStep, Salary__c, Future_Prospects__c, Duration__c, Training_Delivery_Site__c, Qualification_taken__c, Entry_Requirements__c, 
                Key_Responsibilities__c, Skills_Required__c, Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
        WHERE (StageName = '2 - Booked for CK' or StageName = '3 - Live'
                or StageName = '4 - Work Trial') AND (Placement__c = 'New Apprentice')];
          }
}

Any help is much appreciated!
Many Thanks,
Natasha :)
Ajay K DubediAjay K Dubedi
Hi Natasha,
Please replace your field with existing field and let me know if this works for you.If you still facing any problem then ask for same.
 
public class OpportunityController {
    public List<Opportunity> opp {get;set;}
    public OpportunityController() {
        opp = [SELECT Id, Name, CreatedDate, StageName,  Account.Name, Account.BillingPostalCode, Account.BillingStreet, Account.BillingCity FROM Opportunity 
               WHERE (StageName = 'Closed Won' or StageName = 'Closed Loss' or StageName='Prospecting') AND (Name = 'himalaya') AND (Post_Ad__c = true)];
        System.debug('oppp'+opp);
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Natasha AliNatasha Ali
Hi Ajay,
The query seems to be working fine, but the Visualforce page is still showing the wrong opps.
Natasha AliNatasha Ali
<apex:page controller="OpportunityController" docType="html-5.0" showHeader="false" standardStylesheets="false">
    <apex:stylesheet value="{!URLFOR($Resource.archive, 'styles/salesforce-lightning-design-system.css')}"/>
    <!-- <apex:stylesheet value="{!URLFOR($Resource.styles, 'styles.css' )}"/> -->
    <apex:stylesheet value="{!URLFOR($Resource.fontawesome,'/font-awesome-4.7.0/css/font-awesome.css')}"/>
    <!--jQuery CDN-->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <!--Salesforce Lightning Design System Static Resource-->
    <script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" loadonready="true">
        
        var j$ = jQuery.noConflict();
    
    </script> 
    <style>
        CUSTOM CSS HERE
    </style>
    <!-- HEADER WITH LOGO -->
    <div class="slds-panel slds-size_full slds-size_medium slds-panel_docked slds-panel_docked-left slds-is-open" aria-hidden="false">
         <div class="slds-panel__body slds-p-top_xx-large slds-p-left_large navbar-opps">
            <apex:image value="{!URLFOR($Resource.logo,'ldn-apprenticeships-logo.png')}" width="10%" height="10%"/>
            <!-- DROP DOWN MENU -->
            <div class="dropdown-about slds-float_right">
                <button class="slds-button">About</button>
                <div class="dropdown-content-about">
                    <a href="https://ldnapprenticeships.com/programmes/">Programmes</a>
                    <a href="https://ldnapprenticeships.com/careerkickstarter/">Career Kickstarter</a>
                    <a href="https://ldnapprenticeships.com/careerkickstarter/">Initiatives</a>
                </div>
            </div>
            <div class="dropdown-apps slds-float_right">
                <a href="https://ldnapprenticeships.com/employers/" class="slds-button">Apprentices</a>
            </div>
            <div class="dropdown-emps slds-float_right">
                <a href="https://ldnapprenticeships.com/apprentices/" class="slds-button">Employers</a>
            </div>
        </div>
    </div>
    <div class="slds-p-around_xx-large opps-body">
    <!-- OPPORTUNITY ADS -->
    <div class="slds-align_absolute-center slds-text-heading_medium opps-header">Apprenticeships Available Now</div>
    <apex:dataTable value="{!opp}" var="o" styleClass="slds-table slds-table--bordered slds-table_cell-buffer">     
        <apex:column styleClass="slds-truncate slds-line-height_reset">
            <!-- TAB TITLE -->
            <div class="slds-section" style="width: 100%" id="{!o.Id}">   
            <h3 class="slds-section__title">
                <button class="slds-button tab-button slds-section__title-action">
                    <span class="slds-truncate tab-title" title="Section Title"> 
                        {!o.Job_Title__c} - {!o.Employer_Name__c}
                    </span>
                    <span class="slds-icon_container slds-icon-utility-chevrondown" >
                        <svg aria-hidden="true" class="slds-icon slds-icon-text-default">
                           <use xmlns:xlink="http://www.w3.org/1999/xlink"
                                xlink:href="/apexpages/slds/latest/assets/icons/utility-sprite/svg/symbols.svg#chevrondown">
                           </use>
                        </svg>
                        <span class="slds-assistive-text">chevrondown</span>
                    </span> 
                </button></h3>
                <!-- CONTENT -->
                <div class="slds-section__content">
                    <div class="content-left">
                        <p class="header-text">Main Description</p>
                        <p class="long-text">{!o.Description}</p>
                        <p class="header-text">Key Responsibilities</p>
                        <span class="long-text">
                            <apex:outputText value="{!o.Key_Responsibilities__c}" escape="false"/>
                        </span>
                        <p class="header-text">Entry requirements</p>
                        <p class="long-text">{!o.Entry_Requirements__c}</p>
                        <p class="header-text">Skills Required</p>
                        <span class="long-text">
                            <apex:outputText value="{!o.Skills_Required__c}" escape="false"/>
                        </span>
                    </div>
                    <div class="content-right">
                        <apex:map width="400px" height="280px" mapType="roadmap" zoomLevel="15" center="{!o.Account.BillingStreet}">
                            <apex:mapMarker title="{!o.Account.Name}" position="{!o.Account.BillingStreet},{!o.Account.BillingCity},
                        {!o.Account.BillingPostalCode}"/>
                        </apex:map>
                        <div class="content-section">
                            <p class="header-text">Location</p>
                            <p class="long-text"> {!o.Account.BillingStreet}, {!o.Account.BillingCity}, {!o.Account.BillingPostalCode}</p>
                            <p class="header-text">Salary</p>
                            <span class="output-text">
                                <apex:outputText value="{0, number, ###,##0}">
                                    <apex:param value="{!o.Salary__c}" />
                                </apex:outputText>
                            </span> 
                            <p class="header-text">Qualifications</p>
                            <p class="long-text">{!o.Qualification_taken__c}</p>
                            <p class="header-text">Training delivery site</p>
                            <p class="long-text">{!o.Training_Delivery_Site__c}</p>
                            <p class="header-text">Possible Start Date</p>
                            <span class="output-text">
                                <apex:outputText value="{0,date,' 'dd'/'MM'/'yy}">
                                    <apex:param value="{!o.CloseDate}" />
                                </apex:outputText>
                            </span>
                            <p class="header-text">Duration</p>
                            <p class="long-text">{!o.Duration__c}</p>
                            <p class="header-text">What Next?</p>
                            <p class="long-text">{!o.Future_Prospects__c}</p>
                        </div>
                        <apex:form >
                        <!-- APPLY BUTTON -->
                        <!--<apex:commandButton action="{!redirect}" value="Apply" />-->
                        <apex:commandButton action="https://ldnapprenticeships.com/applynow?tfa_1974={!o.Id}&tfa_1976={!o.Pathway__c}&tfa_1982={!o.LDN_Company__c}" value="Apply" />
                    </apex:form>
                    </div>
                </div>
                <!-- END OF CONTENT -->
            </div>
        </apex:column> 
    </apex:dataTable>
    </div>
    <!-- FOOTER -->
    <div class="footer">
        <div class="footer-navbar">
            <ul id="menu-footer-menu" class="bottom-nav">
                <li><a href="https://ldnapprenticeships.com/about/">About</a></li>
                <li><a href="https://ldnapprenticeships.com/employers/">Employers</a></li>
                <li><a href="https://ldnapprenticeships.com/apprentices/">Apprentices</a></li>
                <li><a href="https://ldnapprenticeships.com/careerkickstarter/">Career Kickstarter</a></li>
                <li><a href="https://ldnapprenticeships.com/programmes/">Programmes</a></li>
                <li><a href="https://ldnapprenticeships.com/blog/">Blog</a></li>
                <li><a href="https://ldnapprenticeships.com/team/">Meet The Team</a></li>
                <li><a href="https://ldnapprenticeships.com/the-levy/">The levy</a></li>
                <li><a href="https://ldnapprenticeships.com/care-guidance/">Guidance</a></li>
                <li><a href="https://ldnapprenticeships.com/careers/">Careers</a></li>
                <li><a href="https://ldnapprenticeships.com/contact/">Contact</a></li>
            </ul>                   
        </div> 
        <p>LDN Apprenticeships LTD | Lansdowne, 278-280 South Lambeth Road, London, SW8 1UJ | hello@ldnapprenticeships.com The 
        friendly team at LDN Apprenticeships are here to help and support you. Contact us. Privacy Statement | Terms and Conditions
        </p>
    </div>
    <script loadOnReady="true">
    /*SLDS Sections*/
    j$('.slds-section__content').hide();
    j$('.slds-section__title').find('button').find('svg').css('transition', '0.3s');
    j$('.slds-section__title').click(function(){
            j$(this).parent().toggleClass('slds-is-open');
            if(j$(this).parent().hasClass('slds-is-open')){
                j$(this).parent().find('.slds-section__content').show();
            }else{
                j$(this).parent().find('.slds-section__content').hide();
            }
        }
    );

    /*SLDS Sections*/
    </script>
</apex:page>