1

Hi I have created a Request form that would get inserted in a Custom object in salesforce. by submitting the form an email would trigger with the request form Number to the customer, However I could not get the record number dynamically.

Please find the Controller Class for the Form:

public without sharing class DevelopmentRequestFormController {

public Attachment myfile { get; set; }
public Attachment attachment {
    get {
        if (attachment == null)
            attachment = new Attachment();
        return attachment;
    }
    set;
}

public  Peoplenet_Request_Form__c prf {get;set;}
public String parentId {get;set;} 
public string Name {get;set;}
public string Problem {get;set;}
public string BenefittoOrganization {get;set;} 
public string ChangeImpact{get;set;}
public string Enhancedreportname {get;set;}
public string ProposedChange {get;set;}
public string TimeSensitivity {get;set;}
public string Title{get;set;}
public Date RequestDate {get;set;}
public string ContactNumber {get;set;}
public string EmailAddress {get;set;}
public String mail_attach_yes_no;
public List<Peoplenet_Request_Form__c>  RequestFormsList {get;set;}     


public DevelopmentRequestFormController () {
    myfile = new Attachment();
    Name = '';
    Problem = '';
    BenefittoOrganization = '';
    ChangeImpact = '';
    Enhancedreportname = '';
    ProposedChange = '';
    TimeSensitivity = '';
    Title = '';
    ContactNumber = '';
    EmailAddress = '';
    prf = new Peoplenet_Request_Form__c();      
}
public void emailTrigger(List<Peoplenet_Request_Form__c> RequestForms, String Names, String Name)
{


}
public pagereference submit(){

    string attachmentName = '';

    boolean isValid = true;
    if(Name == null || Name.trim().length()==0)
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill your Name'));
        isValid = false;
    }
    if(Title == null || Title.trim().length()==0)
    {
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill your Title'));
        isValid = false; 
    }
    if(ContactNumber == null || ContactNumber.trim().length()==0)
    {
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please enter your contact number'));
        isValid = false;  
    }
    if(ProposedChange == null || ProposedChange.trim().length()==0)
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill the proposed change'));
        isValid = false;
    }
    if(Enhancedreportname == null || Enhancedreportname.trim().length()==0)
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill the enhanced report name'));
        isValid = false;
    }
    if(BenefittoOrganization == null || BenefittoOrganization.trim().length()==0)
    {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill the benefit to organization'));
        isValid = false;  
    }
    if(Problem == null || Problem.trim().length()==0)
    {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill the Describe the problems that exist because this solution is not in place'));
        isValid = false;  
    }
    if(ChangeImpact == null || ChangeImpact.trim().length()==0)
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill Who in the organization will this change impact'));
        isValid = false;
    }
    if(TimeSensitivity == null || TimeSensitivity.trim().length()==0)
    {
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please fill time sensitivity related to this request'));
        isValid = false;
    }
    if(isValid==false) 
    return null;
    try{
        Id CID = '001E0000011YjVbIAK';
        List<Account> accs = [select Id,name from Account where Id =: CID];
        prf.Name__c = Name;
        prf.Title__c = Title;
        prf.Contact_Number__c = ContactNumber;
        prf.Email__c = EmailAddress;
        prf.Request_Date__c = RequestDate;
        prf.Proposed_Change__c = ProposedChange;
        prf.Enhanced_report_name__c = Enhancedreportname;
        prf.Benefit_to_Organization__c = BenefittoOrganization;
        prf.Problem__c = Problem;
        prf.Change_Impact__c = ChangeImpact;
        prf.Time_Sensitivity__c = TimeSensitivity;


        try{                
            if(accs!=null && !accs.isEmpty())
                prf.Account__c = accs.get(0).Id;
            insert prf;
             }catch(Exception e1){}
        try{
            if(attachment!=null && attachment.Name!=null){   
                attachment.IsPrivate = true;                                                        
                attachment.ParentId = prf.Id;
                mail_attach_yes_no =  'Yes';
                insert attachment;
                attachment =null;
            }
            else
                mail_attach_yes_no =  'No';
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Thanks for submitting your request!'));                
        }
        catch (DMLException e) {   
            attachment = new Attachment();
            System.debug('Attachment issue: ' + e.getMessage() + ' : ' + e.getLineNumber());                                       
        } 
        try{      
string Names ='';

List<Peoplenet_Request_Form__c> RequestForms = [select Id, Name from Peoplenet_Request_Form__c where Name = :Names];
        if(RequestForms!=null && !RequestForms.isEmpty())
            for(Peoplenet_Request_Form__c reqform : RequestForms)
            Names = reqform.Name;

        String toEmail = EmailAddress;
    System.debug('toEmailtoEmail : ' + toEmail);
    String bot_firstLine = 'Dear ' + Name +','; 
    String succMes = 'Your request has been submitted and case # '+ Names +'  has been created.';
    String bot_firstLine_1 = succMes + Names;
    String bot_secondLine= 'Our goal is to respond within five (5) business days (excluding weekends and holidays).';
    String bot_thirdLine= 'If you have any additional questions and concerns, please feel free to contact Peoplenet Support at 800-669-9765.';
    String bot_fifthLine  = 'Thank you,';
     String bot_sixthLine = 'Peoplenet Account Management”';
    String space = '<br>';

    String paraStart = '<html><body><div><p>';
    String paraEnd = '</p></div></body></html>';

    String bot =paraStart + bot_firstLine + space + space + bot_firstLine_1+ space + space + bot_secondLine + space + bot_thirdLine + space +space+ bot_fifthLine + space +space + bot_sixthLine + space +space + paraEnd;
    if(toEmail!=null){
            Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
            String[] sendingTo = new String[]{toEmail};
                semail.setToAddresses(sendingTo);
            semail.setSubject('Peoplenet Development Request '+ Names +' Confirmation');
            semail.setHtmlBody(bot);
             Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
        }
        }catch(exception e){

            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage() ));
    }
        prf = new Peoplenet_Request_Form__c();
        Name = '';
    Problem = '';
    BenefittoOrganization = '';
    ChangeImpact = '';
    Enhancedreportname = '';
    ProposedChange = '';
    TimeSensitivity = '';
    Title = '';
    ContactNumber = '';
    EmailAddress = '';
        return null;
    }
    catch (Exception ex) {
        system.debug('exception');
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, ex.getMessage() ));
        return null;

    }
}

}

