• Ellsa James
  • NEWBIE
  • 50 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 11
    Replies
I have a picklist with 4 text values. I want to assign a numeric value to each text value. I then want to multiply the chosen value by a number field.  Can anyone help me with the syntax?  

Picklist field = Plan_object__c
Picklist Values = Low,High,Medium,None
Number Field = R_Complex__c 
I have set up an email service and Apex class that handles inbound emails and creates a new task with the details from the email. The task is then related to a custom object based on the subject line of the email matching a custom field on the custom object record. This is working fine at the moment but I need to tweek the criteria the check if the subject of the email contains the value of the custom field. At the moment it is checking if the subject = the field. I need to check if it contains rather than =.

Custom object = Request
Custom field to check against email subject = Test

Here is the Apex class
global class CreateTaskEmailExample1 implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){
 
    // Create an InboundEmailResult object for returning the result of the 
    // Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
  
    String myPlainText= '';
    
    // Add the email plain text into the local variable 
    myPlainText = email.plainTextBody;
   
    // New Task object to be created
    Task[] newTask = new Task[0];
   
    // Try to look up any Request based on the email subject
    
    try {
      Request__c vCon = [SELECT Id, Name, Number__c, Test__c
        FROM Request__c 
        WHERE Test__c =:email.subject
        LIMIT 1];
      
      // Add a new Task to the Request record we just found above.
      newTask.add(new Task(Description =  myPlainText,
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1,
           WhatId =  vCon.Id));
     
     // Insert the new Task 
     insert newTask;    
     
     System.debug('New Task Object: ' + newTask );   
    }
    // If an exception occurs when the query accesses 
    // the Request record, a QueryException is called.
    // The exception is written to the Apex debug log.
   catch (QueryException e) {
       System.debug('Query Issue: ' + e);
   }
   
   // Set the result to true. No need to send an email back to the user 
   // with an error message
   result.success = true;
   
   // Return the result for the Apex Email Service
   return result;
  }
}



 
We are using a custom object (instead of Case object) to handle our requests. I am looking to add the functionality to attach incoming emails to their associated request record similar to the functionality offered by email to case. We will only be attaching to existing records and Not creating new ones.

I believe this can be accomplished via an email service and handler class. I am ok with creating the email service but I need some pointers or code example of what the handler class would look like?

Thank you.
I am trying to create a JFrame for my java project but cannot get the JFrame to display. I am getting a successful build but no JFrame appears. I have only been learning java for a couple of weeks and have written all the code while in class so I don't have a clue whats wrong or what a lot of the code does. The idea is to display a JFrame with some textfields and Combo boxes which will query a database and return a value. Its a program for a restaurant where the waiter will enter a starter,main and desert and the program gets the price of each dish from the database and returns the bill.  Again I am a newbie to java and I don't know if I should have seperate classes that this program is calling or what is wrong so any help or pointers are much appreciated.

My code is below.
 
package restaurantbillcalculator;

// Exercise 26.12: RestaurantBillCalculator.java   
// Calculates a table's bill.   
import java.awt.*;   
import java.awt.event.*;   
import java.sql.*;   
import java.text.*;   
import java.util.*;   
import javax.swing.*;   
   
public class RestaurantBillCalculator extends JFrame   
{   
   // JLabel for Restaurant   
   private JLabel restaurantJLabel;   
   
   // JPanel to display waiter information   
   private JPanel waiterJPanel;   
   
   // JLabel and JTextField for table number   
   private JLabel tableNumberJLabel;   
   private JTextField tableNumberJTextField;   
   
   // JLabel and JTextField for waiter name   
   private JLabel waiterNameJLabel;   
   private JTextField waiterNameJTextField;   
   
   // JPanel to display menu items   
   private JPanel menuItemsJPanel;   
   
   // JLabel and JComboBox for beverage   
   private JLabel beverageJLabel;   
   private JComboBox beverageJComboBox;   
   
   // JLabel and JComboBox for appetizer   
   private JLabel appetizerJLabel;   
   private JComboBox appetizerJComboBox;   
   
   // JLabel and JComboBox for main course   
   private JLabel mainCourseJLabel;   
   private JComboBox mainCourseJComboBox;   
   
   // JLabel and JComboBox for dessert   
   private JLabel dessertJLabel;   
   private JComboBox dessertJComboBox;   
   
   // JButton for calculate bill   
   private JButton calculateBillJButton;   
   
   // JLabel and JTextField for subtotal   
   private JLabel subtotalJLabel;   
   private JTextField subtotalJTextField;   
   
   // JLabel and JTextField for tax   
   private JLabel taxJLabel;   
   private JTextField taxJTextField;   
   
   // JLabel and JTextField for total   
   private JLabel totalJLabel;   
   private JTextField totalJTextField;   
   
   // constant for tax rate   
   private final static double TAX_RATE = 0.05;   
   
   // declare instance variables for database processing   
   private Connection myConnection;   
   private Statement myStatement;   
   private ResultSet myResultSet;   
   
   // declare instance variable ArrayList to hold bill items   
   private ArrayList billItems = new ArrayList();   
   
   // constructor   
   public RestaurantBillCalculator(    
      String databaseDriver, String databaseURL )   
   {   
      createUserInterface(); // set up GUI   
   
   } // end constructor   
   
