• satakshi
  • NEWBIE
  • 150 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 57
    Questions
  • 49
    Replies
Hello,
I want validation rule on account object. Its a professional edition. When lead converts into account I am checking Client__c field.
I want validation rule on account so that if that account is created by lead conversion and client is equal to true then account address is manadatory. I am getting validation error on lead conversion page rather than account page.

AND( ISBLANK(BillingAddress), NOT(ISNEW()), Client__c  = TRUE)
Hello,

 I am writing a code where if checkbox is checked then mail will send to desired user otherwise it will show an error "Please select checkbox". Can i get javascript for this?

<apex:pageBlockTable value="{!searchResults}" var="accWrap" id="table"">
 <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
<apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/> 
<apex:column colspan="5" value="{!accWrap.acc.Name}" />
<apex:column colspan="5" value="{!accWrap.acc.Email}" />
<apex:column colspan="5" value="{!accWrap.acc.Phone}" />
</apex:pageBlockTable>

I want functionality where if checkbox is checked then only email will send to desired user otherwise it will throw an error "Please select atleast one contact". How it is possible?
 

          <apex:pageBlockTable value="{!searchResults}" var="accWrap" id="table" >                                    
                    <apex:column colspan="2">
                      <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/> </apex:column>                   
                    <apex:column colspan="5" value="{!accWrap.acc.Name}" />
                    <apex:column colspan="5" value="{!accWrap.acc.Email}" />
                    <apex:column colspan="5" value="{!accWrap.acc.Phone}" />
          </apex:pageBlockTable>
     
Hello,
I am writing a code whre i want to come back on previous page. but in my case back button is not working. can anyone please help me?

public pageReference CancelAction()
 {
  PageReference pr1 = new PageReference('/apex/SBAddQuestionPage' );
 pr1.setRedirect(true);
 return pr1;



 <apex:commandButton value="Back"  action="{!CancelAction}" styleClass="red-btn" style="margin-left: 113% !important; margin-top: -2% !important; font-weight: bold;"/>   

Thanks & Regards,
Satakshi
Hello,

  I am writing code ehre i e=want to refresh page after picklist value is change. not when it is save. please help me to achieve this.
<apex:page controller="QBsampleCon" sidebar="false" showHeader="false" standardStylesheets="false">

<html>
<head>

            <div class="formFeildreport formFeild">
            <div class="feild formFeild">
       <!--<h2 style="color:black; "> Question Type:</h2> class="questionlabel"-->
             
             <label class="questionlabel" id="picvalchange">Question Type</label>

            <apex:selectList value="{!pickval}" multiselect="false" size="1" id="PickVal" styleClass="Picklist" label="Question Type:" ><br />
             <apex:actionSupport event="onchange" action="{!pickvalselect}" />   
            <apex:selectOptions value="{!SelectedOptions}"/>
            </apex:selectList><br /><br />
            
            </div>                 
          
Thanks & Regards,
Satakshi
 
Hello,

I am writing a code where i want functionality where if contact are not selected then it will throw error otherwise it will proceed further. i tried a lot. but its not working..
My code is:
public with sharing class ContactSelectClassController

{

    public String beforeblob1{get;set;}
    //public String conid{get;set;}
    public String emailEncoded { get; set; }
    public String email { get; set; }
    public String phoneEncoded { get; set; }
    public String con_number { get; set; }
    public String fullname{get;set;}
    public String emailName{get;set;}
    public String fullnameEncoded{get;set;}
    @TestVisible public List<wrapAccount> wrapAccountList {get; set;}
    //-----added----
   
    public List<Contact> selectedAccounts{get;set;}
    
    public String feedid;
    private  List<Id> contactids=new list<Id>();
    public List<Contact> cont{get;set;}
 
    public List<Feedback_Contacts__c> feedcon{get;set;}  
 
// ---------for search-------
    
    public List<wrapAccount> searchResults {get;set;}
    public List<String> selectP = new List<String>();
    
//--------------searchText--------------
   
    public string searchText {
        get {
            if (searchText == null) searchText = ''; // prefill the serach box for ease of use
            return searchText;
        }
        set;
    }  

   
//--------------ContactSelectClassController()--------------  
   
    public ContactSelectClassController()
    {
     feedid= (ApexPages.currentPage().getParameters().get('fid'));
     emailName= (ApexPages.currentPage().getParameters().get('emailName'));
     fullnameEncoded = ApexPages.currentPage().getParameters().get('fullname');
     emailEncoded = ApexPages.currentPage().getParameters().get('email');
     phoneEncoded = ApexPages.currentPage().getParameters().get('con_number');
              
      //-------added--------
         
      if(searchResults == null)
      {
        searchResults = new List<wrapAccount>(); // init the list if it is null
      }
      
      else
      {
        wrapAccountList.clear(); // clear out the current results if they exist
      }
           
      String qry =  'select Id,Name,Email,Phone from Contact  where firstname LIKE \''+String.escapeSingleQuotes(searchText)+'%\' OR lastname LIKE \''+String.escapeSingleQuotes(searchText)+'%\'';
      for(Contact c : Database.query(qry))
      {
             
     
        
         wrapAccount wa = new wrapAccount(c);
        searchResults.add(wa);
      
      }
           
    //-------added--------
       
      }

//--------------search()--------------


 public PageReference search() {
 
      searchResults = new List<wrapAccount>();
      
      String qry = 'select Id,Name,Email,Phone from Contact where firstname LIKE \''+String.escapeSingleQuotes(searchText)+'%\' OR lastname LIKE \''+String.escapeSingleQuotes(searchText)+'%\'';
      List<Contact> contactList = Database.query(qry);
       
       if(contactList.size()<1)
       {
       String htmlText = 'Oops...Contact not found, Sorry !';
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info, htmlText));
       }  
         
      for(Contact c : Database.query(qry)) {
          
            wrapAccount cw = new wrapAccount(c);
            searchResults.add(cw);
        }
       
     return null;
    }

