+ Start a Discussion
Abhishek Singh 88Abhishek Singh 88 

how to parse string

Hi All,

I have below data in Description Field of incident.

Application: Oracle eBusiness Suite (eBS)
Change Driver: Migration
Change Category: New scripts
Is this Change part of a Project?: Yes
Non-Technical Reason for Change?: Importing Fieldglass invoices programatically
Do we need a WebEx?: No
Why is WebEx NOT Required?: It is a new component. And all the details are discussed with the functional team.
WebEx/Bridge Information: 
Number of Users Affected: Internal – None
Worst Case if not Implemented: Oracle might not able to import fieldglass invoices
End user experience if Change fails: Oracle might not able to import fieldglass invoices
End User Experience during Change: Once change implemented successfully. User might able to import fieldglass invoice

I want to parse it and want to store only bold text(Number of Users Affected)

Any Suggestion would be appriciated
Best Answer chosen by Abhishek Singh 88
DevADSDevADS
Hey Abhishek,

There is no specific of string parsing in Salesforce, You have to write a custom logic either using split/substring method -

For Ex. Say you are storing your string value in Description field on Account, See below your code for the reference -
Account acc = [SELECT Description from Account where id='<accountId>'];
List<String> strList = acc.Description.split('\n');
for(String str : strList){
     if(str.startsWith('Number of Users Affected')){
         list<String> response = str.split(':');
		 if(response.size()>1){
			system.debug('======response====\n\n'+response[1]);
		 }
     }
}

This will return 'Internal – None'.

Post here if you have any further questions OR close this thread if thee answer resolves your questions.

Happy Coding!!

All Answers

DevADSDevADS
Hey Abhishek,

There is no specific of string parsing in Salesforce, You have to write a custom logic either using split/substring method -

For Ex. Say you are storing your string value in Description field on Account, See below your code for the reference -
Account acc = [SELECT Description from Account where id='<accountId>'];
List<String> strList = acc.Description.split('\n');
for(String str : strList){
     if(str.startsWith('Number of Users Affected')){
         list<String> response = str.split(':');
		 if(response.size()>1){
			system.debug('======response====\n\n'+response[1]);
		 }
     }
}

This will return 'Internal – None'.

Post here if you have any further questions OR close this thread if thee answer resolves your questions.

Happy Coding!!
This was selected as the best answer
Deepali KulshresthaDeepali Kulshrestha
Hi Abhishek,

Please refer to this link it may be helpful to you:-

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsonparser.htm

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha