You need to sign in to do that
Don't have an account?
Jasmeen Kaur 22
Email to Case: Subject
Hi Experts
Here is a question regarding Email to Case. In my org, we use Email to Case. The Subject of email-to-case is like : "Credit Hold : (ABCDEFGH ) : Sales Order : 1236589kmjl456" Where ABCDEFGH = Account name.
On Case Page layout, we have a field = Account name. Is there a way that This field can be auto filled from Subject by finding the string in ()? Because the Account name in subject is always in ( ).
I am an Admin so, I don't know much coding. Any help will be highly appreciated.
Regards
Here is a question regarding Email to Case. In my org, we use Email to Case. The Subject of email-to-case is like : "Credit Hold : (ABCDEFGH ) : Sales Order : 1236589kmjl456" Where ABCDEFGH = Account name.
On Case Page layout, we have a field = Account name. Is there a way that This field can be auto filled from Subject by finding the string in ()? Because the Account name in subject is always in ( ).
I am an Admin so, I don't know much coding. Any help will be highly appreciated.
Regards
Please reference here: https://developer.salesforce.com/forums/?id=9060G000000BirVQAS
I am aiming to populate the account lookup, not just a text field with a name in it. Is it posible and how?
Thanks
To be honest, I never created any apex class. Can you please help me with this by explaining bit more? Or if it is possible by using Flows?
I can't find it out, can you please elaborate it if you have ever did this?
Well, Thanks for investigating through.
Good Day!
Please let me know whether the sample code meets your requirements:
Trigger CaseTrigger on Case(after insert){
Public Static final STR1='(';
Public static final STR2 = ')';
set<String>accNameSet = new Set<String>();
Map<String,String>accNameMap = new Map<String,String>();
set<Id>accId= new Set<Id>();
List<Case>caseUpdateList = new List<Case>();
for(Case c: trigger.new){
if(c.origin.equalsIgnoreCase('Give the Case origin you have set on Email-to-Case Settings') && !string.isBlank(c.Subject)){
string subject = string.valueof(c.Subject);
string accName = subject.substringBetween(STR1,STR2);
accNameSet.add(accName);
caseUpdateList.add(c);
}
}
for(Account acct:[Select Id,Name from Account where Name IN :accCaseMap.keyset()])
{
accNameMap.put(acct.Name,acct.id);
}
if(!caseUpdateList.isEmpty() && !accId.isEmpty())
{
List<Case>finalCaseList = new List<Case>();
for(Case c1 : caseUpdateList){
string caseSubject = string.valueof(c.Subject);
string acctName = caseSubject.substringBetween(STR1,STR2);
c1.Account = accNameMap.get(acctName);
finalCaseList.add(c1);
}
Database.update(finalCaseList,false);
}
}
The only Potential risk I can see in the above solution, if there are more than one Accounts with same name, we might end up mapping wrong account to the Case.
So, please make sure to adjust the duplicate Account Name issue in the org.
Please mark this as best answer if this solves your requirement.