• Arik
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 49
    Replies
Hi,

I need to add attachments to this class (Email)

Any ideas ?


global class tasks2 implements Messaging.InboundEmailHandler {

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                  Messaging.InboundEnvelope env){

// Create an inboundEmailResult object for returning 
// the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

String myPlainText = '';

// Add the email plain text into the local variable

try
{
      myPlainText = email.plainTextBody.substring(0, email.plainTextBody.indexOf('<stop>'));
}
catch (System.StringException e)
{
     myPlainText = email.plainTextBody;
     System.debug('No <stop> in email: ' + e);
}

// new Task object to be created

Task[] newTask = new Task[0];

    // Try to lookup any contacts based on the email from address
    // If there is more than 1 contact with the same email address
    // an exception will be thrown and the catch statement will be called
try {
       Contact vCon = [Select Id, Name, Email
       From Contact  
       Where Email = :email.fromAddress
       Limit 1];

// Add a new Task to the contact record we just found above
 newTask.add(new Task(Description = myPlainText,
     Priority = 'Normal',
     Status = 'Inbound Email',
     Subject = email.subject,
     ActivityDate = Date.today(),
     IsReminderSet = false,
     ReminderDateTime = System.now()+1,
     WhoId = vCon.Id));

// Insert the new Task and it will be created and appended to the contact record
     insert newTask;

System.debug('New Task Object: ' + newTask );
}
   // If there is an exception with the query looking up
   // the contact this QueryException will be called.
   // and the exception will be written to the Apex Debug logs

   catch (System.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 Force.com Email Service
  return result;
}

static testMethod void testTasks() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Create the plainTextBody and fromAddres for the test
    email.plainTextBody = 'Here is my plainText body of the email';
    email.fromAddress ='rmencke@salesforce.com';

Tasks taskObj = new Tasks();
taskObj.handleInboundEmail(email, env);


}
  • January 23, 2012
  • Like
  • 0

Does anybody have any idea how one would go about solving this problem:

 

1  I want to create an a SFDC event from an inbound email (using mail service)

 

Thank in advance

  • January 21, 2012
  • Like
  • 0

The receipe is located at http://developer.force.com/cookbook/recipe/creating-tabbed-accounts

 

I tried to add a custom object called "Test" and have can not solve it.

 

Any help would be appreciated.

 

Thx

 

 

  • January 11, 2012
  • Like
  • 0

Any thoughts on how to do a Mass Lead Convert ?

 

Any Ideas Appreciated - that do not include, export import

  • January 09, 2012
  • Like
  • 0

Error: Compile Error: unexpected token: 'Messaging.InboundEmail' at line 71 column 3 is the error received on below.

 

Any ideas ?

 

global class tasks implements Messaging.InboundEmailHandler {

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
                                                  Messaging.InboundEnvelope env){

// Create an inboundEmailResult object for returning
// the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

String myPlainText = '';

// Add the email plain text into the local variable

try
{
      myPlainText = email.plainTextBody.substring(0, email.plainTextBody.indexOf('<stop>'));
}
catch (System.StringException e)
{
     myPlainText = email.plainTextBody;
     System.debug('No <stop> in email: ' + e);
}

// new Event object to be created

Event[] newEvent = new Event[0];

    // Try to lookup any contacts based on the email from address
    // If there is more than 1 contact with the same email address
    // an exception will be thrown and the catch statement will be called
try {
       Contact vCon = [Select Id, Name, Email
       From Contact  
       Where Email = :email.fromAddress
       Limit 1];

// Add a new Event to the contact record we just found above
 newEvent.add(new Event(Description = myPlainText,
     Subject = email.subject,
     ActivityDate = Date.today(),
     IsReminderSet = false,
     ReminderDateTime = System.now()+1,
     IsAllDayEvent = True,
     WhoId = vCon.Id));

// Insert the new Task and it will be created and appended to the contact record
     insert newEvent;

System.debug('New Event Object: ' + newEvent );
}
   // If there is an exception with the query looking up
   // the contact this QueryException will be called.
   // and the exception will be written to the Apex Debug logs

   catch (System.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 Force.com Email Service
  return result;
}

static testMethod void testEvents {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Create the plainTextBody and fromAddres for the test
    email.plainTextBody = 'Here is my plainText body of the email';
    email.fromAddress ='rmencke@salesforce.com';

Events eventObj = new Events();
taskObj.handleInboundEmail(email, env);
}

}

  • January 08, 2012
  • Like
  • 0

