• Jonathan91
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I'm new to SF and trying to write a basic custom case controller that adds an attachment to a case.
I've simplified my apex code below. I'm guessing I need to do 
a.OwnerId = UserInfo.getUserId();
to get the attachment to show up under the user's case list? I would like to see the attachment

when I view a new case under the contact.

I would like to delete an attachment I used for a test but I can't find it.


public class MyCaseController {
    
    public Case c { get; set; }
    public Attachment a { get; set; }
          
    public MyCaseController() {
        c = new Case();
        a = new Attachment();        
    }

public PageReference save() {
        try {
            INSERT c;
            if (a.BodyLength > 0)
            {
                a.ParentId = c.Id;
                INSERT a;
            }
            return new PageReference('/apex/Thanks');
        } catch (Exception e) {
            ApexPages.addMessages(e);
            return null;
        }
}



<apex:page controller="MyCaseController" sidebar="False" showHeader="False">
    <apex:form >
        <apex:pageMessages ></apex:pageMessages><br />
        <apex:commandButton action="{!save}" value="Submit"/><br /><br />
        Issue type:<br />
        <apex:inputfield value="{!c.type}" required="true"/><br />
        Issue priority:<br />
        <apex:inputField value="{!c.priority}"/><br />
        Subject:<br />
        <apex:inputField value="{!c.Subject}" required="true"/><br />
        <apex:inputTextarea value="{!c.description}" rows="20" cols="20" /><br />
        Attachment:<br />
        <apex:inputFile value="{!a.body}" filename="{!a.name}" id="file"/>
    </apex:form>
</apex:page>

I have a site that I we have created that the forgot password link is not working.  When you put in the username and click submit, it just sits there.  The ForgotPassword Confirm page does not display nor does the email get sent.  This is the standard Forgot Password pages and controller that was built when the site was created so they are standard pages. 

 

Any help is greatly appreciated.  This is an urgent project we are trying to roll and it's driving me insane.

 

Code for the page is here. 

 

<apex:page id="Registration" showHeader="false" controller="ForgotPasswordController" title="{!$Label.site.forgot_password}">

<apex:stylesheet value="{!URLFOR($Resource.CP_Site_Resources, 'main.css')}"/>




    <apex:composition template="CPSiteTemplate">


        <apex:define name="body">

            <div id="mainouter">
                
                <div id="maininner" align="center">
                    
                  <apex:form id="theForm" forceSSL="true">
                    <apex:panelGrid columns="2" style="margin-top:1em;">
                      <apex:outputLabel value="{!$Label.site.username}" for="username"/>
                      <apex:inputText required="true" id="username" value="{!username}"/>
                      <apex:commandButton id="submit" value="{!$Label.site.submit}" action="{!forgotPassword}"/>
                    </apex:panelGrid>
                    </apex:form>                  
                   <!-- Closing maininner Div here -->
                </div>
 
            <!-- closing mainouter Div here -->    
            </div>                     
 
 
        </apex:define>


  </apex:composition>





</apex:page>

 

 

 

/**
 * An apex page controller that exposes the site forgot password functionality
 */
public class ForgotPasswordController {
    public String username {get; set;}  
    
 
       
    public ForgotPasswordController() {}
    
    public PageReference forgotPassword() {
        boolean success = Site.forgotPassword(username);
        PageReference pr = Page.ForgotPasswordConfirm;
        pr.setRedirect(true);
        
        system.debug(success);
        
        if (success) {              
            return pr;
        }
        return null;
    }
    
     public static testMethod void testForgotPasswordController() {
        // Instantiate a new controller with all parameters in the page
        ForgotPasswordController controller = new ForgotPasswordController();
        controller.username = 'test@salesforce.com';        
    
        System.assertEquals(controller.forgotPassword(),null); 
    }
}