• Jamie 5mith
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Coastal Cloud


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
I have the following trigger:
trigger HelloWorldTrigger on Book__c (before insert) {
    Book__c[] books = Trigger.new;
    MyHelloWorld.applyDiscount(books);
}
which calls the function in the follwoing class:
public class MyHelloWorld {
    public static void applyDiscount(Book__c[] books) {
        for (Book__c b: books) {
            b.Price__c *= 0.9;
        }
    }
}
but when I am running a test script:
@isTest
private class HelloWorldTestClass {
    static testMethod void validateHelloWorld() {
        Book__c b = new Book__c(Name='Behind the Cloud', Price__c=100);
        System.debug('Price before inserting new book: ' + b.Price__c);
        // Insert book
        insert b;
        // Retrieve the new book
        b = [SELECT Price__c FROM Book__c WHERE Id =:b.Id];
        System.debug('Price after trigger fired: ' + b.Price__c);
        // Test that the trigger correctly updated the price
        System.assertEquals(90, b.Price__c);
    }
}
its giving me a 0% code coverage
User-added image

Can anyone please help me with this?
  • December 10, 2015
  • Like
  • 0
Does <apex:pageMessages /> work the same with the VF page is embedded in a standard page?

I've added (inside the form tag)...

<apex:pageMessages />

then from the controller extn - I'm doing a 
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'ERROR message.'));

But I never see the message.  I've verified that the code is executing for the ApexPages.add...

 
I am in need of some serious help here.  I am trying to add the ability to add attachments to a visualforce page before the VF page is saved.  I found the code online but I am getting the following error:  Unknown Property 'Incident_Reports__cStandardController.IncidentReport'.  I have triple checked that the extension is correct, so I'm not sure why this error keeps coming up.

Apex Class:
 
public class IncidentReportAttachment {

    private final Incident_Reports__c IncidentReport;

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

        set;
    }

    public IncidentReportAttachment (ApexPages.StandardController stdController)
    {
        IncidentReport = (Incident_Reports__c)stdController.getRecord();
    }

    public PageReference save() {
        insert IncidentReport;
        attachment.parentId = IncidentReport.Id;
        insert attachment;
      
        PageReference page = ApexPages.currentPage();
        page.setRedirect(true);
        return page;
     }
}

Here is the VF page:
 
<apex:page standardController="Incident_Reports__c" extensions="IncidentReportAttachment">
    <apex:sectionHeader title="Property Incident Reports Edit" subtitle="{!Incident_Reports__c.Name}"/>
    <apex:form >
        
        <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Save & New" action="{!save}" />
                <apex:commandButton value="Cancel" action="{!cancel}"/>
        <apex:pageBlock title="Property Incident Reports Edit" mode="edit" id="thePageBlock">
          <apex:pagemessages />
            
            <apex:pageBlockSection columns="1">
              <apex:outputText value="ATTENTION:  Attorney work product/privileged document (for internal use only).  NOT for Associate Injuries, use Worker's Comp Incident Report." style="font-weight:800"/>
              <apex:outputText value="RED LINES REPRESENT REQUIRED FIELDS" style="color:red"  />
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Property Information" columns="2">
                <apex:inputField value="{!Incident_Reports__c.Property__c}" required="true"/>
                
            </apex:pageBlockSection>
               
            <apex:pageBlockSection title="Claimant Information" columns="2">
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Name__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Gender__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Address__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Age__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Date_of_Birth__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Phone_Number__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Phone_Number_Other__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Claimant_s_Occupation__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Alliance_Associate__c}" required="false"/>
            </apex:pageBlockSection>  
                          
        </apex:pageBlock>
            
       
        
       <apex:pageBlock title="Incident Information" mode="edit" id="Incident">
            
          <apex:actionRegion >
            <apex:pageBlockSection title="Incident Type" columns="1">
              <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Type of Incident"/>
                    <apex:outputPanel >
                      <apex:inputField value="{!Incident_Reports__c.Type_of_Incident__c}" required="TRUE">
                        <apex:actionSupport event="onchange" rerender="Incident" status="IncidentType"/>
                      </apex:inputField>
                      <apex:actionStatus startText="applying value..." id="IncidentType"/>
                    </apex:outputPanel>
                  </apex:pageBlockSectionItem> 
            </apex:pageBlockSection>
          </apex:actionRegion>

          <apex:actionRegion >
            <apex:pageBlockSection title="Incident Information" columns="2">     
                <apex:inputField value="{!Incident_Reports__c.Date_Time_of_Incident__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Date_Time_Incident_Reported__c}" required="false"/> 
                <apex:inputField value="{!Incident_Reports__c.Pictures_Attached__c}" required="false"/>
                <apex:inputField value="{!Incident_Reports__c.Property_Owner_Notified__c}" required="false"/> 
                
                <apex:pageBlockSectionItem helpText="Check this box if Police, Fire or Ambulance were dispatched to the property.">
                    <apex:outputLabel value="Emergency Services Called"/>
                    <apex:outputPanel >
                      <apex:inputField value="{!Incident_Reports__c.Emergency_Services_Required__c}" label="Check if Police, Fire or Ambulance were dispatched to the property.">
                        <apex:actionSupport event="onclick" rerender="Incident" status="status"/>
                      </apex:inputField>
                      <apex:actionStatus startText="applying value..." id="status"/>
                    </apex:outputPanel>
                  </apex:pageBlockSectionItem>  
            </apex:pageBlockSection>
            
          </apex:actionRegion>
          
          <apex:actionRegion >
            <apex:pageBlockSection title="Responding Agencies" id="agencies" columns="2" rendered="{!Incident_Reports__c.Emergency_Services_Required__c == TRUE}">
              
              
              <apex:pageBlockSectionItem >
               
              <apex:outputLabel value="Police Department"/>
              <apex:outputPanel >
                <apex:inputField value="{!Incident_Reports__c.Police_Responded__c}">
                <apex:actionSupport event="onclick" rerender="Incident" status="status1"/>
              </apex:inputField>
              <apex:actionStatus startText="adding Police Department block..." id="status1"/>
              </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem >
               
              <apex:outputLabel value="Fire Department"/>
              <apex:outputPanel >
                <apex:inputField value="{!Incident_Reports__c.Fire_Department_Responded__c}">
                <apex:actionSupport event="onclick" rerender="Incident" status="status2"/>
              </apex:inputField>
              <apex:actionStatus startText="adding Fire Department block..." id="status2"/>
              </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem >
               
              <apex:outputLabel value="Ambulance Service"/>
              <apex:outputPanel >
                <apex:inputField value="{!Incident_Reports__c.Ambulance_Company_Responded__c}">
                <apex:actionSupport event="onclick" rerender="Incident" status="status3"/>
              </apex:inputField>
              <apex:actionStatus startText="adding Ambulance Service block..." id="status3"/>
              </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem >
               
              <apex:outputLabel value="Other Emergency Service"/>
              <apex:outputPanel >
                <apex:inputField value="{!Incident_Reports__c.Other_Department_Responded__c}">
                <apex:actionSupport event="onclick" rerender="Incident" status="status4"/>
              </apex:inputField>
              <apex:actionStatus startText="adding Other Emergency Service block..." id="status4"/>
              </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
            </apex:pageBlockSection>
          </apex:actionRegion>
            
            <apex:pageBlockSection title="Police Department Information" id="police" columns="2" rendered="{!Incident_Reports__c.Police_Responded__c == TRUE}">
                <apex:inputField value="{!Incident_Reports__c.Police_Department_Name__c}" label="Police Department Name"/>
                <apex:inputField value="{!Incident_Reports__c.Police_Report_Number__c}" label="Police Report Number"/>
                
                                
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Fire Department Information" columns="2" rendered="{!Incident_Reports__c.Fire_Department_Responded__c == TRUE}">
                <apex:inputField value="{!Incident_Reports__c.Fire_Department_Name__c}" label="Fire Department Name"/>
                <apex:inputField value="{!Incident_Reports__c.Fire_Dept_Report_Number__c}" label="Fire Dept. Report Number"/>
                
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Ambulance Information" columns="2" rendered="{!Incident_Reports__c.Ambulance_Company_Responded__c == TRUE}">
                <apex:inputField value="{!Incident_Reports__c.Ambulance_Company_Name__c}" label="Ambulance Company Name"/>
                <apex:inputField value="{!Incident_Reports__c.Ambulance_Company_Report_Number__c}" label="Ambulance Co. Report Number"/>
                
                <apex:inputField value="{!Incident_Reports__c.Hospital_Name__c}" label="Hospital Taken To (if applicable)"/>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Other Emergency Services" columns="2" rendered="{!Incident_Reports__c.Other_Department_Responded__c == TRUE}">
                <apex:inputField value="{!Incident_Reports__c.Other_Respondant__c}" label="Other Department Name"/>
                <apex:inputField value="{!Incident_Reports__c.Other_Report_Number__c}" label="Other Department Report Number"/>
                
            </apex:pageBlockSection>
            
            <apex:pageBlockSection title="Moisture / Flooding" columns="3" rendered="{!Incident_Reports__c.Type_of_Incident__c == 'Flood/Moisture'}" id="FloodingSection">
                <apex:inputTextarea value="{!Incident_Reports__c.Affected_Area__c}" label="Describe Affected Area" cols="40" rows="8"/>
                <apex:inputTextarea value="{!Incident_Reports__c.Source_Cause_of_Moisture__c}" label="Describe Cause of Moisture" cols="40" rows="8"/>
                <apex:inputTextarea value="{!Incident_Reports__c.Personal_Property_Damage__c}" label="Detail Damage to Personal Property" cols="40" rows="8"/>
                <apex:inputField value="{!Incident_Reports__c.Date_Notification_Letter_Sent__c}" label="Date Notification Letter Sent"/>
                <apex:inputField value="{!Incident_Reports__c.Date_Option_Letter_Given__c}" label="Date Option Letter Given"/>
                <apex:inputField value="{!Incident_Reports__c.Date_Option_Letter_Received__c}" label="Date Option Letter Received"/>
                <apex:inputField value="{!Incident_Reports__c.Follow_Up_Call_Completed__c}" label="Date Follow-up Call Completed"/>
                <apex:inputField value="{!Incident_Reports__c.Follow_Up_Call_Associate__c}" label="Name of Associate Conducting Call"/>
                <apex:inputTextarea value="{!Incident_Reports__c.Result_of_Conversation__c}" label="Result of Conversation" cols="40" rows="8"/>
            </apex:pageBlockSection>
           
        </apex:pageBlock>
           
        <apex:pageBlock title="Add Attachments">
          	<apex:pageBlockSection>
                <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/>
          </apex:pageBlockSection>
            <apex:repeat value="{!IncidentReport.attachments}" var="attachment">
                <apex:image height="200px" value="{!URLFOR($Action.Attachment.Download, attachment.Id)}"/><p/>
                
            </apex:repeat>
           
        </apex:pageBlock>

           
        
        
    </apex:form>
    
    
     