Hi,

 

I have the box checked to add all attachments on the apex service, yet the attachments are not being added.  Here is the associated class.

 

global class tasks implements Messaging.InboundEmailHandler {

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                  Messaging.InboundEnvelope env){

// Create an inboundEmailResult object for returning 
// the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

String myPlainText = '';

// Add the email plain text into the local variable

try
{
      myPlainText = email.plainTextBody.substring(0, email.plainTextBody.indexOf('<stop>'));
}
catch (System.StringException e)
{
     myPlainText = email.plainTextBody;
     System.debug('No <stop> in email: ' + e);
}

// new Task object to be created

Task[] newTask = new Task[0];

    // Try to lookup any contacts based on the email from address
    // If there is more than 1 contact with the same email address
    // an exception will be thrown and the catch statement will be called
try {
       Contact vCon = [Select Id, Name, Email
       From Contact  
       Where Email = :email.fromAddress
       Limit 1];

// Add a new Task to the contact record we just found above
 newTask.add(new Task(Description = myPlainText,
     Priority = 'Normal',
     Status = 'Inbound Email',
     Subject = email.subject,
     ActivityDate = Date.today(),
     IsReminderSet = false,
     ReminderDateTime = System.now()+1,
     WhoId = vCon.Id));

// Insert the new Task and it will be created and appended to the contact record
     insert newTask;

System.debug('New Task Object: ' + newTask );
}
   // If there is an exception with the query looking up
   // the contact this QueryException will be called.
   // and the exception will be written to the Apex Debug logs

   catch (System.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 Force.com Email Service
  return result;
}

static testMethod void testTasks() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Create the plainTextBody and fromAddres for the test
    email.plainTextBody = 'Here is my plainText body of the email';
    email.fromAddress ='rmencke@salesforce.com';

Tasks taskObj = new Tasks();
taskObj.handleInboundEmail(email, env);


}
Any ideas ?
  • January 07, 2012
  • Like
  • 0

Hi all -

 

This is my test class:

 

@isTest
private class testAutomaticFollowUp {

    public static testMethod void unitTestAutomaticFollowUp() {

        Contact acct = new Contact();
        acct.Name = 'Test Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);


        insert acct;

        test.startTest();

        acct.Follow_Upcheckbox__c = true;
        update acct;

        test.stopTest();

    }
}

 

I get the error:

 

Error: Compile Error: Field is not writeable: Contact.Name at line 7 column 9

 

Here is the Trigger:

 

trigger AutomaticFollowUp on Contact (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the Followup field
    // and creates an Event
    ////////////////////////////////////
    
    if(trigger.isUpdate && trigger.isBefore) {
        
        // Create empty List to hold new Events (bulk DML) 
        List<Event> lstNewEvents = new List<Event>();
        
        for(Contact a : trigger.new) {
            
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.Follow_Upcheckbox__c == true && a.Follow_Upcheckbox__c != trigger.oldMap.get(a.Id).Follow_Upcheckbox__c) {
                
                // Set Start Date
                Date dteStart = a.Follow_Up_Date__c;
                
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhoId = a.id; // Sets the Contact as the Event's Name
                newEvent.Whatid = a.Deal__c;
                newEvent.Subject = a.Follow_Up_Reason__c;
                newEvent.ActivityDate = a.Follow_Up_Date__c;
                newEvent.IsAllDayEvent = true;
                
                lstNewEvents.add(newEvent);
                
            }
        }
        
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
        
    }

}

