• CaroReinecke
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
First let me begin by stating that I am a beginner. Apex is the first language I have tried to learn, and I have only been trying for a few months.

I am trying to create a controller class for a page that allows the user to create records of packages that were sent via mail. When creating a new mail package the user will need to be able to select from the multiple contracts that could be included in the package. I want to override the save button so that when a new package is saved the files that are included in the package are automatically created in a Mailed Package File object. I know that my save button is working because it works if I do not select any files for the package. However, if I try to select one or more files I receive the error "Conversion Error Setting Values."  This confuses me because I thought I was working with IDs. I tried to convert the data type to string but received the same error. Any help would be much appreciated
Code:
public class Mailed_Package_Controller {
 
 public Mailed_Package_Controller(ApexPages.StandardController Controller){
  this.MP = (MailedPackage__c)controller.getRecord();
 }
  
 
 public MailedPackage__c MP;
 
 public List<ID> selectedFiles {get;set;}
 
 public List<SelectOption> getFileOptions(){
  List<SelectOption> Filefeed = new List<SelectOption>();
  File__c[] A = [select ID, Name from File__c Order By LastModifiedDate];
  for (File__c f : A){
   Filefeed.add(new SelectOption (f.ID, f.Name));
  }  
  return Filefeed;
  }
 
   
 /* next you need a save method that overrides the default save method
 it needs to create the Mailer Package
 retrieve the id of the mailer package 
 then iterate through the list of selected file IDs
 and for each file ID create a !!! mailed Package File record !!!
 where the package ID is that of the mailer package
 and the file ID is the current ID in the list of selected file IDs
 */
   
  
 public List<MailedPackageFile__c> MPFs = new List <MailedPackageFile__c>();
 
 public void newMPF(){
  MailedPackageFile__c MPF = new MailedPackageFile__c();
  for (ID c : selectedFiles){
   MPF.File__c = c;
   MPF.MailedPackage__c = this.MP.Id;
   MPFs.add(MPF);
  }
 }
   
 public PageReference save(){
  try { 
   insert this.MP;
  } catch (Exception e){}
   
  newMPF();
  insert MPFs;
  PageReference MPpage = new PageReference('/'+MP.ID);
  MPpage.setRedirect(true);
  return MPpage; 
    
 }
 
 
}

 

  • October 02, 2008
  • Like
  • 0
First let me begin by stating that I am a beginner. Apex is the first language I have tried to learn, and I have only been trying for a few months.

I am trying to create a controller class for a page that allows the user to create records of packages that were sent via mail. When creating a new mail package the user will need to be able to select from the multiple contracts that could be included in the package. I want to override the save button so that when a new package is saved the files that are included in the package are automatically created in a Mailed Package File object. I know that my save button is working because it works if I do not select any files for the package. However, if I try to select one or more files I receive the error "Conversion Error Setting Values."  This confuses me because I thought I was working with IDs. I tried to convert the data type to string but received the same error. Any help would be much appreciated
Code:
public class Mailed_Package_Controller {
 
 public Mailed_Package_Controller(ApexPages.StandardController Controller){
  this.MP = (MailedPackage__c)controller.getRecord();
 }
  
 
 public MailedPackage__c MP;
 
 public List<ID> selectedFiles {get;set;}
 
 public List<SelectOption> getFileOptions(){
  List<SelectOption> Filefeed = new List<SelectOption>();
  File__c[] A = [select ID, Name from File__c Order By LastModifiedDate];
  for (File__c f : A){
   Filefeed.add(new SelectOption (f.ID, f.Name));
  }  
  return Filefeed;
  }
 
   
 /* next you need a save method that overrides the default save method
 it needs to create the Mailer Package
 retrieve the id of the mailer package 
 then iterate through the list of selected file IDs
 and for each file ID create a !!! mailed Package File record !!!
 where the package ID is that of the mailer package
 and the file ID is the current ID in the list of selected file IDs
 */
   
  
 public List<MailedPackageFile__c> MPFs = new List <MailedPackageFile__c>();
 
 public void newMPF(){
  MailedPackageFile__c MPF = new MailedPackageFile__c();
  for (ID c : selectedFiles){
   MPF.File__c = c;
   MPF.MailedPackage__c = this.MP.Id;
   MPFs.add(MPF);
  }
 }
   
 public PageReference save(){
  try { 
   insert this.MP;
  } catch (Exception e){}
   
  newMPF();
  insert MPFs;
  PageReference MPpage = new PageReference('/'+MP.ID);
  MPpage.setRedirect(true);
  return MPpage; 
    
 }
 
 
}

 

  • October 02, 2008
  • Like
  • 0