-2

My SOQL Query

 string str = '%'+email.subject.trim()+'%';
  GMC__c gmcList =  [select id,name,Case_Number__c from GMC__c where name like :str limit 1];  

GMC__c Name is an autonumber field which will be unique

Now my actual requirement is when a user sends mail Subject with only Name it works perfect. In the other case if he sends say suppose This is regarding GMCName then we need to Query that contains GMCName. What would be the best aproach for this

1

What I understood from your requirement is, Subject sent by User can be dynamic. Sometimes its only GMCName and sometimes it is included in some sentence, as you have mentioned This is regarding GMCName.
And your GMC__c Name is autonumber field. So it must be having some particular format like Q{00000} i.e A-{0000} etc. Having fixed length and fixed format. You must be knowing starting characters of your GMC Name.
You can do following :

Integer index = email.subject.indexOf(--Starting Characters of GMC Name--);

//As you know length of your GMC name(as it is Autonumber), so that length to Integer index obtained above.

String gmcName = email.subject.substring(index,index+lengthOfAutonumber)

In this way you can obtain GMCName

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.