//--------------CancelAction()--------------
   
   public pageReference CancelAction()
  {
    PageReference pr1 = new PageReference('/apex/SBSendSurvey');
    pr1.setRedirect(true);
    return pr1;
  }
    
    
//--------------processSelected()--------------
    
     @TestVisible public void processSelected()
     {
     try
       {
     
     feedid= (ApexPages.currentPage().getParameters().get('id'));
    
     fullnameEncoded = ApexPages.currentPage().getParameters().get('fullname');
   
     if(fullnameEncoded !=null || fullnameEncoded =='')
     {
        Blob bodyBlob1 =EncodingUtil.base64Decode(fullnameEncoded );
        fullname = bodyBlob1.toString();
        
     }
  else
  {
   fullname = ApexPages.currentPage().getParameters().get('fullname');
  }
    emailEncoded = ApexPages.currentPage().getParameters().get('email');
 
    if(emailEncoded !=null || emailEncoded =='')
    {
      Blob bodyBlob1 =EncodingUtil.base64Decode(emailEncoded );
      email = bodyBlob1.toString();
    }
  else
  {
   email = ApexPages.currentPage().getParameters().get('email');
  }
  phoneEncoded = ApexPages.currentPage().getParameters().get('con_number');
  if(phoneEncoded !=null )  
  {
  Blob bodyBlob2 =EncodingUtil.base64Decode(phoneEncoded );
  con_number =bodyBlob2.toString();
  }
  else
  {
  con_number=ApexPages.currentPage().getParameters().get('con_number');
  }
        
    selectedAccounts = new List<Contact>();
                            
        for(wrapAccount wrapAccountObj : searchResults)
         {
            if(wrapAccountObj.selected == true)
             {
                selectedAccounts.add(wrapAccountObj.acc);
                
             }
        }
        
           for(Contact cont : selectedAccounts)
              {
                contactids.add(cont.Id);
              }
           
       feedcon = new List<Feedback_Contacts__c>();

        cont  = new List<Contact>();
        cont  =  [Select firstname,lastname,email,id,name,MobilePhone from Contact where id in :selectedAccounts];
        for(Contact c :cont)
        {
       
        string fullname = c.firstname + ' ' + c.lastname;
      
        Blob beforeblob = Blob.valueOf(fullname);
        EncodingUtil.urlEncode(fullname,'UTF-8');
     
        string email = c.email;
        Blob beforeblob1 = Blob.valueOf(email);
        EncodingUtil.urlEncode(email,'UTF-8');
   
           string con_number = c.MobilePhone;

           Blob beforeblob2 = Blob.valueOf(con_number);
           EncodingUtil.urlEncode(con_number,'UTF-8');
    
       
        Feedback_Contacts__c fc = new Feedback_Contacts__c();
        fc.FeedbackContactName__c= c.Id;
        //system.debug('++++++++++ConNumber__c++++++++++'+ fc.FeedbackContactName__c);
        fc.FeedBackNo__c = feedid;
        // system.debug('++++++++++ConNumber__c++++++++++'+fc.FeedBackNo__c);

        fc.test__c = EncodingUtil.base64Encode(beforeblob );
        fc.Email__c = EncodingUtil.base64Encode(beforeblob1 );
       fc.ConNumber__c= EncodingUtil.base64Encode(beforeblob2 );
         //system.debug('++++++++++ConNumber__c++++++++++'+ fc.ConNumber__c+'**'+fc.FeedBackNo__c);
        feedcon.add(fc);
        //system.debug('++++++++++feedcon++++++++++'+feedcon);
       }
       insert feedcon;
        
        // system.debug('++++++++++INSERT++++++++++'+feedcon);
      
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setTargetObjectIds(contactids);
   
     if(!Test.isRunningTest())
     {
   
          EmailTemplate templateId = [Select id from EmailTemplate where name = 'SurveyFeedback'];
         // system.debug('+++++++++++++++++++++++TEMPLATE ID++++++++++++++++++++++++++++++'+templateId.id);
          
        mail.setTemplateId(templateId.id); //00X55000000E1LO
        Messaging.sendEmail(new Messaging.MassEmailMessage[] {mail});
        
      }   
        String msg1 = 'Mail Sent!';
      ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO,msg1));
    }
        catch(Exception e) {
       // System.debug('Oops ! Email limit exceeded...Sorry');
               ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Error,'Message not sent'));
