+ Start a Discussion
s_k_as_k_a 

the function that can work in apex code same as Alt+Enter in excel 2010

Hi,

 

Can someone help on this issue.

 

For Reporting purpose  we are population a field  on parent object with all related list records separated by new line.

 

Example:

 

Object B has master detail Relationship with ObjectA. 

Let say 3 records  Record1, Record2, Record3  Of ObjectB realted to One Record of ObjectA.

ObjectBSummry is a field on Object A

We are using trigger to Populate  ObjectBSummry by using trigger.

 

Now the value of field ObjectBSummry :

 

Record1

Record2

Record3

(we have used \n character to see values )

 

But when we create a Report on objectA and export value into Excel the newline character is not working

 

The field value ObjectBSummry  is : Record1Record2Record3.

 

But we want the field value in excel also same as UI :

Record1

Record2

Record3

 

 

Is there any keyword we can use in Apex that works same as ALT+ Enter in Excel.

 

Here is my class code and trigger code.

 

public class InvoiceLineitemsSummary{

  public static void LineItemsSummary(Map<Id,Line_Item__c> LineItemsMap){
   
   set<Id> InvoiceIds = new Set<Id>();
   for( Id id:LineItemsMAp.keySet())
       InvoiceIds.add(LineItemsMap.get(id).Invoice_Statement__c);
   List<Line_Item__c> LineItems = [select Invoice_Statement__c,Merchandise__r.Name, Units_Sold__c , value__c from Line_Item__c
                                     where Invoice_Statement__c in:InvoiceIds];
   Map<Id, String> invToLineitemMap = new Map<Id, String>();
   for(Line_Item__c li:  LineItems)
   { 
       if(!invToLineitemMap.containsKey(li.Invoice_Statement__c))
           invToLineitemMap.put(li.Invoice_Statement__c,li.Merchandise__r.Name +'-'+ li.Units_Sold__c +'-'+ li.value__c +'\n');
       else
       invToLineitemMap.put(li.Invoice_Statement__c,invToLineitemMap.get(li.Invoice_Statement__c)+ li.Merchandise__r.Name + '-'+ li.Units_Sold__c +'-'+li.value__c +'\n');
   }
   List<Invoice_Statement__c> InvList  = [select id, Invoices_Summary__c from  Invoice_Statement__c where Id in: InvoiceIds];
   List<Invoice_Statement__c> InvUpdates = new List<Invoice_Statement__c>();
   for(Invoice_Statement__c inv : InvList)
   {
     inv.Invoices_Summary__c =  invToLineitemMap.get(inv.id);
     InvUpdates.add(inv);
   }
    update InvUpdates;
 }
}

 Trigger code:

 

rigger InvoiceLineitesSummaryTrigger on Line_Item__c (after insert,after delete,after Update) {

  if((trigger.isInsert || trigger.isUpdate)&& trigger.isAfter)
  {   
   InvoiceLineitemsSummary.LineItemsSummary(trigger.newMap);
 
  } else if(trigger.isDelete && trigger.isAfter)
  {
     InvoiceLineitemsSummary.LineItemsSummary(trigger.oldmap);
  }
}

 

 the new line character in code is workin in UI and when i export report results into csv.

But  it is nou working when i export report results into .xls format.

 

 

 

 

 

crop1645crop1645

The new lines will appear in CSV exports

s_k_as_k_a

Thank you for your reply.

 

Yes Eric . The new lines appering in csv, but i want to export in excel format .xls

 

The character '\n' is not working if i export into excel.

crop1645crop1645

I am unaware of any solution via SFDC Reports where line breaks are preserved in .xls Export output (they will appear I think if you do Printable View).  

 

This isn't an APEX issue as a user who enters multiple lines in a long text field won't see these line breaks preserved in SFDC Report Exxport to .xls