Any Ideas or help - more then appreciated


Thanks in advance


  • January 07, 2012
  • Like
  • 0

I am stuck on the test class.....Any help appreciated:

 

Here is the Trigger:

 

trigger     CICDocumentsObjectionDeadline on rethink2__Closing__c (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the TestCheckbox field
    // and creates an Event
    ////////////////////////////////////
   
    if(trigger.isUpdate && trigger.isBefore) {
       
        // Create empty List to hold new Events (bulk DML)
        List<Event> lstNewEvents = new List<Event>();
       
        for(rethink2__Closing__c a : trigger.new) {
           
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.CIC_Documents_Objection_Deadline_Checkbo__c == true && a.CIC_Documents_Objection_Deadline_Checkbo__c != trigger.oldMap.get(a.Id).CIC_Documents_Objection_Deadline_Checkbo__c) {
               
                // Set Start Date
                Date dteStart = a.CIC_Documents_Objection_Deadline__c;
               
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
                newEvent.Subject = 'CIC Documents Objection Deadline';
                newEvent.ActivityDate = a.CIC_Documents_Objection_Deadline__c;
                newEvent.IsAllDayEvent = true;
               
                lstNewEvents.add(newEvent);
               
            }
        }
       
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
       
    }
    
}

Here is the Test Class that gives error

Error: Compile Error: Expression cannot be assigned at line -1 column -1

 

@isTest
private class testCICDocumentsObjectionDeadline{

    public static testMethod void unitTestCICDocumentsObjectionDeadline() {

        rethink2__Closing__c.Name = new Name();
        rethink2__Closing__c.Name = 'Test Closing';
rethink2__Closing__c.CIC_Documents_Objection_Deadline__c = Date.newInstance(2011,5,1);


        insert rethink2__Closing__c.Name;

        test.startTest();

        rethink2__Closing__c.CIC_Documents_Objection_Deadline_Checkbo__c = true;
        update rethink2__Closing__c.Name;

        test.stopTest();

    }
}

 

 

  • January 06, 2012
  • Like
  • 0

Help - need apex - not workflows to do a field update on tasks....

  • January 04, 2012
  • Like
  • 0

I want a field update to take place via workflow once a task is created with another workflow.  The field is custom so it cant be added when task created...any ideas

  • January 04, 2012
  • Like
  • 0

I need a test class for this trigger:

 

trigger CreateEvent on Task (after insert,after update)
{
task ta=trigger.new[0];
if(ta.CreateEvent__c==true)
{
task ta1=trigger.old[0];
Datetime startDateTime=Datetime.newInstance(ta1.activitydate, Time.newInstance(1, 0, 0, 0));
Datetime endDateTime=Datetime.newInstance(ta1.activitydate, Time.newInstance(12, 0, 0, 0));
Event e=new event(OwnerId = ta1.ownerid,Subject = ta1.Subject,StartDateTime = startDateTime,EndDatetime = endDateTime,WhoId = ta1.whoid);
insert e;
task t=new task(id=ta1.id);
delete t;
}
}

Any help would be appreciated
  • January 04, 2012
  • Like
  • 0

I am trying to write a trigger, that will, in effect turn a task into an event in sfdc as follows:

 

1.  Make a check box on task (Custom field called "turn into event")

2.  When checkbox is checked, a trigger is activated to create a new event.

3.  This event is populated with the data from the task that starts it.

4.  Then the old task is deleted.

 

Thanks in advance

  • January 04, 2012
  • Like
  • 0
 I want to send an email out when an opportunity's stage is changed to "closed-won". The email needs to contain information from the opportunity and the contact associated with that opportunity (contact first and last name, contact email, contact phone).

Has anyone encounetered this error before?

 

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: ENTITY_IS_DELETED, entity is deleted: []"

  • June 29, 2012
  • Like
  • 0

I need to show the files i uploaded in "Attachments and Notes" in salesforce in a popup window....how can this be done?????

 

Help please!!

 

Thanks

  • June 29, 2012
  • Like
  • 0

I've been working on my own implementation of Salesforce and loving it. I have Person Account with some custom fields. In my setting, I need to track the name of a host home provider for a student.

 

So I've created two custom text fields, Host First Name and Host Last Name. I've got these added to my Account record detail and they work as expected. 

 

However, I would like to be able to have them display on one line like the account name does. Right now each field is separated. I would like a similiar functionality like the built in Account Name where you click it and get a pop-up window of Title, First Name, and LastName... although i don't necessarily need the title field.

 

Is there a basic way to do this? Any help is much appreciated.

Would anybody shed some light on the pros and cons of using Force.com licenses vs. Authenticated Sites licenses?

 

We need to decide the option for a site which has following major objectives

 

1. Custom UI

 

2. Collaboration (chatter)

 

2. Data Entry into custom objects

 

3. Standard SF reports

 

5. Business logic & rules implementation

 

Three different parties will have access to the site with their own internal  users.

 

What would be the best licence to use (or combination)?

 

Thanks,

Sourabh

Hi,

I need to add attachments to this class (Email)

Any ideas ?


global class tasks2 implements Messaging.InboundEmailHandler {

global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, 
                                                  Messaging.InboundEnvelope env){

// Create an inboundEmailResult object for returning 
// the result of the Force.com Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

String myPlainText = '';

// Add the email plain text into the local variable

try
{
      myPlainText = email.plainTextBody.substring(0, email.plainTextBody.indexOf('<stop>'));
}
catch (System.StringException e)
{
     myPlainText = email.plainTextBody;
     System.debug('No <stop> in email: ' + e);
}

// new Task object to be created

Task[] newTask = new Task[0];

    // Try to lookup any contacts based on the email from address
    // If there is more than 1 contact with the same email address
    // an exception will be thrown and the catch statement will be called
try {
       Contact vCon = [Select Id, Name, Email
       From Contact  
       Where Email = :email.fromAddress
       Limit 1];

// Add a new Task to the contact record we just found above
 newTask.add(new Task(Description = myPlainText,
     Priority = 'Normal',
     Status = 'Inbound Email',
     Subject = email.subject,
     ActivityDate = Date.today(),
     IsReminderSet = false,
     ReminderDateTime = System.now()+1,
     WhoId = vCon.Id));

// Insert the new Task and it will be created and appended to the contact record
     insert newTask;

System.debug('New Task Object: ' + newTask );
}
   // If there is an exception with the query looking up
   // the contact this QueryException will be called.
   // and the exception will be written to the Apex Debug logs

   catch (System.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 Force.com Email Service
  return result;
}

static testMethod void testTasks() {

// Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

// Create the plainTextBody and fromAddres for the test
    email.plainTextBody = 'Here is my plainText body of the email';
    email.fromAddress ='rmencke@salesforce.com';

Tasks taskObj = new Tasks();
taskObj.handleInboundEmail(email, env);


}
  • January 23, 2012
  • Like
  • 0

The receipe is located at http://developer.force.com/cookbook/recipe/creating-tabbed-accounts

 

I tried to add a custom object called "Test" and have can not solve it.

 

Any help would be appreciated.

 

Thx

 

 

  • January 11, 2012
  • Like
  • 0

Hi all -

 

This is my test class:

 

@isTest
private class testAutomaticFollowUp {

    public static testMethod void unitTestAutomaticFollowUp() {

        Contact acct = new Contact();
        acct.Name = 'Test Contact';
acct.Follow_Up_Date__c = Date.newInstance(2011,5,1);


        insert acct;

        test.startTest();

        acct.Follow_Upcheckbox__c = true;
        update acct;

        test.stopTest();

    }
}

 

I get the error:

 

Error: Compile Error: Field is not writeable: Contact.Name at line 7 column 9

 

Here is the Trigger:

 

trigger AutomaticFollowUp on Contact (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the Followup field
    // and creates an Event
    ////////////////////////////////////
    
    if(trigger.isUpdate && trigger.isBefore) {
        
        // Create empty List to hold new Events (bulk DML) 
        List<Event> lstNewEvents = new List<Event>();
        
        for(Contact a : trigger.new) {
            
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.Follow_Upcheckbox__c == true && a.Follow_Upcheckbox__c != trigger.oldMap.get(a.Id).Follow_Upcheckbox__c) {
                
                // Set Start Date
                Date dteStart = a.Follow_Up_Date__c;
                
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhoId = a.id; // Sets the Contact as the Event's Name
                newEvent.Whatid = a.Deal__c;
                newEvent.Subject = a.Follow_Up_Reason__c;
                newEvent.ActivityDate = a.Follow_Up_Date__c;
                newEvent.IsAllDayEvent = true;
                
                lstNewEvents.add(newEvent);
                
            }
        }
        
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
        
    }

}