System.debug('*********************Oops ! Email limit exceeded...Sorry******************************');
      }    
     }
     
     
//--------------class wrapAccount--------------

    @TestVisible public class wrapAccount {
        public Contact acc {get; set;}
        public Boolean selected {get; set;}
 
        public wrapAccount(Contact a) {
            acc = a;
            selected = false;
        }
    }
    
    
//--------------Redirect()--------------

    
    public PageReference Redirect(){
    PageReference ref = new PageReference('/apex/SBEmailTemplate');
    ref.setRedirect(true);
    return ref;
    }
    
    
    public PageReference RedirectCon(){
    PageReference ref = new PageReference('/apex/ContactPage');
    ref.setRedirect(true);
    return ref;
    }
    
}

Thanks & regards,
Satakshi
Hello, I am writing a code where i want to show contact name as a link. so after clicking on the name i will go into org and edit delete the record. I want this on this line.   <apex:column colspan="5" value="{!accWrap.acc.Name}" /> Can anyone help me to achiev this?




<apex:page controller="ContactSelectClassController" sidebar="false" showHeader="false" standardStylesheets="false">
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Send Mail</title>
<apex:stylesheet value="https://fonts.googleapis.com/css?family=Roboto:400,300,500,700,900"/>
<apex:stylesheet value="{!$Resource.SurveyMaster}"/>
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"/ >
<!--<link href="https://fonts.googleapis.com/css?family=Roboto:400,300,500,700,900" rel="stylesheet" type="text/css">
<link href="assets/css/master.css" rel="stylesheet">-->

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script>
function ShowHide(){
document.GetElementById('field1').display='block';
}
 
</script>
<style>
.lookupIcon {
 background-image: url('{!$Resource.LookupIcon}') !important;
 height:30px !important;
 width:30px !important;
 position:absolute !important;
 top:6px !important;
 right:-25px !important;
}

.lookupIconOn {
 background-image: url('{!$Resource.LookupIcon}') !important;
 height:30px !important;
 width:30px !important;
 position:absolute !important;
 top:6px !important;
 right:-25px !important;
}

