2

I am trying to find number of lines of long text area field using (formula).As formula field doesn't supports long text area workaround is to use workflow field update formula(workflow field update formula supports long text area).How to get number of lines of long text area field in formula or Do I need to achieve this in trigger ?

1

1 Answer 1

1

Here is my solution

    trigger UpdateCount on my_object__c (after insert,after update) {

    list<Id> lpIdList = new list<Id>();

        for(my_object__c  lp : trigger.new){

            if(trigger.isInsert){
              if((lp.my_long_text_area__c != null)){
              lpIdList.add(lp.Id);
             }
            }

            if(trigger.isUpdate){
               if((Trigger.oldMap.get(lp.Id).my_long_text_area__c != Trigger.newMap.get(lp.Id).my_long_text_area__c) && (Trigger.newMap.get(lp.Id).my_long_text_area__c != null)){
                 lpIdList.add(lp.Id);
              }
            }
        }

     list<my_object__c> lpList = [select id,Line_Count__c,my_long_text_area__c from my_object__c where id in:lpIdList];

    for(LNP_Request__c lp:lpList){
         list<String> totalLines =  lp.my_long_text_area__c.split('\n');
         lp.Line_Count__c = totalLines.size();
      }

    if(lpList.size()>0){
       update lpList; 
    }

  }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .