1
 for(EmailMessage message : Messg){
   System.debug('#####TEST SUBSTRING START #####'+message.Subject);
   try {
      c=[SELECT id,RecordType.name, Description, AccountId, ContactId, OwnerId, CaseNumber, RecordTypeId, CountryCase__c, status, Origin, Subject, VIN__c, Device_Brand__c, Device_Type__c, Language__c FROM Case WHERE Id = :message.ParentId];
   }
   catch(Exception e) {}  

Please provide me a solution asap ...

  • 1
    for future reference, the SFSE community does not look kindly on requests for assistance with imperatives like asap. You should consider the community as providing a service on their own time - and, if you look at the historical record, will find that responses are timely without exhortation required. – cropredy May 17 '15 at 17:13
6
    //First you would loop through your EmailMessage list and collect ParentId to a Set.
Set<Id> parentIds = new Set<Id>();
for(EmailMessage message : Messg){
   parentIds.add(message.ParentId);
}
//Then run the query
List<Case>cases = [SELECT id,RecordType.name, Description, AccountId, ContactId, OwnerId, CaseNumber, RecordTypeId, CountryCase__c, status, Origin, Subject, VIN__c, Device_Brand__c, Device_Type__c, Language__c FROM Case WHERE Id = :parentIds];
//Then you can loop through your cases to implement your logic
for(Case c : cases){
 //your logic goes here
}
  • 1
    @user20539 - Your request for an asap answer was granted, now can you please provide the same courtesy and accept the answer as the correct one. – Eric May 18 '15 at 2:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.