function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brandon Bridges 16Brandon Bridges 16 

From Subject Received Size Categories Salesforce Success Community ( New reply to your question. Sat 12/10 16 KB

In the service cloud, I am trying to set up a trigger.

The trigger is on emailMessage. When a consultant sends a second email to a customer, I want to create a new case with all of the same field values as the original case,except for id, and attach the trigger email to that new case. 
Currently, I'm having major trouble with the SOQL query that does this.
 if(e.Incoming==false){//Email must be outgoing
    string expr='[SELECT ';
    Map<String, String> labelMap = new Map<String, String>();
    Schema.DescribeSObjectResult objectDescribe  = Case.SObjectType.getDescribe();
    Map<String, Schema.SObjectField>fieldMap = objectDescribe.fields.getMap();
   	for(String fieldName:fieldMap.keySet()) {
      		Schema.SObjectField field=fieldMap.get(fieldName);
        	Schema.DescribeFieldResult fieldDescribe=field.getDescribe();      		labelMap.put(fieldDescribe.getLabel(),fieldDescribe.getName());
               ' FROM case WHERE id=:e.parentId]';
        List<case>myCases=[SELECT expr FROM case WHERE id=:e.ParentId LIMIT 1];