You need to sign in to do that
Don't have an account?
Setting up objects via static resource CSV in apex
I had a bit of trouble finding the solution to my relativley simple problem, set up a bunch of default objects via a static resource instead of using the data loader.
This page was useful, it focuses on creating and reading from a csv via apex:inputFile
http://www.forcetree.com/2010/08/read-and-insert-records-from-csv-file.html
Turns out you can simply query the static resources and split it all up manually so long as you know the order of the fields in the CSV (my static resource is a straight-up csv, no zip)
StaticResource defaultResource = [Select s.Body From StaticResource s where s.Name LIKE 'resourceName%']; blob tempB = defaultResource.Body; String contentFile = tempB.toString(); String[] filelines = contentFile.split('\n'); List<object_to_Create__c> defaults = new List<object_to_Create__c>(); for (Integer i=1;i<filelines.size();i++) { object_to_Create__c temp = object_to_Create__c(); String[] inputvalues = filelines[i].split(','); temp.Field1__c = inputValues[0]; temp.Field2__c = inputValues[1]; defaults.add(temp); } insert defaults;
I hope this saves some developers time, because i was suprised as to how little i was able to find out there
Check out this Force.com Blogpost. Its showing you patterns on how to achieve this type of functionality also.
http://blog.sforce.com/sforce/2011/05/application-initialization-patterns-from-forcecom-labs.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SforceBlog+%28Force.com+Blog%29