Skip to main content
Pratima Shrivastav (Slalom) 님이 #Visualforce에 질문했습니다
Hi here is my vf page..

<apex:page Controller="Site_Visit1__c" >

    <apex:form >

        

        <apex:pageBlock title="Edit SiteVisit">

            <apex:pageBlockSection columns="1">

                <apex:inputField value="{!Site_Visit1__c.Name}"/>

                <apex:inputField value="{!Site_Visit1__c.Doctor_Office__c}"/>

                <apex:inputField value="{!Site_Visit1__c.Time_and_Date__c}"/>

                

         

          </apex:pageBlockSection>

            <apex:pageBlockButtons >

                <apex:commandButton action="{!save}" value="Save"/>

            </apex:pageBlockButtons>

       

        </apex:pageBlock>

        

    </apex:form>

</apex:page>

 I want to write a controller to make sure that new records entered should be checked with records already existingin database that name of doctor office should not be entered twice if it was visited within last 5 days. Please suggest me the SOQL required for that as well as how can I compare the input values with already existing values in database.

 Thnaks in advance
답변 1개
  1. 2016년 4월 21일 오전 10:18
    public class SiteVisitExension {

        public  Site_Visit1__c objSiteVisit {get;set;}

        public SiteVisitExension(ApexPages.StandardController stdController) {

            this.objSiteVisit = new Site_Visit1__c();

            objSiteVisit = (Site_Visit1__c)stdController.getRecord();

        }

        public void save() 

        {

            if(String.isNotBlank(objSiteVisit.Doctor_Office__c))

            {

    /*** I am assuming CreatedDate should lie in last 5 days****/

                Integer intCount = [SELECT COUNT()

                                FROM Site_Visit1__c 

                                WHERE Doctor_Office__c =:objSiteVisit.Doctor_Office__c 

                                    AND CreatedDate = LAST_N_DAYS:5];

                if(intCount > 0)

                {

                    // Code to show error message on page

                }

            }

            

        }

    }

     
0/9000