Any Ideas or help - more then appreciated


Thanks in advance


  • January 07, 2012
  • Like
  • 0

I am stuck on the test class.....Any help appreciated:

 

Here is the Trigger:

 

trigger     CICDocumentsObjectionDeadline on rethink2__Closing__c (before update) {

    ////////////////////////////////////
    // This trigger detects the change of the TestCheckbox field
    // and creates an Event
    ////////////////////////////////////
   
    if(trigger.isUpdate && trigger.isBefore) {
       
        // Create empty List to hold new Events (bulk DML)
        List<Event> lstNewEvents = new List<Event>();
       
        for(rethink2__Closing__c a : trigger.new) {
           
            // Determine if the checkbox is TRUE and the user has just flipped it from FALSE.
            if(a.CIC_Documents_Objection_Deadline_Checkbo__c == true && a.CIC_Documents_Objection_Deadline_Checkbo__c != trigger.oldMap.get(a.Id).CIC_Documents_Objection_Deadline_Checkbo__c) {
               
                // Set Start Date
                Date dteStart = a.CIC_Documents_Objection_Deadline__c;
               
                // Create Event
                Event newEvent = new Event();
                newEvent.OwnerId = UserInfo.getUserId(); // Sets the current userId as the Event Owner
                newEvent.WhatId = a.Id; // Sets the Account as the Event's "Related To"
                newEvent.Subject = 'CIC Documents Objection Deadline';
                newEvent.ActivityDate = a.CIC_Documents_Objection_Deadline__c;
                newEvent.IsAllDayEvent = true;
               
                lstNewEvents.add(newEvent);
               
            }
        }
       
        if(lstNewEvents.size() > 0) { insert lstNewEvents; }
       
    }
    
}

Here is the Test Class that gives error

Error: Compile Error: Expression cannot be assigned at line -1 column -1

 

@isTest
private class testCICDocumentsObjectionDeadline{

    public static testMethod void unitTestCICDocumentsObjectionDeadline() {

        rethink2__Closing__c.Name = new Name();
        rethink2__Closing__c.Name = 'Test Closing';
rethink2__Closing__c.CIC_Documents_Objection_Deadline__c = Date.newInstance(2011,5,1);


        insert rethink2__Closing__c.Name;

        test.startTest();

        rethink2__Closing__c.CIC_Documents_Objection_Deadline_Checkbo__c = true;
        update rethink2__Closing__c.Name;

        test.stopTest();

    }
}

 

 

  • January 06, 2012
  • Like
  • 0

Help - need apex - not workflows to do a field update on tasks....

  • January 04, 2012
  • Like
  • 0

I want a field update to take place via workflow once a task is created with another workflow.  The field is custom so it cant be added when task created...any ideas

  • January 04, 2012
  • Like
  • 0

Hi,

 

We are creating a simple App, there are no Visualforce pages involved in the App. In the Salesforce standard UI how do I enable Inline Editing for Related List.

I have enable Inline Edit option from Setup-Customize-User Interface, but that does not allow me to make inline edit for Related lists. The field types that are to be editted or Text and Picklist.

Any help on this would be great.

 

Thanks

KD