</apex:page>
I'm at a loss as to why I keep getting this error.  Any help you can provide will be greatly appreciated.

Thanks,

Matt
 

Is there anything like function "ListFind" in apex.

 

such that  ListFind(a,b) returns true or false depending on if  an element "b" is there in list "a" or not.

To test a visualforce page, we pass the record id to the page, as in,

 

https://c.na9.visual.force.com/apex/pages/AccountRecord?id=a00E0000002RzBR

 

I want to dynamically pass the record id so I created a class, however it's giving an error, can someone please help me correct my code. 

 

Visualforce Page

<apex:page standardController="Position__c" showHeader="false" >

<apex:form>
<apex:pageBlock >
    <apex:pageBlockSection >
    
    <apex:sectionHeader title="New Position Details" /> 
    </apex:pageBlockSection > <br/>
    
    <b>  &nbsp;&nbsp;
         <apex:OutputLabel value="Your approval has been requested for the following New Position."> 
         </apex:OutputLabel>
    </b>
      
   <br/> <br/>
    &nbsp;&nbsp;
    Position Record: {!Position__c.Name} <br/><br/>
   
    &nbsp;&nbsp;
    Status: {!Position__c.Status__c} <br/><br/>
   
    &nbsp;&nbsp;
    Location: {!Position__c.Location__c}<br/><br/>
    
    &nbsp;&nbsp;
    Functional Area: {!Position__c.Functional_Area__c}<br/><br/>
    
    &nbsp;&nbsp;
    Job Level: {!Position__c.Job_Level__c}<br/><br/>
    
    &nbsp;&nbsp;
    Minimum Salary: {!Position__c.Min_Pay__c}
    Maximum Salary: {!Position__c.Max_Pay__c}
    
    <br/><br/><br/><br/><br/><br/>
    
    &nbsp;&nbsp;&nbsp;
    
    <apex:OutputLabel value="Please Click the appropriate button below to approve or reject the request."> 
    </apex:OutputLabel> <br/><br/>
    
    &nbsp;&nbsp;&nbsp;
           
    <apex:commandButton action="{!saveAndReject}" styleClass="buttonStyle" style="vertical-align:left;width:80px;height:20px;background:green;" value="Approve" />        
    
    <apex:commandButton action="{!saveAndReject}" styleClass="buttonStyle" style="vertical-align:left;width:80px;height:20px;background:red;" value="Reject" />
              
    <br/><br/> 
   
</apex:pageBlock>
</apex:form>
</apex:page>

 extension controller

public class JobApp {

public Id posId       {get;set;}
private final Position__c pos;
public JobApp(ApexPages.StandardController controller)

{

 posId = controller.getRecord().Id;  
 
}
public PageReference saveAndReject() {

PageReference requestPage = Page.AccountRecord;
requestPage.getParameters().put(posId, Position__c.Id);
requestPage.setRedirect(true);
return requestPage;

}

}

 The above class gives an error -

 

 Error: Compile Error: Incompatible value type Schema.SObjectField for MAP<String,String> at line 15 column 29