+ Start a Discussion
Matt GajdaMatt Gajda 

Disallow back dating on log a call function

Hello,
  I am the admin for a company that has an instance of SFDC that has a lot of customizations and my experience with apex is minimal, so until now i have been making a lot of declarative changes to complete tasks that are given to me. Most recently, i have been asked to not let anyone back date calls that they are making. I am hoping it is a subtle change to the code that i can make. Also, i will be using a Sandbox enviroment to test the changes. Here are some screen shots to give you an idea of my under standing of what is happening with the code. First is a screen shot of what the log a call VF page looks like to the end users. Second is what i am presuming to the be the code that makes that page. Also, would it be difficult to remove the reminder date/ time and reminder notes fields?
 I am open to all suggestions and words of wisdom that may help me understand why this works the way it does. 

Thanks in advance,

Matt
User-added image
User-added image
Derek Davis 7Derek Davis 7
Hi Matt,
I would attempt to controll back dating issue with a validation rule before adding more code. Have you already tried that?
You could go to Setup >>> Customize >>> Leads >>> Validation Rules.

Create a new validation rule something like this:

Rule Name: No_Back_Dating_Allowed

Rule formula could be something like:
"Task.ActivityDate  >=  TODAY()"

And Error message:  "You cannot backdate calls..."


Regarding your second question. It should be pretty easy to remove those two fields. Would you mind coping and pasting your code into a code block in a comment below, and I will edit for you.

Good luck! I hope this helps.
Derek Davis 7Derek Davis 7
Actually - regarding removing the fields from the page... just delete what's highlighted in yellow.
I'm sure you are probably well aware... but it's good practice to make code changes in sandbox, test and deploy when your happy with results. Also - a lot of times when making simple visualforce changes like this I will just copy entire VF Page code and temporarily store it in a txt document on my desktop. Then if I accidently hose something it's easy to undo. ... not that I've ever done that of course.  ;)

Remove Reminder Notes & Reminder Date/Time from page.
Matt GajdaMatt Gajda
Derek, 

 Thank you for the suggestion, I will try the validation rule. Would i want the VR on the leads object or the activites object? 

Here is the code... Thanks again


<apex:page standardController="Task" extensions="TasksExtention"  showHeader="true" tabStyle="Lead">
   <style>
      .activeTab {background-color: #236FBD; color:white; 
         background-image:none}
      .inactiveTab { background-color: lightgrey; color:black; 
         background-image:none}
   </style>
   
    <apex:form >
        <apex:pageBlock title="Log a Task"> <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:inputField value="{! Task.Ownership__c}" label="Take Ownership of This Lead" rendered="{!CheckOwnership}"/>
                
            </apex:pageBlockSection>

            <apex:pageBlockSection >
                <apex:inputField value="{! Task.Type}" required="true"/>
                <apex:inputField value="{! Task.ActivityDate}" required="true"/>
                <apex:inputField value="{! Task.Rating__c}"/>
                <apex:inputField value="{! Task.Description}" style="width:90%; height:250%" required="true"/>
                <apex:inputField value="{! Task.Subject}" label="Reminder notes"/>
                <apex:inputField value="{! Task.ReminderDateTime}"/>
            <!--<apex:inputField value="{! Task.Why no Appt}"/>-->
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:outputText label=" " style="font-weight:800" value="Update the Ad Series if the lead/contact is responding to advertising."></apex:outputText>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Ad Series" for="AdSeries"></apex:outputLabel>
                    <apex:selectList id="AdSeries" value="{!Task.Ad_Series__c}" size="1" title="Ad Series">
                        <apex:selectOptions value="{!AdSeries}"></apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            
            <apex:pageBlockButtons >
                <apex:commandButton action="{!saveTask}" value="Save"/>
                <apex:commandButton action="{!saveTaskAndEmail}" value="Save & New Email"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    
    
</apex:page>
Derek Davis 7Derek Davis 7
To be clear... I still do work in Dev Sandbox, then deploy to QA (Full Copy Sandbox), then deploy to Production. I don't JUST store stuff in txt file. :)
Derek Davis 7Derek Davis 7
Hi Matt - sorry... validation rule will go on the Task... not the lead.

Try this code:
<apex:page standardController="Task" extensions="TasksExtention"  showHeader="true" tabStyle="Lead">
   <style>
      .activeTab {background-color: #236FBD; color:white; 
         background-image:none}
      .inactiveTab { background-color: lightgrey; color:black; 
         background-image:none}
   </style>
   
    <apex:form >
        <apex:pageBlock title="Log a Task"> <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockSection >
                <apex:inputField value="{! Task.Ownership__c}" label="Take Ownership of This Lead" rendered="{!CheckOwnership}"/>
                
            </apex:pageBlockSection>

            <apex:pageBlockSection >
                <apex:inputField value="{! Task.Type}" required="true"/>
                <apex:inputField value="{! Task.ActivityDate}" required="true"/>
                <apex:inputField value="{! Task.Rating__c}"/>
                <apex:inputField value="{! Task.Description}" style="width:90%; height:250%" required="true"/>
            <!--<apex:inputField value="{! Task.Why no Appt}"/>-->
            </apex:pageBlockSection>
            
            <apex:pageBlockSection columns="1" showHeader="false">
                <apex:outputText label=" " style="font-weight:800" value="Update the Ad Series if the lead/contact is responding to advertising."></apex:outputText>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Ad Series" for="AdSeries"></apex:outputLabel>
                    <apex:selectList id="AdSeries" value="{!Task.Ad_Series__c}" size="1" title="Ad Series">
                        <apex:selectOptions value="{!AdSeries}"></apex:selectOptions>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            
            
            <apex:pageBlockButtons >
                <apex:commandButton action="{!saveTask}" value="Save"/>
                <apex:commandButton action="{!saveTaskAndEmail}" value="Save & New Email"/>
                <apex:commandButton action="{!cancel}" value="Cancel"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
    
    
</apex:page>