• m3umax
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

I want to implement a use case like this:

 

1. System allows a user to send an email to a client. User is prompted for a to: address, subject and body text.

2. There is an input file field and a button labelled "Upload" which allows a user to browse for a file to upload which will be attached to the email. The user is allows to repeat this step multiple times to upload multiple attachments.

3. Each time a file is uploaded, the page is refreshed and a table at the bottom of the screen lists the file names of all the files uploaded so far.

4. User can click on the file names of the uploaded files shown in the table. A new window opens with a preview of the uploaded file

5. The user can finally click the "Send" button on the form which will send the email along with all attachments uploaded.

6. The user can close the send email window at any time. If they do so, any files uploaded during the session are deleted from memory.

 

Is something like this even possible? I have been doing a lot of research on using the messaging.singleemailmessage class and can't find any examples remotely like what I want to achieve.

 

I can't get my head around where the uploaded attachments would be stored temporarily which the user is composing the email.

 

According to what I read, an attachment must have a "Parent ID". Thus, if I coded it to put the attachments uploaded against my custom object, what happens if the user aborts the email send operation? The files will still exist against the object. How would I get the system to automatically delete the files if the user aborts?

  • March 21, 2012
  • Like
  • 0

Hi all,

 

I'm just starting Apex coding to try and get some custom functionality. I created a custom object called Settings__c in which I want to hold user configurable settings. There should only ever be one record there. I'm making a custom VF page to allow users to modify the settings.

 

I want my custom VF page to display the current settings. If a settings record does not exist, I want the code to insert a new record and populate it with the values from the form. If an existing record exists I want the form to  update the settings.

 

The problem is that the command button doesn't seem to do anything. I deleted all the records from my custom object so my understanding of the code I have written is that it should execute the insert statement resulting in a new record. But when I check, no record is created. I don't know why, can anyone tell me what the coding error is?

 

Controller code:

 

 

public class Settings {

  //Settings variables
  public String URL {get; set;}
  public ID SettingID{get; set;}
  
  //Constructor
  public Settings() {
    
    //Return list of settings
    list<Settings__c> settings = [select ID,URL__c from Settings__c limit 1];
    
    //Check for existing settings record
    if (!settings.isempty()) {
      //If one exists, loop through and assign settings variables
      for (Settings__c a : settings) {
        SettingID = a.ID;
        URL = a.URL__c;
      }
    }
  }
  
  //Save settings
  public void save() {

    //Check for existing settings record indicated by presence of SettingID
    if (SettingID == null) {
      //Create a new record
      Settings__c newSettings = new Settings__c(URL__c = URL);
        
        try {
            Insert newSettings;
        } catch (DMLException e) {
            newSettings.addError('There was a problem adding the settings. The error message returned is: ' + e.getMessage());
        }
    } else {
      //Update the existing settings record
      Settings__c updateSettings = new Settings__c(URL__c = URL);
        
        try {
            update updateSettings;
        } catch (DMLException e) {
            updateSettings.addError('There was a problem updating the settings. The error message returned is: ' + e.getMessage());
        }
    }
  }
}

 VF page code

 

 

<apex:page controller="Settings">
<apex:form >
  <apex:outputlabel value="URL"/>
  <apex:inputtext value="{!URL}"/>
  <apex:outputlabel value="Default Status"/>
  <apex:inputtext value="{!DefaultStatus}"/>
  <apex:inputText value="{!SettingID}"/>
  <apex:commandButton action="{!save}" value="Save Settings"/>
</apex:form>    
</apex:page>

 

 

 

  • April 27, 2011
  • Like
  • 0

I want to implement a use case like this:

 

1. System allows a user to send an email to a client. User is prompted for a to: address, subject and body text.

2. There is an input file field and a button labelled "Upload" which allows a user to browse for a file to upload which will be attached to the email. The user is allows to repeat this step multiple times to upload multiple attachments.

3. Each time a file is uploaded, the page is refreshed and a table at the bottom of the screen lists the file names of all the files uploaded so far.

4. User can click on the file names of the uploaded files shown in the table. A new window opens with a preview of the uploaded file

5. The user can finally click the "Send" button on the form which will send the email along with all attachments uploaded.

6. The user can close the send email window at any time. If they do so, any files uploaded during the session are deleted from memory.

 

Is something like this even possible? I have been doing a lot of research on using the messaging.singleemailmessage class and can't find any examples remotely like what I want to achieve.

 

I can't get my head around where the uploaded attachments would be stored temporarily which the user is composing the email.

 

According to what I read, an attachment must have a "Parent ID". Thus, if I coded it to put the attachments uploaded against my custom object, what happens if the user aborts the email send operation? The files will still exist against the object. How would I get the system to automatically delete the files if the user aborts?

  • March 21, 2012
  • Like
  • 0

Hi all,

 

I'm just starting Apex coding to try and get some custom functionality. I created a custom object called Settings__c in which I want to hold user configurable settings. There should only ever be one record there. I'm making a custom VF page to allow users to modify the settings.

 

I want my custom VF page to display the current settings. If a settings record does not exist, I want the code to insert a new record and populate it with the values from the form. If an existing record exists I want the form to  update the settings.

 

The problem is that the command button doesn't seem to do anything. I deleted all the records from my custom object so my understanding of the code I have written is that it should execute the insert statement resulting in a new record. But when I check, no record is created. I don't know why, can anyone tell me what the coding error is?

 

Controller code:

 

 

public class Settings {

  //Settings variables
  public String URL {get; set;}
  public ID SettingID{get; set;}
  
  //Constructor
  public Settings() {
    
    //Return list of settings
    list<Settings__c> settings = [select ID,URL__c from Settings__c limit 1];
    
    //Check for existing settings record
    if (!settings.isempty()) {
      //If one exists, loop through and assign settings variables
      for (Settings__c a : settings) {
        SettingID = a.ID;
        URL = a.URL__c;
      }
    }
  }
  
  //Save settings
  public void save() {

    //Check for existing settings record indicated by presence of SettingID
    if (SettingID == null) {
      //Create a new record
      Settings__c newSettings = new Settings__c(URL__c = URL);
        
        try {
            Insert newSettings;
        } catch (DMLException e) {
            newSettings.addError('There was a problem adding the settings. The error message returned is: ' + e.getMessage());
        }
    } else {
      //Update the existing settings record
      Settings__c updateSettings = new Settings__c(URL__c = URL);
        
        try {
            update updateSettings;
        } catch (DMLException e) {
            updateSettings.addError('There was a problem updating the settings. The error message returned is: ' + e.getMessage());
        }
    }
  }
}

 VF page code

 

 

<apex:page controller="Settings">
<apex:form >
  <apex:outputlabel value="URL"/>
  <apex:inputtext value="{!URL}"/>
  <apex:outputlabel value="Default Status"/>
  <apex:inputtext value="{!DefaultStatus}"/>
  <apex:inputText value="{!SettingID}"/>
  <apex:commandButton action="{!save}" value="Save Settings"/>
</apex:form>    
</apex:page>

 

 

 

  • April 27, 2011
  • Like
  • 0