   // create and position GUI components; register event handlers   
   private void createUserInterface()   
   {   
      // get content pane for attaching GUI components   
      Container contentPane = getContentPane();   
   
      // enable explicit positioning of GUI components    
      contentPane.setLayout( null );   
   
      // set up restaurantJLabel   
      restaurantJLabel = new JLabel();   
      restaurantJLabel.setBounds( 80, 8, 128, 24 );   
      restaurantJLabel.setText( "Restaurant" );   
      restaurantJLabel.setFont(    
         new Font( "SansSerif", Font.BOLD , 16 ) );   
      contentPane.add( restaurantJLabel );   
   
      // set up waiterJPanel   
      createWaiterJPanel();    
      contentPane.add( waiterJPanel );   
   
      // set up menuItemsJPanel   
      createMenuItemsJPanel();   
      contentPane.add( menuItemsJPanel );   
   
      // set up calculateBillJButton   
      calculateBillJButton = new JButton();   
      calculateBillJButton.setBounds( 92, 320, 90, 24 );   
      calculateBillJButton.setText( "Calculate Bill" );   
      calculateBillJButton.setBorder(    
         BorderFactory.createRaisedBevelBorder() );   
      contentPane.add( calculateBillJButton );   
      calculateBillJButton.addActionListener(   
   
         new ActionListener()  // anonymous inner class   
         {   
            // event handler called when calculateBillJButton    
            // is clicked   
            public void actionPerformed( ActionEvent event )    
            {   
               calculateBillJButtonActionPerformed( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addActionListener   
         
      // set up subtotalJLabel   
      subtotalJLabel = new JLabel();   
      subtotalJLabel.setBounds( 28, 360, 56, 16 );   
      subtotalJLabel.setText( "Subtotal:" );   
      contentPane.add( subtotalJLabel );   
   
      // set up subtotalJTextField   
      subtotalJTextField = new JTextField();   
      subtotalJTextField.setBounds( 92, 360, 90, 20 );   
      subtotalJTextField.setEditable( false );   
      subtotalJTextField.setBorder(    
         BorderFactory.createLoweredBevelBorder() );   
      subtotalJTextField.setHorizontalAlignment( JTextField.RIGHT );   
      contentPane.add( subtotalJTextField );   
   
      // set up taxJLabel   
      taxJLabel = new JLabel();   
      taxJLabel.setBounds( 28, 392, 56, 16 );   
      taxJLabel.setText( "Tax:" );   
      contentPane.add( taxJLabel );   
   
      // set up taxJTextField   
      taxJTextField = new JTextField();   
      taxJTextField.setBounds( 92, 392, 90, 20 );   
      taxJTextField.setEditable( false );   
      taxJTextField.setBorder(    
         BorderFactory.createLoweredBevelBorder() );   
      taxJTextField.setHorizontalAlignment( JTextField.RIGHT );   
      contentPane.add( taxJTextField );   
   
      // set up totalJLabel   
      totalJLabel = new JLabel();   
      totalJLabel.setBounds( 28, 424, 56, 16 );   
      totalJLabel.setText( "Total:" );   
      contentPane.add( totalJLabel );   
   
      // set up totalJTextField   
      totalJTextField = new JTextField();   
      totalJTextField.setBounds( 92, 424, 90, 20 );   
      totalJTextField.setEditable( false );   
      totalJTextField.setBorder(    
         BorderFactory.createLoweredBevelBorder() );   
      totalJTextField.setHorizontalAlignment( JTextField.RIGHT );   
      contentPane.add( totalJTextField );   
   
      // set properties of application's window   
      setTitle( "Restaurant Bill Calculator" ); // set window title   
      setSize( 280, 500 ); // set window size   
      setVisible( true );  // display window   
   
      // ensure database connection is closed    
      // when user quits application   
      addWindowListener(   
   
         new WindowAdapter() // anonymous inner class   
         {   
            // event handler called when close button is clicked   
            public void windowClosing( WindowEvent event )   
            {   
               frameWindowClosing( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addWindowListener   
   
   } // end method createUserInterface   
   
   // set up waiterJPanel   
   private void createWaiterJPanel()   
   {   
      // set up waiterJPanel   
      waiterJPanel = new JPanel();   
      waiterJPanel.setBounds( 20, 48, 232, 88 );   
      waiterJPanel.setBorder( BorderFactory.createTitledBorder(    
         BorderFactory.createEtchedBorder(),    
         "Waiter Information" ) );   
      waiterJPanel.setLayout( null );   
   
      // set up tableNumberJLabel   
      tableNumberJLabel = new JLabel();   
      tableNumberJLabel.setBounds( 35, 24, 90, 16 );   
      tableNumberJLabel.setText( "Table number:" );   
      waiterJPanel.add( tableNumberJLabel );   
         
      // set up tableNumberJTextField   
      tableNumberJTextField = new JTextField();   
      tableNumberJTextField.setBounds( 128, 24, 88, 21 );   
      waiterJPanel.add( tableNumberJTextField );   
   
      // set up waiterNameJLabel   
      waiterNameJLabel = new JLabel();   
      waiterNameJLabel.setBounds( 35, 56, 90, 16 );   
      waiterNameJLabel.setText( "Waiter name:" );   
      waiterJPanel.add( waiterNameJLabel );   
   
      // set up waiterNameJTextField   
      waiterNameJTextField = new JTextField();   
      waiterNameJTextField.setBounds( 128, 56, 88, 21 );   
      waiterJPanel.add( waiterNameJTextField );   
   
   } // end method createWaiterJPanel   
   
   // create menuItemsJPanel   
   private void createMenuItemsJPanel()   
   {   
      // set up menuItemsJPanel   
      menuItemsJPanel = new JPanel();   
      menuItemsJPanel.setBounds( 20, 152, 232, 152 );   
      menuItemsJPanel.setBorder( BorderFactory.createTitledBorder(    
         BorderFactory.createEtchedBorder(), "Menu Items" ) );   
      menuItemsJPanel.setLayout( null );   
    
      // set up beverageJLabel   
      beverageJLabel = new JLabel();   
      beverageJLabel.setBounds( 8, 24, 80, 24 );   
      beverageJLabel.setText( "Beverage:" );   
      menuItemsJPanel.add( beverageJLabel );   
   
      // set up beverageJComboBox   
      beverageJComboBox = new JComboBox();   
      beverageJComboBox.setBounds( 88, 24, 128, 25 );   
      menuItemsJPanel.add( beverageJComboBox );   
      beverageJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in beverageJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               beverageJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      // add items to beverageJComboBox   
      beverageJComboBox.addItem( "" );   
      loadCategory( "Beverage", beverageJComboBox );   
   
      // set up appetizerJLabel   
      appetizerJLabel = new JLabel();   
      appetizerJLabel.setBounds( 8, 56, 80, 24 );   
      appetizerJLabel.setText( "Appetizer:" );   
      menuItemsJPanel.add( appetizerJLabel );   
   
      // set up appetizerJComboBox   
      appetizerJComboBox = new JComboBox();   
      appetizerJComboBox.setBounds( 88, 56, 128, 25 );   
      menuItemsJPanel.add( appetizerJComboBox );   
      appetizerJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in appetizerJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               appetizerJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      // add items to appetizerJComboBox   
      appetizerJComboBox.addItem( "" );   
      loadCategory( "Appetizer", appetizerJComboBox );   
   
      // set up mainCourseJLabel   
      mainCourseJLabel = new JLabel();   
      mainCourseJLabel.setText( "Main Course:" );   
      mainCourseJLabel.setBounds( 8, 88, 80, 24 );   
      menuItemsJPanel.add( mainCourseJLabel );   
   
      // set up mainCourseJComboBox   
      mainCourseJComboBox = new JComboBox();   
      mainCourseJComboBox.setBounds( 88, 88, 128, 25 );   
      mainCourseJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in mainCourseJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               mainCourseJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      menuItemsJPanel.add( mainCourseJComboBox );   
   
      // add items to mainCourseJComboBox   
      mainCourseJComboBox.addItem( "" );   
      loadCategory( "Main Course", mainCourseJComboBox );   
   
      // set up dessertJLabel   
      dessertJLabel = new JLabel();   
      dessertJLabel.setBounds( 8, 120, 80, 24 );   
      dessertJLabel.setText( "Dessert:" );   
      menuItemsJPanel.add( dessertJLabel );   
   
      // set up dessertJComboBox   
      dessertJComboBox = new JComboBox();   
      dessertJComboBox.setBounds( 88, 120, 128, 25 );   
      menuItemsJPanel.add( dessertJComboBox );   
      dessertJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in dessertJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               dessertJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      // add items to dessertJComboBox   
      dessertJComboBox.addItem( "" );   
      loadCategory( "Dessert", dessertJComboBox );   
   
   } // end method createMenuItemsJPanel   
   
   // add items to JComboBox   
   private void loadCategory(   
      String category, JComboBox categoryJComboBox )   
   {   
               
   } // end method loadCategory   
   
   // user select beverage   
   private void beverageJComboBoxItemStateChanged( ItemEvent event )   
   {   
         
   } // end method beverageJComboBoxItemStateChanged   
   
   // user select appetizer   
   private void appetizerJComboBoxItemStateChanged( ItemEvent event )   
   {   
         
   } // end method appetizerJComboBoxItemStateChanged   
   
   // user select main course   
   private void mainCourseJComboBoxItemStateChanged(    
      ItemEvent event )   
   {   
         
   } // end method mainCourseJComboBoxItemStateChanged   
   
   // user select dessert   
   private void dessertJComboBoxItemStateChanged( ItemEvent event )   
   {   
         
   } // end method dessertJComboBoxItemStateChanged   
   
   // user click Calculate Bill JButton   
   private void calculateBillJButtonActionPerformed(    
      ActionEvent event )   
   {   
         
   } // end method calculateBillJButtonActionPerformed   
   
   // calculate subtotal   
   private double calculateSubtotal()   
   {   
      return 0;   
   
   } // end method calculateSubtotal   
   
   // user close window   
   private void frameWindowClosing( WindowEvent event )   
   {   
         
   }  // end method frameWindowClosing   
   
   // method main   
   public static void main( String[] args )    
   {   
      // check command-line arguments   
      if ( args.length == 2 )   
      {   
         // get command-line arguments   
         String databaseDriver = args[ 0 ];   
         String databaseURL = args[ 1 ];   
   
         // create new RestaurantBillCalculator   
         RestaurantBillCalculator application =    
            new RestaurantBillCalculator (    
               databaseDriver, databaseURL );   
      }   
      else   
      {   
         System.out.println( "Usage: java " +    
            "RestaurantBillCalculator databaseDriver databaseURL" );   
      }         
   
   } // end method main   
   
} // end class RestaurantBillCalculator

 
I am trying to pull an email address from the standard "Description" field on Cases object. The below formula is correctly pulling everything AFTER the "@" symbol in the email address, (for example "@sample.com").I cannot get it to pull the first part of the email address.

Here is the formula I am using
SUBSTITUTE( Description ,RIGHT(Description, FIND("@",Description))+ LEFT(Description, FIND("@",Description)), NULL)

All help much appreciated.
I am trying to create a validation rule that will prevent users from closing a record with a certain status. Only 2 users should be able to close the records with these statuses.

Object = Custom object called Application for stock
Criteria for the rule = If Type of Request= "Placement", "Demo" or "Consignment" And Status = Closed And user id = "005200000036LQs" OR "00520000003RRW6".

Type of request andstatus are picklist fields.

Current formula

(ISPICKVAL(Type_of_Request__c, "Placement") || 
(ISPICKVAL(Type_of_Request__c, "Demo")|| 
(ISPICKVAL(Type_of_Request__c, "Consignment ")))) 

&& 

ISPICKVAL( Status__c , "Closed") 

&& 

$User.Id <> "005200000036LQs" || $User.Id <> "00520000003RRW6"

At the moment the rule fires on every edit.

 
I have written the below trigger and helper class that adds a partner user to a specific public group when a checkbox is ticked on the contact record.

Trigger
trigger Addtogroup4 on Contact (after insert, after update) {
      
      List<GroupMember> GMlist = new List<GroupMember>();
       Set<String> contactEmails = new Set<String>();
       for(Contact con : Trigger.New) {
          //create a set with the contact email addresses
          contactEmails.add(con.email);
       }
    
       //query for the related users and put them in a map,
       //where the key is the email and the value is the user
       Map<String, User> emailUserMap = new Map<String, User> ();
       for(User aUser : [select id, email from User where email in : contactEmails]){
          emailUserMap.put(aUser.email, aUser);
       }
           system.debug(emailUserMap);
           List<Id> userIdList = new List<Id>();
      for(Contact con : Trigger.New) {
        if(con.Public_Group_Technology_Partner_Content__c == TRUE) {    
              
             userIdList.add(emailUserMap.get(con.email).id);
    
          }
      }  
   
      //dymanically get the get group id.
      Group theGroup = [select id from Group where Name = 'Technology Partner Content'];
      if(null != theGroup){
          //call the contact trigger helper if the group exists. 
          //This method adds the user to the group
          ContactTriggerHelper.addUsersToGroup(theGroup.id,userIdList );
      }
  }

Helper Class
public class ContactTriggerHelper{
       
      //future call to do the group adding.  the future call will spawn a new thread.
      @future
      public static void addUsersToGroup(String groupId, List<Id> userIds){
          List<GroupMember> GMlist = new List<GroupMember>();
          for(ID userId: userIds){
              GroupMember gm = new GroupMember();
              gm.GroupId = groupId;
              gm.UserOrGroupId = userId;
              gmList.add(GM);
          }
      
       
          if(gmList.size() > 0){
              insert gmList;
          }
      }
    
  }

The trigger and class are working fine in sandbox. The problem is I am a newbie to apex and have no Idea how to write the test class for this. I pieced the trigger and clas together with assistance on this forum. Do I need a test class for the class and the trigger? Can anyone advise what it would look like?

Thank you
I am using the below syntax which I have seen posted as a solution but I am getting an error.

IF( INCLUDES(Service_Engineer__c, "Alan Clarkson"), "Alan Clarkson; ","")
&
IF( INCLUDES(Service_Engineer__c, "Alan Eadie"), "Alan Eadie; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Dave Matthews"), "Dave Matthews; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Dean Hunt"), "Dean Hunt; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Paul Beddard"), "Paul Beddard; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Paul Levay"), "Paul Levay; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Richard Hatch"), "Richard Hatch; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Veritek"), "Veritek; ", "")
&
IF( INCLUDES(Service_Engineer__c, "Dave Beswick"), "Dave Beswick; ", "")

The error I am getting is Error: Incorrect parameter type for function 'INCLUDES()'. Expected Picklist, received Text

I am positive the field "Service_Engineer__c" is a multi-Picklist field so i do not know why I am getting this error.

I have written the below trigger which creates a related record when a checkbox is updated. The problem is, it is creating a new record everytime the record is edited since the criteria is being met. Can anyone advise how I can edit my trigger so that it only fires once. (ie.The first time the criteria is met) ?

Trigger
Trigger copyEquipmentonsite on Unit_Placements_Sales__c(after insert, after update)
{
     List<Services__c> sub=new List<Services__c>();
     for(Unit_Placements_Sales__c u : Trigger.new)
     {
           if(u.Service_Month_is_Next_Month__c == TRUE)
           {
                   Services__c s=new Services__c();
                   
                   s.Equipment_Onsite__c=u.ID;
                   s.Equipment_Type__c=u.Equipment__c;
                   s.Machine_Specific_Notes__c=u.Machine_Specific_Notes__c;   
                   s.Product__c=u.The_Product__c;  
                   s.Dell_Tag_Number__c=u.Dell_Tag_Number__c;
                   s.Serial_Number__c=u.Serial_Number__c; 
                   s.XD_Number__c=u.XD_Number__c;
                   
                                                  
                   
                                    
                   sub.add(s);
            }
            if(sub.size()>0)
            insert sub;
     }
}

Thank you
I am using the below code

trigger AddToPG on Contact (after insert, after update) {
    List<GroupMember> GMlist = new List<GroupMember>();
    for(Contact U : Trigger.New) {
        if(U.Add_to_Group__c == TRUE) {
            GroupMember GM = new GroupMember();
            GM.GroupId = '00Gg0000000afKH';
            GM.UserOrGroupId = U.Id;
            GMList.add(GM);        
        }
    }

        insert GMList;
    }

However, this is giving the below error

Error:Apex trigger AddToPG caused an unexpected exception, contact your administrator: AddToPG: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, User/Group ID: id value of incorrect type: 003g000000HfUsiAAF: [UserOrGroupId]: Trigger.AddToPG: line 12, column 1

I think this is because I am trying the set the contact ID where I should be using the User or Group ID. The contacts will be Partner users so they will have a user record. Are there any changes I can make to my trigger which will allow me to do this?
Trigger copyunitdetail on Unit__c(before insert,after insert, after update)
{
     List<Services__c> sub=new List<Services__c>();
     for(Unit__c u : Trigger.new)
     {
           if(u.Service_Date__c == 'THIS MONTH')
           {
                   Services__c s=new Services__c();
                   s.Name=u.Name;
                   s.Covered_By_Manuf_Warranty__c=u.Covered_By_Manuf_Warranty__c;
                   s.Date_for_Call_About_Servces__c=u.Date_for_Call_About_Services__c;
                   s.Dell_Tag_Number__c=u.Dell_Tag_Number__c;
                   s.Dongle_Number__c=u.Dongle_Number__c;
                   s.Equipment_Type__c=u.Equipment_Type__c;
                   s.ID__c=u.ID__c;
                   s.Installed_Date_First__c=u.Installed_Date__c;
                   s.Item_Onsite__c=u.Item_Onsite__c;
                   s.Machine_Specific_Notes__c=u.Machine_Specific_Notes__c;
                   s.Manufacturers_Warranty_End_Date__c=u.Manufacturers_Warranty_End_Date__c;
                   s.NX_Number__c=u.NX_Number__c;
                   s.Onsite_with_Customer__c=u.On_Site_With_Customer__c;
                   s.Product__c=u.Product__c;
                   s.Purchase_Date__c=u.Purchased_Date__c;
                   s.Serial_Number__c=u.Serial_Number__c;
                   s.Service_Date__c=u.Service_Date__c;
                   s.Service_Date_Month__c=u.Service_Date_Month__c;
                   s.Service_Engineer__c=u.Service_Engineer__c;
                   s.Service_Month__c=u.Service_Month__c;
                   s.Service_Month_Text__c=u.Service_Mnth__c;
                   s.Shipped_to_a_Customer__c=u.Shipped_to_a_Customer__c;
                   s.Time_Remaining_on_Manuf_Warranty__c=u.Time_Remaining_on_Manuf_Warranty__c;
                   s.Vendor__c=u.Vendor__c;
                   s.XD_Number__c=u.XD_Number__c;
                  
                
                   sub.add(s);
            }
            if(sub.size()>0)
            insert sub;
     }
}
I have set up an email service and Apex class that handles inbound emails and creates a new task with the details from the email. The task is then related to a custom object based on the subject line of the email matching a custom field on the custom object record. This is working fine at the moment but I need to tweek the criteria the check if the subject of the email contains the value of the custom field. At the moment it is checking if the subject = the field. I need to check if it contains rather than =.

Custom object = Request
Custom field to check against email subject = Test

Here is the Apex class
global class CreateTaskEmailExample1 implements Messaging.InboundEmailHandler {
 
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                       Messaging.InboundEnvelope env){
 
    // Create an InboundEmailResult object for returning the result of the 
    // Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
  
    String myPlainText= '';
    
    // Add the email plain text into the local variable 
    myPlainText = email.plainTextBody;
   
    // New Task object to be created
    Task[] newTask = new Task[0];
   
    // Try to look up any Request based on the email subject
    
    try {
      Request__c vCon = [SELECT Id, Name, Number__c, Test__c
        FROM Request__c 
        WHERE Test__c =:email.subject
        LIMIT 1];
      
      // Add a new Task to the Request record we just found above.
      newTask.add(new Task(Description =  myPlainText,
           Priority = 'Normal',
           Status = 'Inbound Email',
           Subject = email.subject,
           IsReminderSet = true,
           ReminderDateTime = System.now()+1,
           WhatId =  vCon.Id));
     
     // Insert the new Task 
     insert newTask;    
     
     System.debug('New Task Object: ' + newTask );   
    }
    // If an exception occurs when the query accesses 
    // the Request record, a QueryException is called.
    // The exception is written to the Apex debug log.
   catch (QueryException e) {
       System.debug('Query Issue: ' + e);
   }
   
   // Set the result to true. No need to send an email back to the user 
   // with an error message
   result.success = true;
   
   // Return the result for the Apex Email Service
   return result;
  }
}



 
I am trying to create a JFrame for my java project but cannot get the JFrame to display. I am getting a successful build but no JFrame appears. I have only been learning java for a couple of weeks and have written all the code while in class so I don't have a clue whats wrong or what a lot of the code does. The idea is to display a JFrame with some textfields and Combo boxes which will query a database and return a value. Its a program for a restaurant where the waiter will enter a starter,main and desert and the program gets the price of each dish from the database and returns the bill.  Again I am a newbie to java and I don't know if I should have seperate classes that this program is calling or what is wrong so any help or pointers are much appreciated.

My code is below.
 
package restaurantbillcalculator;

// Exercise 26.12: RestaurantBillCalculator.java   
// Calculates a table's bill.   
import java.awt.*;   
import java.awt.event.*;   
import java.sql.*;   
import java.text.*;   
import java.util.*;   
import javax.swing.*;   
   
public class RestaurantBillCalculator extends JFrame   
{   
   // JLabel for Restaurant   
   private JLabel restaurantJLabel;   
   