And Also the Date field is showing null in the salesforce Record detail page. I is not getting inserted even if I fill the Date field in the Form.

VF Page:

    <apex:page docType="html-5.0" controller="DevelopmentRequestFormController" showHeader="false" showChat="false" sidebar="false"  cache="true">
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />  
        <apex:stylesheet value="{!URLFOR($Resource.OnlineOrderFormCss, 'OnlineOrderForm.css')}" />
    <apex:include pageName="PeoplenetHeader"/> 
    <apex:includeScript value="{!URLFOR($Resource.OnlineOrderFormScript, 'OnlineOrderFormScript.js')}"/>
    <script>
    function validateEmail(emailField){
        var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

        if (reg.test(emailField.value) == false) 
        {
            alert('Invalid Email Address');
            return false;
        }

        return true;

}
    </script>

    <style type="text/css">
        .detailList .helpOrb {
        position: absolute;
        left: -20px!important;
        right: inherit!important;        
        }
         .btnblue{
            margin-bottom:0px!important;

        } 

        .btnred{
            margin-bottom:0px!important;

        } 
    </style> 
    <div class="pbSubheader brandTertiaryBgr first tertiaryPalette" style="font-size: 1.3em;"><span class="pbSubExtra">                
        </span>
        <h1>Peoplenet Customization Request Form</h1>
    </div>
    <div style="width:90%;padding: 5px 20px;">   
        <p style="font-size:16px">
            Peoplenet understands that our partners and clients have diverse business needs. While our standard offerings suit the needs of most, some products may require a degree of customization. Customization may be completed by Peoplenet after a Customization Request is submitted through Account Management. We will review and prioritize your customization, determine any applicable fees, capture your approval, and complete development. Report Customization starts at $500 per report. Customization to non-report functions is also available. Customization fees will vary depending on the nature of the enhancement and the amount of work required to complete. To start Peoplenet Customization, complete the following form and click submit. Please remember to include as much detail as possible. A member from the Account Management team will respond to your request to discuss next steps.           
        </p>
    </div>
    <apex:form >             
        <div class="pbSubheader brandTertiaryBgr first tertiaryPalette" style="font-size: 1.3em;">
            <span class="pbSubExtra"> </span>        
        </div> 
        <apex:pageBlock title="" id="requestForm">
            <apex:outputPanel >
                <apex:pageMessages ></apex:pageMessages>
            </apex:outputPanel>
            <apex:pageBlockSection title="Development Request Form" id="devrequestform" columns="2">
                <apex:actionRegion >
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;" >
                                <apex:outputLabel value="Name" for="Name"/> 
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputText value="{!Name}" styleClass="form-control" required="true" label="Name" id="name">   
                                </apex:inputText>                               
                            </td>
                        </tr>
                    </table>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                  <apex:outputLabel value="Title" for="Title"/>
                                </td> 
                            <td style="padding-left: 10px;">
                               <apex:inputText value="{!Title}" styleClass="form-control" required="true" label="Title" id="title"/>                                                                                                                                                                                                                                                                                                    
                            </td>
                        </tr>
                    </table>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Contact Number" for="ContactNumber"/>  
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputText value="{!ContactNumber}" styleClass="form-control" required="true" label="Contact Number" html-placeholder="(XXX) XXX-XXXX" id="cntctnum" onkeypress="validatePhone(event, '{!$Component.tphone}');" maxlength="14"/>
                            </td>
                            </tr>
                    </table>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Email Address" for="EmailAddress"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputText value="{!EmailAddress}" styleClass="form-control" required="true" label="Email Address" id="email" onchange="validateEmail(this);"/>
                            </td>
                        </tr>
                    </table>
                    <apex:actionRegion renderRegionOnly="false">
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Request Date" for="RequestDate"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputField value="{!prf.Request_Date__c}" styleClass="form-control" required="true" label="Request Date" id="reqdate"/>
                            </td>      
                        </tr>
                    </table>
                    </apex:actionRegion>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Describe the proposed change" for="ProposedChange"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputTextarea value="{!ProposedChange}" styleClass="form-control" required="true" label="Describe the proposed change" id="propchng"/>
                            </td>
                        </tr>
                    </table>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="If an existing report is being enhanced, what is the report name?" for="Enhancedreportname"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputText value="{!Enhancedreportname}" styleClass="form-control" required="true" label="If an existing report is being enhanced, what is the report name?" id="encreport" />
                            </td>
                        </tr>
                    </table>
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Describe the benefit to your organization" for="BenefittoOrganization" />
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputTextarea value="{!BenefittoOrganization}" styleClass="form-control" required="true" label="Describe the benefit to your organization" id="bentoorg"/>
                            </td>
                        </tr>
                    </table>
                    <apex:outputPanel >
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Describe the problems that exist because this solution is not in place" for="Problem"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputTextarea value="{!Problem}" styleClass="form-control" required="true" label="Describe the problems that exist because this solution is not in place" id="prob"/>
                            </td>
                        </tr>
                    </table>
                    </apex:outputPanel>
                    <apex:outputPanel >
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Who in the organization will this change impact?" for="ChangeImpact"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputText value="{!ChangeImpact}" styleClass="from-control"  required="true" label="Who in the organization will this change impact?" id="chngimpct"/>
                            </td>
                        </tr>
                    </table>
                    </apex:outputPanel>
                    <apex:outputPanel >
                    <table style="width:100%;">
                        <tr>
                            <td style="text-align:right;width:35%;font-weight:bold;font-size:11px;color: #4a4a56;padding-right: 2px;">
                                <apex:outputLabel value="Provide information if there is time sensitivity related to this request" for="TimeSensitivity"/>
                            </td>
                            <td style="padding-left: 10px;">
                                <apex:inputTextarea value="{!TimeSensitivity}" styleClass="form-control" required="true" label="Provide information if there is time sensitivity related to this request" id="timesenst"/>                                                                                                                                                                               
                            </td>
                        </tr>
                    </table>
                    </apex:outputPanel>
                    <apex:actionRegion renderRegionOnly="false">
                    <table>
                            <tr>
                                <td><apex:inputFile value="{!attachment.body}" filename="{!attachment.name}" id="file"  styleclass="form-control" styleClass="btnblue" /></td>
                                <td><apex:outputLabel value=" Max File Size 5MB"></apex:outputLabel></td>                         
                            </tr>
                        </table>
                        </apex:actionRegion>
                    <apex:actionRegion renderRegionOnly="false">
                    <div align="right" draggable="false" >
                    <apex:commandButton styleClass="btngreen" action="{!submit}"  value="Submit"/>
                    </div> 
                        </apex:actionRegion>
                </apex:actionRegion>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
12
  • Do you need Peoplenet_Request_Form__c prf Id in the Email..If so just do prf[0].Id
    – sfdc
    Sep 2, 2016 at 15:18
  • @sfdc no Iam actually need the record number or Record name in the email like your request number #xxxxx. Sep 2, 2016 at 16:07
  • Just change this query List<Peoplenet_Request_Form__c> RequestForms = [select Id, Name from Peoplenet_Request_Form__c where Id= :prf[0].Id]; ...Then Names = RequestForms[0].Name
    – sfdc
    Sep 2, 2016 at 16:09
  • @sfdc when i used this syntax it throws an error now as "Expression must be a list type: Peoplenet_Request_Form__c" Sep 2, 2016 at 16:13
  • Try this ... List<Peoplenet_Request_Form__c> RequestForms = [select Id, Name from Peoplenet_Request_Form__c where Id= :prf.Id];
    – sfdc
    Sep 2, 2016 at 16:14

1 Answer 1

1

Update with below query in your controller

List<Peoplenet_Request_Form__c> RequestForms = [select Id, Name from Peoplenet_Request_Form__c where Id= :prf.Id];

And remove this line in controller

prf.Request_Date__c = RequestDate;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .