• shubhi vijayvergia
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi everyone,

I have Visualforce page and i want populate massage based on cirtain condition while saving the record.
Here is my code:

<apex:page standardController="Travel_Request__c" extensions="DataValidate" showHeader="true" sidebar="false" title="Travel Request"> 

    
  
  <apex:form > 
     
<script>
    function validateName(trdesID,)
    {
        var desig=document.getElementById(trdesID);
        
        
        if(pc.Designation__c == tc.Designation__c && tc.Advance__c=='Cash Advance' && tc.Amount__c > pc.Cash_Advance__c)
        {
                    var msg="HEY";
                        alert(msg);
                    return true;
           }
        
       
    }
  </script>
 <apex:slds />  
 <div class="slds-scope">
 <apex:outputPanel id="TR">
 <apex:pageBlock title="Travel Request">
 <apex:pageBlockSection columns="2" title="General Information" collapsible="false">
 
       <apex:inputField value="{!Travel_Request__c.Name}"/>   
          
       <apex:inputField value="{!Travel_Request__c.Branch__c}"/>   
       <apex:inputField value="{!Travel_Request__c.Department__c}" /> 
       <apex:inputField value="{!Travel_Request__c.Designation__c}" id="trdesigID"/> 
       <apex:inputField value="{!Travel_Request__c.Travel_Mode__c}"/>   
       <apex:inputField value="{!Travel_Request__c.Travel_Start_Date__c}"/>
       <apex:inputField value="{!Travel_Request__c.Travel_End_Date__c}"/>
        <apex:inputField value="{!Travel_Request__c.Meals_Choice__c}"/>
        <apex:inputField value="{!Travel_Request__c.Status__c}" />
       <apex:inputField value="{!Travel_Request__c.Travel_Type__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>

       <apex:inputField value="{!Travel_Request__c.Accommodation_Required__c}">
       <apex:actionSupport event="onchange" rerender="TR" />
      
                    </apex:inputField>
         <apex:inputField value="{!Travel_Request__c.Advance__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>
         <!---
         <apex:inputField value="{!Travel_Request__c.Travel_Card_Loaded__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>
         <apex:inputField value="{!Travel_Request__c.Travelers_Cheque__c}">
        <apex:actionSupport event="onchange" rerender="TR" />
         </apex:inputField>
              --->      
                </apex:pageBlockSection>                
                <apex:pageBlockSection columns="2" Title="Travel Type Information">                     
         <apex:inputField value="{!Travel_Request__c.Proposed_Countries_To_Visit__c}" rendered="{!IF( Travel_Request__c.Travel_Type__c == 'Overseas',true,false  )}" />                   
          <apex:inputField value="{!Travel_Request__c.Proposed_City__c}" rendered="{!IF( Travel_Request__c.Travel_Type__c == 'Overseas',true,false  )}" />
                   
                </apex:pageBlockSection> 
        
        
      
   <apex:pageBlockSection columns="2" collapsible="true" title="Accomodation Information" > 
   <apex:inputField value="{!Travel_Request__c.Check_In_Date__c}" 
                          rendered="{!IF( Travel_Request__c.Accommodation_Required__c == 'Yes',true,false )}" /> 
   <apex:inputField value="{!Travel_Request__c.Check_Out_Date__c}" 
                          rendered="{!IF( Travel_Request__c.Accommodation_Required__c == 'Yes',true,false )}" /> 
   <apex:inputField value="{!Travel_Request__c.City_Name__c}" 
                          rendered="{!IF( Travel_Request__c.Accommodation_Required__c == 'Yes',true,false )}" /> 
                          
         
</apex:pageBlockSection>
<apex:pageBlockSection columns="2" collapsible="true" title="Advance Section" > 
   <apex:inputField value="{!Travel_Request__c.Amount__c}" 
                          rendered="{!IF( Travel_Request__c.Advance__c == 'Cash Advance',true,false )}" />
   <apex:inputField value="{!Travel_Request__c.Travel_card_Amount__c}" 
                      rendered="{!IF( Travel_Request__c.Advance__c == 'Travel Card Loaded',true,false )}" />
   <apex:inputField value="{!Travel_Request__c.Card_Number__c}" 
                          rendered="{!IF( Travel_Request__c.Advance__c == 'Travel Card Loaded',true,false )}" />       
                          
  <apex:inputField value="{!Travel_Request__c.Travelers_Cheque_Number__c}" 
                     rendered="{!IF( Travel_Request__c.Advance__c == 'Travelers Cheque',true,false )}" />       
                           
   <apex:inputField value="{!Travel_Request__c.Quantity__c}" 
                       rendered="{!IF( Travel_Request__c.Advance__c == 'Travelers Cheque',true,false )}" />       
                          
  <apex:inputField value="{!Travel_Request__c.Denomination__c}" 
                     rendered="{!IF( Travel_Request__c.Advance__c == 'Travelers Cheque',true,false )}" />       
                          
</apex:pageBlockSection>
</apex:pageBlock>
            <div align="center" draggable="false" >
            <apex:commandButton action="{!Save}" value="Save" oncomplete="validateName('{!$Component.trdesigID}')"/>
            <apex:commandButton action="{!Cancel}" value="Cancel"/>
            <apex:commandButton action="{!Edit}" value="Edit"/>
            </div>
</apex:outputPanel>
</div>
</apex:form>
</apex:page>
Hi,

  I want to schedule belows class to run every 1hour I tried using the scheduler to run every day at a specific time but this is not working please suggest me how to make this work. 
 
list<String> toAddresses = new List<String>();
 list<Messaging.SingleEmailMessage> mailsToSend = new List<Messaging.SingleEmailMessage>();
 list<opportunity> opp = new list<opportunity>();
 String htmlBody; 

 opp = [select id,name,account.name,owner.name,owner.email, 
               Stage_Prior_Value__c,StageName,Close_Date_Prior_Value__c,
               closedate,f_ACV__c 
         from Opportunity 
         where Stage_Prior_Value__c = '2 - Contracts' or Stage_Prior_Value__c = '3rd Notice - Contracts' ];

for(Opportunity Op: Opp){
 htmlbody = '<html><body>';             
 htmlbody += '<p><strong> Owner Name : ' + op.owner.name + '</strong><br/></p>';
 htmlbody += '<p><strong> Account Name : ' + op.Account.name + '</strong><br/></p>';    
 htmlbody += '<p><strong> ACV Amount : ' + op.f_ACV__c + '</strong><br/></p>';    
 htmlbody += '<p><strong> Prior Forecast Category : ' + op.Stage_Prior_Value__c + '</strong><br/></p>';    
 htmlbody += '<p><strong> New Forecast Category : ' + op.stagename + '</strong><br/></p>';       
 htmlbody += '</body> </html>';   
          
      toAddresses.add('sudhir.narayanaswamy@gmail.com')    
      Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
      mail.setToAddresses(toAddresses);      
      mail.setSenderDisplayName('Deals moving out of Commit forecast ');
      mail.setSubject('Deals moving out of Commit forecast ');
      mail.setUseSignature(false);            
      mail.setHtmlBody(htmlBody);
      mailsToSend.add(mail);
      Messaging.sendEmail(mailsToSend);    
    
}

Thanks
Sudhir
Salesforce.com could not email the report to any of the specified recipients. Check that recipients are specified and that they have the appropriate permissions to view the report.

If you get this ^error:

Make sure you also check:
Setup > Customize > Reports & Dashboards > Email Notifications > Allow Reports and Dashboards to Be Sent to Portal Users

Posting this here since it took me a long time to find this checkbox.