function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sieb4mesieb4me 

worflow triggering and count

Hi,
Is it possible to have some kind of counter field on object which is updated and added whenever workflow is triggered on that object.

Example we want to know how many times workflow sent email when case status field was set to closed.
We have workflow on case object which sends survey email alert when case status is closed. We wish to count how many such emails were sent or rather how many times workflow was called to send email.

Thanks

Best Answer chosen by sieb4me
Daniel B ProbertDaniel B Probert
hmmm ok i just tested and it's the formula your using in the field update.

this is the formula that i used:

PRIORVALUE(Counter__c) + 1

this will then add when each time a case is close - so if a case is closed then reopened then closed you will get the number 1.

for a cumulative total across all case just create a report on that field which is a summary and total the counter column.

hope that makes sense.

dan


All Answers

Daniel B ProbertDaniel B Probert
create the counter field(number) on the case.

then update the workflow that sends the email with a field update that has a value of fieldname + 1
sieb4mesieb4me
thanks yes thats what i did
Daniel B ProbertDaniel B Probert
excellent then you should mark this as resolved.

thanks
dan
sieb4mesieb4me
its not working..i get this error..Error: Formula cannot use another formula field that directly or indirectly refers to itself. Case.counter__c -> Case.counter__c
sieb4mesieb4me
this field needs to be cumulative...so for diff cases when emails go, it needs to add up..counter field on case wont work
Daniel B ProbertDaniel B Probert
hmmm ok i just tested and it's the formula your using in the field update.

this is the formula that i used:

PRIORVALUE(Counter__c) + 1

this will then add when each time a case is close - so if a case is closed then reopened then closed you will get the number 1.

for a cumulative total across all case just create a report on that field which is a summary and total the counter column.

hope that makes sense.

dan


This was selected as the best answer
Daniel B ProbertDaniel B Probert
oh and when you created the counter__c field you need to set the default value to be 0
sieb4mesieb4me
Thanks Dan. I have another question, for which i log another issue here , however do you know if for email2cases, currently salesforce creates cases without consider if constomer wants p1 or p2 severity logged, it simply takes email and logs cases.
can we have customers use template and salesforce considers whats in template and logs case so that case fields are populated as per what customer seleected like P1 for severity, etc.
Daniel B ProbertDaniel B Probert
no worries - to do this you should add a trigger to the case object that fires before insert - you should then beable to search the case for keywords which you can ask you clients to put in the emai like.

URGENT P1

this should get you going..

trigger Trg_email2case on Case (before insert) {
    // LOOP THROUGH new cases and see if any email2case, "process" them
    for(Case thisCase : trigger.new) 
    {
        if(thisCase.Origin == 'your email to case origin name') {
            // Now do the clever logic do your work
            if(thisCase.Subject.contains('URGENT') || thisCase.Subject.contacts('P1')) {
                thisCase.PRIORITY = 'High';
            }

        }
    }

}
or something like that - might be typos in there but hopefully that points you in the right direction..

sieb4mesieb4me
Thanks Dan, how about email body parsing code, example

lets say if we have 4 fields like this in email body which customer has sent to us assuming anything in the brackets is field name[ ]

[severity]
P1

[Project]
0-100

[Area]
install

you can post your answer here to following link since i posted question for this on that link,  so i can mark it as best answer
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AWZgIAO
sieb4mesieb4me
thanks, yes thats another way to do it, however can you please check my link and question there, can you please tell me how to resolve that error.

https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AWajIAG