   // JPanel to display waiter information   
   private JPanel waiterJPanel;   
   
   // JLabel and JTextField for table number   
   private JLabel tableNumberJLabel;   
   private JTextField tableNumberJTextField;   
   
   // JLabel and JTextField for waiter name   
   private JLabel waiterNameJLabel;   
   private JTextField waiterNameJTextField;   
   
   // JPanel to display menu items   
   private JPanel menuItemsJPanel;   
   
   // JLabel and JComboBox for beverage   
   private JLabel beverageJLabel;   
   private JComboBox beverageJComboBox;   
   
   // JLabel and JComboBox for appetizer   
   private JLabel appetizerJLabel;   
   private JComboBox appetizerJComboBox;   
   
   // JLabel and JComboBox for main course   
   private JLabel mainCourseJLabel;   
   private JComboBox mainCourseJComboBox;   
   
   // JLabel and JComboBox for dessert   
   private JLabel dessertJLabel;   
   private JComboBox dessertJComboBox;   
   
   // JButton for calculate bill   
   private JButton calculateBillJButton;   
   
   // JLabel and JTextField for subtotal   
   private JLabel subtotalJLabel;   
   private JTextField subtotalJTextField;   
   
   // JLabel and JTextField for tax   
   private JLabel taxJLabel;   
   private JTextField taxJTextField;   
   
