• Loïc
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 9
    Replies

Hello,

 

I'm trying to display the last email received linked to a case in a VF page in an html format. 

 

This code is working great to display the first email received : 

 

public with sharing class CaseHTMLEmailController {
    private final Case caseObj;

    public String firstHTMLEmail { get 
        {return getFirstHTMLEmail(); }
    }
    
    public CaseHTMLEmailController(ApexPages.StandardController stdController) {
        this.caseObj = (Case)stdController.getRecord();
    }

    public String getFirstHTMLEmail() {
        EmailMessage firstEmail = [Select HtmlBody From EmailMessage where ParentId=:caseObj.Id order by LastModifiedDate asc limit 1];
        if (firstEmail!=null) {
            return firstEmail.HtmlBody;
        }
        
        return '';
    }
}

 But if I change the "order by LastModifiedDate asc limit 1" by "desc", to display the last email received, it won't display any records (EmailMessage HtmlBody) :

 

public with sharing class CaseHTMLEmailController {
    private final Case caseObj;

    public String firstHTMLEmail { get 
        {return getFirstHTMLEmail(); }
    }
    
    public CaseHTMLEmailController(ApexPages.StandardController stdController) {
        this.caseObj = (Case)stdController.getRecord();
    }

    public String getFirstHTMLEmail() {
        EmailMessage firstEmail = [Select HtmlBody From EmailMessage where ParentId=:caseObj.Id order by LastModifiedDate desc limit 1];
        if (firstEmail!=null) {
            return firstEmail.HtmlBody;
        }
        
        return '';
    }
}

 Any suggestion would be great and helpful.

 

Thanking you in advance for your help.

Loïc.

  • October 29, 2013
  • Like
  • 0

Hello,

 

In the email to case, when I get an email not attached to a contact, I autocreate a contact but not linked to an account.

 

Then I manually attached the case to an account. I d'like to get the value from this filed : "Account Name" to update the contact filed "Account Name".

 

When I try to save my trigger I get the following error: Invalid initial expression type for field Contact.Id, expecting: Id

 

Here is my code (I'm just starting coding trigger so be kind ;-) ): 

trigger Case_account on Case (before update){
	if(Trigger.isUpdate)
    {
      if(Case.AccountId==null && Case.ContactId==null)
        { List <Contact> objCase= new List<Contact>();
      for(Case c:Trigger.New)
        {
    List <Case> ContactIDCase = [select ContactId from Case where CaseNumber=:c.CaseNumber LIMIT 1];
    List <Case> ContactAccountIdCase = [select AccountId from Case where CaseNumber=:c.CaseNumber LIMIT 1];
	contacts.update(new Contact (Id = ContactIDCase, AccountId = ContactAccountIdCase));
	update objCase;
        }
    }
    }
    }

Any help or suggestion are welcome!

 

  • February 07, 2012
  • Like
  • 0

Hello,

 

I'm trying to get the number of solutions attached to case (the goal is to be able to use a email template displaying the last added solution only with something like :

<apex:repeat first="{!relatedTo.nb_solutions__c-1}" value="{!relatedTo.CaseSolutions}" var="line">
<apex:outputText value="{!line.Solution.SolutionNote}" escape="false" />
</apex:repeat>).

 

Here is my code:

 

trigger CountSolution on Case (after update) {
		case.nb_solutions__c = [select casesolution.SolutionId from casesolution where caseID = :case.Id];
		update case.nb_solutions__c;
}

 

But I'm getting this error:

Save error: Invalid bind expression type of Schema.SObjectField for column of type Id CountSolution.trigger /Test Trigger/src/triggers line 2 Force.com save problem

 

I'm a "newbie", so any help or direction is appreciated. :smileyembarrassed:

  • January 23, 2012
  • Like
  • 0

Hello,

 

In the email to case, when I get an email not attached to a contact, I autocreate a contact but not linked to an account.

 

Then I manually attached the case to an account. I d'like to get the value from this filed : "Account Name" to update the contact filed "Account Name".

 

When I try to save my trigger I get the following error: Invalid initial expression type for field Contact.Id, expecting: Id

 

Here is my code (I'm just starting coding trigger so be kind ;-) ): 

trigger Case_account on Case (before update){
	if(Trigger.isUpdate)
    {
      if(Case.AccountId==null && Case.ContactId==null)
        { List <Contact> objCase= new List<Contact>();
      for(Case c:Trigger.New)
        {
    List <Case> ContactIDCase = [select ContactId from Case where CaseNumber=:c.CaseNumber LIMIT 1];
    List <Case> ContactAccountIdCase = [select AccountId from Case where CaseNumber=:c.CaseNumber LIMIT 1];
	contacts.update(new Contact (Id = ContactIDCase, AccountId = ContactAccountIdCase));
	update objCase;
        }
    }
    }
    }

Any help or suggestion are welcome!

 

  • February 07, 2012
  • Like
  • 0

Hello,

 

I'm trying to get the number of solutions attached to case (the goal is to be able to use a email template displaying the last added solution only with something like :

<apex:repeat first="{!relatedTo.nb_solutions__c-1}" value="{!relatedTo.CaseSolutions}" var="line">
<apex:outputText value="{!line.Solution.SolutionNote}" escape="false" />
</apex:repeat>).

 

Here is my code:

 

trigger CountSolution on Case (after update) {
		case.nb_solutions__c = [select casesolution.SolutionId from casesolution where caseID = :case.Id];
		update case.nb_solutions__c;
}

 

But I'm getting this error:

Save error: Invalid bind expression type of Schema.SObjectField for column of type Id CountSolution.trigger /Test Trigger/src/triggers line 2 Force.com save problem

 

I'm a "newbie", so any help or direction is appreciated. :smileyembarrassed:

  • January 23, 2012
  • Like
  • 0