.SearchField{
background: #F6F6F6;
    height: 36px;
    border-radius: 6px;
    border: 1px solid #E1E1E1;
    padding: 0 15px;
    width: 20%;
    font-family: 'Roboto', sans-serif;
    font-size: 16px;
    font-weight: 400;
    }
</style>

    <script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");
            for(var i=0; i<inputCheckBox.length; i++){
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
    
     <script type="text/javascript">
      function doSearch() {
      searchServer(
      document.getElementById("name").value
     
      );
  }
  </script>
  <script type="text/javascript">
        function validate() {
     
            {
              alert ( "Survey has been sent successfully" );
              
            }
        
            }
    </script>
    </head>
    
    <body>
    
<header class="mainHeader">
    <div class="container clear">
        <a href="/apex/SBIndex" class="logo"><img src="{!$Resource.MainLogo}" alt=""/></a>
        <div class="nav">
            <ul>
                <li><a href="/apex/SBIndex" class="home"><img src="{!$Resource.HomeIcon}" alt=""/></a></li>
                <li><a href="/apex/SBQuestionBank">Question Bank</a></li>
                <li><a href="/apex/SBCreateSurvey">Create Survey</a></li>
                <li class="active"><a href="/apex/SBSendSurvey">Send Survey</a></li>
                <li><a href="/00O50000004d9Np">Report</a></li>
            </ul>
        </div>
    </div>
</header>


<section class="page-name">
    <div class="container clear">
        <h2>All Contacts</h2>
    </div>
</section>

<section class="bodyContainer">
    <div class="container clear">
    
    <apex:form >
     <!--<apex:commandButton value="Add Contact" action="{!RedirectCon}" style="font-weight: bold;display: inline-block !important;padding: 3px 15px !important;line-height: 35px !important;color: #fff !important;font-size: 15px !important;background: #75C181 !important;border-radius: 35px !important; min-width: 125px !important;text-align: center !important; margin-left: 12px !important;   margin-bottom: 20px; float: right;"/>-->
 
     <!--<apex:commandButton value="Edit Template" action="{!Redirect}" style="font-weight: bold;display: inline-block !important;padding: 3px 15px !important;line-height: 35px !important;color: #fff !important;font-size: 15px !important;background: #75C181 !important;border-radius: 35px !important; min-width: 125px !important;text-align: center !important; margin-bottom: 20px; float: right;"/>-->
    
        
   <!-- For search -->
   
      <apex:outputLabel for="searchText">Search Contact</apex:outputLabel>&nbsp;&nbsp;
         <apex:panelGroup >
            <apex:inputText id="searchText" styleClass="SearchField" value="{!searchText}"/>&nbsp;&nbsp;
              <apex:commandButton value="Search" action="{!search}" styleClass="green-btn" style="font-weight: bold;"/>
         </apex:panelGroup>
         
   <!-- For search -->
    
       <apex:pageBlock >
        <apex:messages style="color:red;font-size:15px;" /><br />
        <div style="overflow: scroll; width:100%; height:300px;">
          <apex:pageBlockTable value="{!searchResults}" var="accWrap" id="table" width="100%" cellpadding="0" cellspacing="0" border="0" styleclass="defaultTable addquestionpage" style="overflow:scroll;">
                                     
                    <apex:column colspan="2">
                        <apex:facet name="header">
                            <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
                        </apex:facet>
                      <apex:inputCheckbox value="{!accWrap.selected}" id="inputId"/>
                    </apex:column>
                     
                   
                      <apex:column colspan="5" value="{!accWrap.acc.Name}" />
                    <apex:column colspan="5" value="{!accWrap.acc.Email}" />
                    <apex:column colspan="5" value="{!accWrap.acc.Phone}" />
          </apex:pageBlockTable>
          </div>
             
          <!--<apex:pageBlockTable value="{!selectedAccounts}" var="c" id="table2" width="100%" cellpadding="0" cellspacing="0" border="0" styleclass="defaultTable addquestionpage" style="margin-top:20px;">
                   <apex:column colspan="4" value="{!c.Id}" headerValue="Contact"/>
                    <apex:column colspan="4" value="{!c.Name}" headerValue="Contact Name"/>
                    <apex:column colspan="4" value="{!c.Email}" headerValue="Email"/>
                    <apex:column colspan="4" value="{!c.Phone}" headerValue="Phone"/>
           </apex:pageBlockTable>-->
        
          </apex:pageBlock>
      
         <div class="feild buttons">
                
                <apex:commandButton value="Send Survey" onclick="validate()"  action="{!processSelected}" styleClass="green-btn" rerender="table2" style="margin-top: 20px;font-weight: bold;"/>
                <apex:commandButton value="Cancel" action="{!CancelAction}" styleClass="red-btn" style="font-weight: bold;"/>
           
         </div>
         
         </apex:form>
     </div>
</section>

<footer class="main-footer">
    <ul>
        <li> <a href="#">Privacy Policy</a> </li>
        <li><a href="#">Terms of Services</a></li>
    </ul>
    <div class="copyright">© 2016 Survey Builder, All rights reserved. </div>
</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</body>
</html>

</apex:page>
Hello, 

I am writing a code where when i will create record date should be automatically create into visualforce. i am getting error in this line        date myDate = date.newInstance(obj.Year__c, obj.Month__c, 1);
Can anyone please help me to solve this?

public with sharing class Calender {
    public List<DTP__c> mydtpList{get;set;}
    public  MTP__c obj{get;set;}
    public Calender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 

     }

public Decimal dy;
public date myDate;

public  id tid{get;set;}

    public PageReference createdtp() {
     
        System.debug('***************tid tid*******************'+tid);
        obj = [Select  Id, Month__c, Year__c,  February__c, NumberOfDays__c from MTP__c where id=:tid ];
        dy= obj.NumberOfDays__c;
        if(obj.February__c !=null)      
        {
         String str=obj.February__c;
         dy=Decimal.ValueOf(str);
        }  
           else 
           {
            Decimal str= obj.NumberOfDays__c;
         dy=str;
         }
        
       
        
/*
    for(MTP__c mt:obj)
    {
    if(mt.Month__c=='February')
    
    {
    String str=mt.February__c;
    dy=Decimal.ValueOf(s
      System.debug('***************in IF dy size******************'+dy);
    }
    else
    {
     Decimal str= mt.NumberOfDays__c;
      dy=str;
        System.debug('***************in  else dy size******************'+dy);
    }
    }*/
    
  List<DTP__c> newdtp= new List<DTP__c>();
   System.debug('***************dy size******************'+dy);
    for(Integer i = 1; i<=dy; i++)

    {
       DTP__c  dt = new DTP__c();
       dt.MTP__c=tid;
       date myDate = date.newInstance(obj.Year__c, obj.Month__c, 1);
       Integer day = myDate.dayOfYear();
       system.assertEquals(294, day);
       newdtp.add(dt);
       System.debug('****************dtp added********************'+tid);
       //insert newdtp;
     
   
    }
    insert newdtp;
    return null;
    }
   
    }