   // JLabel and JTextField for total   
   private JLabel totalJLabel;   
   private JTextField totalJTextField;   
   
   // constant for tax rate   
   private final static double TAX_RATE = 0.05;   
   
   // declare instance variables for database processing   
   private Connection myConnection;   
   private Statement myStatement;   
   private ResultSet myResultSet;   
   
   // declare instance variable ArrayList to hold bill items   
   private ArrayList billItems = new ArrayList();   
   
   // constructor   
   public RestaurantBillCalculator(    
      String databaseDriver, String databaseURL )   
   {   
      createUserInterface(); // set up GUI   
   
   } // end constructor   
   
   // create and position GUI components; register event handlers   
   private void createUserInterface()   
   {   
      // get content pane for attaching GUI components   
      Container contentPane = getContentPane();   
   
      // enable explicit positioning of GUI components    
      contentPane.setLayout( null );   
   
      // set up restaurantJLabel   
      restaurantJLabel = new JLabel();   
      restaurantJLabel.setBounds( 80, 8, 128, 24 );   
      restaurantJLabel.setText( "Restaurant" );   
      restaurantJLabel.setFont(    
         new Font( "SansSerif", Font.BOLD , 16 ) );   
      contentPane.add( restaurantJLabel );   
   
      // set up waiterJPanel   
      createWaiterJPanel();    
      contentPane.add( waiterJPanel );   
   
      // set up menuItemsJPanel   
      createMenuItemsJPanel();   
      contentPane.add( menuItemsJPanel );   
   
      // set up calculateBillJButton   
      calculateBillJButton = new JButton();   
      calculateBillJButton.setBounds( 92, 320, 90, 24 );   
      calculateBillJButton.setText( "Calculate Bill" );   
      calculateBillJButton.setBorder(    
         BorderFactory.createRaisedBevelBorder() );   
      contentPane.add( calculateBillJButton );   
      calculateBillJButton.addActionListener(   
   
         new ActionListener()  // anonymous inner class   
         {   
            // event handler called when calculateBillJButton    
            // is clicked   
            public void actionPerformed( ActionEvent event )    
            {   
               calculateBillJButtonActionPerformed( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addActionListener   
         
      // set up subtotalJLabel   
      subtotalJLabel = new JLabel();   
      subtotalJLabel.setBounds( 28, 360, 56, 16 );   
      subtotalJLabel.setText( "Subtotal:" );   
      contentPane.add( subtotalJLabel );   
   
      // set up subtotalJTextField   
      subtotalJTextField = new JTextField();   
      subtotalJTextField.setBounds( 92, 360, 90, 20 );   
      subtotalJTextField.setEditable( false );   
      subtotalJTextField.setBorder(    
         BorderFactory.createLoweredBevelBorder() );   
      subtotalJTextField.setHorizontalAlignment( JTextField.RIGHT );   
      contentPane.add( subtotalJTextField );   
   
      // set up taxJLabel   
      taxJLabel = new JLabel();   
      taxJLabel.setBounds( 28, 392, 56, 16 );   
      taxJLabel.setText( "Tax:" );   
      contentPane.add( taxJLabel );   
   
      // set up taxJTextField   
      taxJTextField = new JTextField();   
      taxJTextField.setBounds( 92, 392, 90, 20 );   
      taxJTextField.setEditable( false );   
      taxJTextField.setBorder(    
         BorderFactory.createLoweredBevelBorder() );   
      taxJTextField.setHorizontalAlignment( JTextField.RIGHT );   
      contentPane.add( taxJTextField );   
   
      // set up totalJLabel   
      totalJLabel = new JLabel();   
      totalJLabel.setBounds( 28, 424, 56, 16 );   
      totalJLabel.setText( "Total:" );   
      contentPane.add( totalJLabel );   
   
      // set up totalJTextField   
      totalJTextField = new JTextField();   
      totalJTextField.setBounds( 92, 424, 90, 20 );   
      totalJTextField.setEditable( false );   
      totalJTextField.setBorder(    
         BorderFactory.createLoweredBevelBorder() );   
      totalJTextField.setHorizontalAlignment( JTextField.RIGHT );   
      contentPane.add( totalJTextField );   
   
      // set properties of application's window   
      setTitle( "Restaurant Bill Calculator" ); // set window title   
      setSize( 280, 500 ); // set window size   
      setVisible( true );  // display window   
   
      // ensure database connection is closed    
      // when user quits application   
      addWindowListener(   
   
         new WindowAdapter() // anonymous inner class   
         {   
            // event handler called when close button is clicked   
            public void windowClosing( WindowEvent event )   
            {   
               frameWindowClosing( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addWindowListener   
   
   } // end method createUserInterface   
   
   // set up waiterJPanel   
   private void createWaiterJPanel()   
   {   
      // set up waiterJPanel   
      waiterJPanel = new JPanel();   
      waiterJPanel.setBounds( 20, 48, 232, 88 );   
      waiterJPanel.setBorder( BorderFactory.createTitledBorder(    
         BorderFactory.createEtchedBorder(),    
         "Waiter Information" ) );   
      waiterJPanel.setLayout( null );   
   
      // set up tableNumberJLabel   
      tableNumberJLabel = new JLabel();   
      tableNumberJLabel.setBounds( 35, 24, 90, 16 );   
      tableNumberJLabel.setText( "Table number:" );   
      waiterJPanel.add( tableNumberJLabel );   
         
      // set up tableNumberJTextField   
      tableNumberJTextField = new JTextField();   
      tableNumberJTextField.setBounds( 128, 24, 88, 21 );   
      waiterJPanel.add( tableNumberJTextField );   
   
      // set up waiterNameJLabel   
      waiterNameJLabel = new JLabel();   
      waiterNameJLabel.setBounds( 35, 56, 90, 16 );   
      waiterNameJLabel.setText( "Waiter name:" );   
      waiterJPanel.add( waiterNameJLabel );   
   
      // set up waiterNameJTextField   
      waiterNameJTextField = new JTextField();   
      waiterNameJTextField.setBounds( 128, 56, 88, 21 );   
      waiterJPanel.add( waiterNameJTextField );   
   
   } // end method createWaiterJPanel   
   
   // create menuItemsJPanel   
   private void createMenuItemsJPanel()   
   {   
      // set up menuItemsJPanel   
      menuItemsJPanel = new JPanel();   
      menuItemsJPanel.setBounds( 20, 152, 232, 152 );   
      menuItemsJPanel.setBorder( BorderFactory.createTitledBorder(    
         BorderFactory.createEtchedBorder(), "Menu Items" ) );   
      menuItemsJPanel.setLayout( null );   
    
      // set up beverageJLabel   
      beverageJLabel = new JLabel();   
      beverageJLabel.setBounds( 8, 24, 80, 24 );   
      beverageJLabel.setText( "Beverage:" );   
      menuItemsJPanel.add( beverageJLabel );   
   
      // set up beverageJComboBox   
      beverageJComboBox = new JComboBox();   
      beverageJComboBox.setBounds( 88, 24, 128, 25 );   
      menuItemsJPanel.add( beverageJComboBox );   
      beverageJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in beverageJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               beverageJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      // add items to beverageJComboBox   
      beverageJComboBox.addItem( "" );   
      loadCategory( "Beverage", beverageJComboBox );   
   
      // set up appetizerJLabel   
      appetizerJLabel = new JLabel();   
      appetizerJLabel.setBounds( 8, 56, 80, 24 );   
      appetizerJLabel.setText( "Appetizer:" );   
      menuItemsJPanel.add( appetizerJLabel );   
   
      // set up appetizerJComboBox   
      appetizerJComboBox = new JComboBox();   
      appetizerJComboBox.setBounds( 88, 56, 128, 25 );   
      menuItemsJPanel.add( appetizerJComboBox );   
      appetizerJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in appetizerJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               appetizerJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      // add items to appetizerJComboBox   
      appetizerJComboBox.addItem( "" );   
      loadCategory( "Appetizer", appetizerJComboBox );   
   
      // set up mainCourseJLabel   
      mainCourseJLabel = new JLabel();   
      mainCourseJLabel.setText( "Main Course:" );   
      mainCourseJLabel.setBounds( 8, 88, 80, 24 );   
      menuItemsJPanel.add( mainCourseJLabel );   
   
      // set up mainCourseJComboBox   
      mainCourseJComboBox = new JComboBox();   
      mainCourseJComboBox.setBounds( 88, 88, 128, 25 );   
      mainCourseJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in mainCourseJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               mainCourseJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      menuItemsJPanel.add( mainCourseJComboBox );   
   
      // add items to mainCourseJComboBox   
      mainCourseJComboBox.addItem( "" );   
      loadCategory( "Main Course", mainCourseJComboBox );   
   
      // set up dessertJLabel   
      dessertJLabel = new JLabel();   
      dessertJLabel.setBounds( 8, 120, 80, 24 );   
      dessertJLabel.setText( "Dessert:" );   
      menuItemsJPanel.add( dessertJLabel );   
   
      // set up dessertJComboBox   
      dessertJComboBox = new JComboBox();   
      dessertJComboBox.setBounds( 88, 120, 128, 25 );   
      menuItemsJPanel.add( dessertJComboBox );   
      dessertJComboBox.addItemListener(   
   
         new ItemListener()  // anonymous inner class   
         {   
            // event handler called when item in dessertJComboBox   
            // is selected   
            public void itemStateChanged( ItemEvent event )   
            {   
               dessertJComboBoxItemStateChanged( event );   
            }   
   
         } // end anonymous inner class   
   
      ); // end addItemListener   
   
      // add items to dessertJComboBox   
      dessertJComboBox.addItem( "" );   
      loadCategory( "Dessert", dessertJComboBox );   
   
   } // end method createMenuItemsJPanel   
   
   // add items to JComboBox   
   private void loadCategory(   
      String category, JComboBox categoryJComboBox )   
   {   
               
   } // end method loadCategory   
   
   // user select beverage   
   private void beverageJComboBoxItemStateChanged( ItemEvent event )   
   {   
         
   } // end method beverageJComboBoxItemStateChanged   
   
   // user select appetizer   
   private void appetizerJComboBoxItemStateChanged( ItemEvent event )   
   {   
         
   } // end method appetizerJComboBoxItemStateChanged   
   
   // user select main course   
   private void mainCourseJComboBoxItemStateChanged(    
      ItemEvent event )   
   {   
         
   } // end method mainCourseJComboBoxItemStateChanged   
   
   // user select dessert   
   private void dessertJComboBoxItemStateChanged( ItemEvent event )   
   {   
         
   } // end method dessertJComboBoxItemStateChanged   
   
   // user click Calculate Bill JButton   
   private void calculateBillJButtonActionPerformed(    
      ActionEvent event )   
   {   
         
   } // end method calculateBillJButtonActionPerformed   
   
   // calculate subtotal   
   private double calculateSubtotal()   
   {   
      return 0;   
   
   } // end method calculateSubtotal   
   
   // user close window   
   private void frameWindowClosing( WindowEvent event )   
   {   
         
   }  // end method frameWindowClosing   
   
   // method main   
   public static void main( String[] args )    
   {   
      // check command-line arguments   
      if ( args.length == 2 )   
      {   
         // get command-line arguments   
         String databaseDriver = args[ 0 ];   
         String databaseURL = args[ 1 ];   
   
         // create new RestaurantBillCalculator   
         RestaurantBillCalculator application =    
            new RestaurantBillCalculator (    
               databaseDriver, databaseURL );   
      }   
      else   
      {   
         System.out.println( "Usage: java " +    
            "RestaurantBillCalculator databaseDriver databaseURL" );   
      }         
   
   } // end method main   
   
} // end class RestaurantBillCalculator

 
I have written the below trigger and helper class that adds a partner user to a specific public group when a checkbox is ticked on the contact record.

Trigger
trigger Addtogroup4 on Contact (after insert, after update) {
      
      List<GroupMember> GMlist = new List<GroupMember>();
       Set<String> contactEmails = new Set<String>();
       for(Contact con : Trigger.New) {
          //create a set with the contact email addresses
          contactEmails.add(con.email);
       }
    
       //query for the related users and put them in a map,
       //where the key is the email and the value is the user
       Map<String, User> emailUserMap = new Map<String, User> ();
       for(User aUser : [select id, email from User where email in : contactEmails]){
          emailUserMap.put(aUser.email, aUser);
       }
           system.debug(emailUserMap);
           List<Id> userIdList = new List<Id>();
      for(Contact con : Trigger.New) {
        if(con.Public_Group_Technology_Partner_Content__c == TRUE) {    
              
             userIdList.add(emailUserMap.get(con.email).id);
    
          }
      }  
   
      //dymanically get the get group id.
      Group theGroup = [select id from Group where Name = 'Technology Partner Content'];
      if(null != theGroup){
          //call the contact trigger helper if the group exists. 
          //This method adds the user to the group
          ContactTriggerHelper.addUsersToGroup(theGroup.id,userIdList );
      }
  }

Helper Class
public class ContactTriggerHelper{
       
      //future call to do the group adding.  the future call will spawn a new thread.
      @future
      public static void addUsersToGroup(String groupId, List<Id> userIds){
          List<GroupMember> GMlist = new List<GroupMember>();
          for(ID userId: userIds){
              GroupMember gm = new GroupMember();
              gm.GroupId = groupId;
              gm.UserOrGroupId = userId;
              gmList.add(GM);
          }
      
       
          if(gmList.size() > 0){
              insert gmList;
          }
      }
    
  }

The trigger and class are working fine in sandbox. The problem is I am a newbie to apex and have no Idea how to write the test class for this. I pieced the trigger and clas together with assistance on this forum. Do I need a test class for the class and the trigger? Can anyone advise what it would look like?

Thank you
I have written the below trigger which creates a related record when a checkbox is updated. The problem is, it is creating a new record everytime the record is edited since the criteria is being met. Can anyone advise how I can edit my trigger so that it only fires once. (ie.The first time the criteria is met) ?

Trigger
Trigger copyEquipmentonsite on Unit_Placements_Sales__c(after insert, after update)
{
     List<Services__c> sub=new List<Services__c>();
     for(Unit_Placements_Sales__c u : Trigger.new)
     {
           if(u.Service_Month_is_Next_Month__c == TRUE)
           {
                   Services__c s=new Services__c();
                   
                   s.Equipment_Onsite__c=u.ID;
                   s.Equipment_Type__c=u.Equipment__c;
                   s.Machine_Specific_Notes__c=u.Machine_Specific_Notes__c;   
                   s.Product__c=u.The_Product__c;  
                   s.Dell_Tag_Number__c=u.Dell_Tag_Number__c;
                   s.Serial_Number__c=u.Serial_Number__c; 
                   s.XD_Number__c=u.XD_Number__c;
                   
                                                  
                   
                                    
                   sub.add(s);
            }
            if(sub.size()>0)
            insert sub;
     }
}

Thank you
I am using the below code

trigger AddToPG on Contact (after insert, after update) {
    List<GroupMember> GMlist = new List<GroupMember>();
    for(Contact U : Trigger.New) {
        if(U.Add_to_Group__c == TRUE) {
            GroupMember GM = new GroupMember();
            GM.GroupId = '00Gg0000000afKH';
            GM.UserOrGroupId = U.Id;
            GMList.add(GM);        
        }
    }

        insert GMList;
    }

However, this is giving the below error

Error:Apex trigger AddToPG caused an unexpected exception, contact your administrator: AddToPG: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, User/Group ID: id value of incorrect type: 003g000000HfUsiAAF: [UserOrGroupId]: Trigger.AddToPG: line 12, column 1

I think this is because I am trying the set the contact ID where I should be using the User or Group ID. The contacts will be Partner users so they will have a user record. Are there any changes I can make to my trigger which will allow me to do this?