You need to sign in to do that
Don't have an account?
Alex Askew
Formula to split array of product SKU's in text field into individual fields
Hi,
I have an array of product SKU's all in one field seprated by commas e.g. SKU42, SKU08, SKU02, SKU12, SKU64
I would like to use a formula to split out the indidvidual SKU's into separte fields. e.g.
I have an array of product SKU's all in one field seprated by commas e.g. SKU42, SKU08, SKU02, SKU12, SKU64
I would like to use a formula to split out the indidvidual SKU's into separte fields. e.g.
- Text field 1 will just show the first SKU in the array (SKU42)
- Text field 2 will just show the second SKU in the array (SKU08)
- Text field 3 will just show the second SKU in the array (SKU02)
- etc
Is that possible? I can only seem to get it to split out the first SKU at the moment using a formula but I'm struggling with the rest.
Many thanks,
Alex.
If spaces also are present in all/some position be sure to add .trim() after each assignment.
Try simthing like this, and just add more fields in the fieldNames list if you need: Good luck!
All Answers
Do you always have a fixed number of values in the array field and a fixed number of characters for each individual product ?
Hi Akhil,
No, it can vary but there's not likely to be more than 15 values in the array field.
Yes, there will be a fixed number of charcters for each individual product.
Thanks,
Alex.
Thanks Akhil. You couldn’t point me in the right direction for what I would need to put in my Apex Trigger to achieve this could you?
Thanks,
Alex.
If spaces also are present in all/some position be sure to add .trim() after each assignment.
Try simthing like this, and just add more fields in the fieldNames list if you need: Good luck!
I'm getting this error message below. Is it because I'm referencing the Opportunity object incorrectly? Tried searching for help but not having much luck.
Error: Compile Error: Method does not exist or incorrect signature: [Schema.SObjectField].split(String) at line 2 column 30
The field that holds the array of products is called 'Products__c'
The fields that I want to split the text into are called 'Product_1__c', 'Product_2__c', 'Product_3__c' etc.
Only an array of product SKU's all in one field string like that: [1] SKU42 [2] SKU02 [3] SKU12 [4] SKU64 ... could be split with formulas (absolute positions for the bounds needed for each field).
2) You can also unload the IDs and the field containing the arrays of products with the free tool dataloader (SOQL SELECT) (or the workbench) and reload the exported data (UPDATE) with the dataloader adding just the new fields in the header ("Product_1__c","Product_2__c","Product_3__c") after removing the useless blanks and replacing single quote with double quotes (only some administration operation without coding)
https://developer.salesforce.com/page/Data_Loader
Alain
Thanks all. I managed to get this to work using your Apex code Peter. I had to learn a bit about more about Apex Triggers/Classes but got there in the end ha.
Just one question, how would I modify that to not run when the Product Array field is completely empty? It currently tries to run all the time and chucks up an error when it's empty.
Thanks for all your help.
Alex.
That should do the trick !
Thanks Peter and Akhil. Worked perfectly.
Happy New Year!
Thanks,
Alex.