Thanks & Regards,
Satakshi
Hi,
I want functionality where according to month and year date will automatically added into record. How can we achive it?



public with sharing class Calender {
    public List<DTP__c> mydtpList{get;set;}
    public  MTP__c obj{get;set;}
    public Calender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 

     }

public Decimal dy;
public  id tid{get;set;}

    public PageReference createdtp() {
     
        System.debug('***************tid tid*******************'+tid);
        obj = [Select  Id, Month__c, Year__c,  February__c, NumberOfDays__c from MTP__c where id=:tid ];
        dy= obj.NumberOfDays__c;
        if(obj.February__c !=null)      
        {
         String str=obj.February__c;
         dy=Decimal.ValueOf(str);
        }  
           else 
           {
            Decimal str= obj.NumberOfDays__c;
         dy=str;
         }
        
       
        
/*
    for(MTP__c mt:obj)
    {
    if(mt.Month__c=='February')
    
    {
    String str=mt.February__c;
    dy=Decimal.ValueOf(s
      System.debug('***************in IF dy size******************'+dy);
    }
    else
    {
     Decimal str= mt.NumberOfDays__c;
      dy=str;
        System.debug('***************in  else dy size******************'+dy);
    }
    }*/
    
  List<DTP__c> newdtp= new List<DTP__c>();
   System.debug('***************dy size******************'+dy);
    for(Integer i = 1; i<=dy; i++)

    {
       DTP__c  dt = new DTP__c();
       dt.MTP__c=tid;
       newdtp.add(dt);
       System.debug('****************dtp added********************'+tid);
       //insert newdtp;
     
   
    }
    insert newdtp;
    return null;
    }
   
    }


Regards,
Satakshi
Hello,

I am inserting some records when i click on custom button. Button is on parent object. I am creating child records of that parent object. I want to show all this records on visualforce page. I have written the code. But nothing is displaing. Can anyone please help me?
VF SHOWDTP


<apex:page standardController="MTP__c"  extensions="showCalender">
<apex:form >
 <apex:pageBlock title="All Dtp">
 <apex:pageblockTable value="{!mydtpList}" var="item">
 <apex:column value="{!item.Name}"/> 
 <apex:column value="{!item.Date__c}"/> 
 <apex:column value="{!item.Visit_type__c}"/> 
 <apex:column value="{!item.Food_Expenses__c}"/> 
</apex:pageblockTable>
 </apex:pageBlock> 
 </apex:form>
</apex:page>


=============================================

Controller

public class showCalender {
    public List<DTP__c> mydtpList {set;get;}
     public  id tid{get;set;}


    public showCalender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 
        getMydtpList();
     }
       public List<DTP__c> getMydtpList(){
      
    
        List<DTP__c> mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where MTP__c=:tid limit 50];

        return mydtpList ;
        }
    //List<DTP__c>  mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];

    }

Regards,
Satakshi
Hello,

I am creating a visualforce page. Where i want to show records. Here MTP is parent object and DTP is child object. I have created code where i am inserting records. I want to show those inserted records on visualforce pages.I have written the code. But records are not displaying.Can anyone please help me with this? 

Controller:
public class showCalender {
    public List<DTP__c> mydtpList {set;get;}
     public  id tid{get;set;}


    public showCalender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 
        getMydtpList();
     }
       public List<DTP__c> getMydtpList(){
      
    
        List<DTP__c> mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where MTP__c=:tid limit 50];

        return mydtpList ;
        }
    //List<DTP__c>  mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];

    }


Visualforce Page:
<apex:page standardController="MTP__c"  extensions="showCalender">
<apex:form >
 <apex:pageBlock title="All Dtp">
 <apex:pageblockTable value="{!mydtpList}" var="item">
 <apex:column value="{!item.Name}"/> 
 <apex:column value="{!item.Date__c}"/> 
 <apex:column value="{!item.Visit_type__c}"/> 
 <apex:column value="{!item.Food_Expenses__c}"/> 
</apex:pageblockTable>
 </apex:pageBlock> 
 </apex:form>
</apex:page>
Hello,

I am writing a code where i have created two formula field which gives me number of days for particular month like this

Formula field= Febrary: To check number of days in febrary
IF( ISPICKVAL( Month__c , 'February') , TEXT(IF( OR((ISPICKVAL(Year__c, '2016')),(ISPICKVAL(Year__c,'2020')), ((ISPICKVAL(Year__c, '2024')))) , 29, 28)), null)

Formula field= NumberOfDays
VALUE( 
CASE(Month__c, 
"January","31",
"March","31", 
"April","30", 
"May","31", 
"June","30", 
"July","31", 
"August","31", 
"September","30", 
"October","31", 
"November","30", 
"December","31",
""))





My query is i am writing a code where i can create records for those particular days of particular month but by my code i am able to create only 30 records. I want that in picklist field if month is jan then it should create 31 records, if month is feb then accordingly leap year it should create 29/28 days. and if month is of 30 days then it should create 30 records. Now with my code i am able to create only 30 records for any month. In debug statement    System.debug('***************dy size******************'+dy); I am getting size 30. Can anyone please help me with this??


Controller:

public with sharing class Calender {
    public List<DTP__c> mydtpList {set;get;}

    public Calender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 

     }

 public Decimal dy;
 public  id tid{get;set;}
    public PageReference createdtp() {
     
        System.debug('***************tid tid*******************'+tid);
        List<MTP__c> obj = [Select  Id, Month__c, Year__c,  February__c, NumberOfDays__c from MTP__c];
 
    for(MTP__c mt:obj)
    {
    if(mt.Month__c=='February')
    {
    String str=mt.February__c;
    dy=Decimal.ValueOf(str);
    }
    else
    {
     Decimal str= mt.NumberOfDays__c;
      dy=str;
    }
    }
  List<DTP__c> newdtp= new List<DTP__c>();
   System.debug('***************dy size******************'+dy);
    for(Integer i = 1; i<=dy; i++)

    {
       DTP__c  dt = new DTP__c();
       dt.MTP__c=tid;
       
       newdtp.add(dt);
       System.debug('****************dtp added********************'+tid);
       //insert newdtp;
     
   
    }
    insert newdtp;
    return null;
    }
        
    public List<DTP__c> getMydtpList(){
    
        List<DTP__c> mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where MTP__c=:tid];

        return mydtpList ;
        }
    //List<DTP__c>  mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];

    }

VF PAge:


<apex:page standardController="MTP__c" extensions="Calender" action="{!createdtp}">
</apex:page>

Thanks & Regards,
Satakshi



 
Hello, 
I am writing code to create calender records. I am facing this error.

Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [MTP]: [MTP]
Error is in expression '{!createdtp}' in component <apex:page> in page createdtp: Class.Calender.createdtp: line 40, column 1
An unexpected error has occurred. Your development organization has been notified.

Can anyone please help me to sort it out. MTP is master detail field

My code is:

Controller:
public with sharing class Calender {

    public Calender(ApexPages.StandardController controller)
     {
          tid = ApexPages.currentPage().getParameters().get('id');
         System.debug('***************dtp added*******************'+tid); 

     }

 public Decimal dy;
 public  id tid{get;set;}
    public PageReference createdtp() {
     
      System.debug('***************tid tid*******************'+tid);
    List<MTP__c> obj = [Select  Id, Month__c, Year__c,  February__c, NumberOfDays__c from MTP__c];
 
    for(MTP__c mt:obj)
    {
    if(mt.Month__c=='February')
    {
    String str=mt.February__c;
    dy=Decimal.ValueOf(str);
    }
    else
    {
     Decimal str= mt.NumberOfDays__c;
      dy=str;
    }
    }
  List<DTP__c> newdtp= new List<DTP__c>();
    for(Integer i = 1; i<=dy; i++)
    {
       DTP__c  dt = new DTP__c();
       dt.MTP__c=tid;
       newdtp.add(dt);
       System.debug('***************dtp added*******************'+tid);
       //insert newdtp;
       
    }
    insert newdtp;
    return null;
    }
        
    public List<DTP__c> getMydtpList(){
mydtpList =[select Name, Expenses__c, MTP__c, Food_Expenses__c, Date__c, Visit_type__c from DTP__c where id=:tid];

    return mydtpList ;
}
    List<DTP__c>  mydtpList = [select Expenses__c, Name, MTP__c, Food_Expenses__c, Visit_type__c from DTP__c where id=:tid];

    }

VF Page:

<apex:page standardController="MTP__c"  extensions="Calender" action="{!createdtp}">
 <apex:pageBlock title="All Dtp">
 <apex:pageblockTable value="{!mydtpList}" var="item">
 <apex:column value="{!item.Name}"/> 
 <apex:column value="{!item.Date__c}"/> 
 <apex:column value="{!item.Visit_type__c}"/> 
 <apex:column value="{!item.Food_Expenses__c}"/> 
</apex:pageblockTable>
 </apex:pageBlock> 
</apex:page>

Thanks & Regards,
Satakshi
Hello,
  I am creating a custom button. On this custom button i want calender. Means suppose I want to create events for september 2016 then i will get rows of days in september 2016. If i want create events for october 2016 then i will get rows of days in oct 2016. How is this possible?egards,
Satakshi