• Kenji778
  • NEWBIE
  • 0 Points
  • Member since 2011
  • Senior Developer
  • LiquidHub


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 13
    Replies

Yup, it's me again.

I dunno if I just suck, or if I'm really pushing this parser. I am making a call to facebook to get user data. The user data comes back as JSON. Most of it is simple string data. There are 3 fields that are arrays. Those arrays contain only 2 items (id and name). I have attempted to create the class based on the JSON and deserialize into it. I am receiving another salesforce system error.

 

System.UnexpectedException: Salesforce System Error: 996229906-358 (-433257328) (-433257328) 
An unexpected error has occurred. Your solution provider has been notified. (system)

Here is the json I am attempting to parse (cleaned up a bit)

{
    "id": "XXXXX",
    "name": "XXXXXX XXXXXXX",
    "first_name": "XXXXXX",
    "last_name": "XXXXXX",
    "link": "http://www.facebook.com/XXXXXX",
    "username": "XXXXXX",
    "about": "some data about the person.",
    "birthday": "00/00/0000",
    "hometown": {
        "id": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "name": "Somewhere, New York"
    },
    "location": {
        "id": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "name": "Nowhere, Nevada"
    },
    "bio": "This is some demo text",
    "inspirational_people": [
        {
            "id": "109425469076258",
            "name": "Miyamoto Musashi"
        },
        {
            "id": "112377255503169",
            "name": "Kenshin Himura"
        },
        {
            "id": "135952326470380",
            "name": "Spike Spiegel"
        },
        {
            "id": "146133595436195",
            "name": "Kamina"
        },
        {
            "id": "12534674842",
            "name": "Albert Einstein"
        },
        {
            "id": "184049470633",
            "name": "Bruce Lee"
        }
    ],
    "gender": "male",
    "email": "XXXXXX@XXXXXX.com",
    "timezone": -4,
    "locale": "en_US",
    "verified": true,
    "updated_time": "2011-11-07T21:17:55+0000"
}


OR EASILY PASTEABLE VERSION
{ "id": "XXXXX", "name": "XXXXXX XXXXXXX", "first_name": "XXXXXX", "last_name": "XXXXXX", "link": "http://www.facebook.com/XXXXXX", "username": "XXXXXX", "about": "some data about the person.", "birthday": "00/00/0000", "hometown": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Somewhere, New York" }, "location": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Nowhere, Nevada" }, "bio": "This is some demo text", "inspirational_people": [ { "id": "109425469076258", "name": "Miyamoto Musashi" }, { "id": "112377255503169", "name": "Kenshin Himura" }, { "id": "135952326470380", "name": "Spike Spiegel" }, { "id": "146133595436195", "name": "Kamina" }, { "id": "12534674842", "name": "Albert Einstein" }, { "id": "184049470633", "name": "Bruce Lee" } ], "gender": "male", "email": "XXXXXX@XXXXXX.com", "timezone": -4, "locale": "en_US", "verified": true, "updated_time": "2011-11-07T21:17:55+0000" } 

 

 Here is the code I am trying to run. You should be able to run this in execute anonymous. I have tried running it regular as well (being invoked by the page, which has the class as a controller) and get the same error either way.



string jsonData = '{ "id": "XXXXX", "name": "XXXXXX XXXXXXX", "first_name": "XXXXXX", "last_name": "XXXXXX", "link": "http://www.facebook.com/XXXXXX", "username": "XXXXXX", "about": "some data about the person.", "birthday": "00/00/0000", "hometown": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Somewhere, New York" }, "location": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Nowhere, Nevada" }, "bio": "This is some demo text", "inspirational_people": [ { "id": "109425469076258", "name": "Miyamoto Musashi" }, { "id": "112377255503169", "name": "Kenshin Himura" }, { "id": "135952326470380", "name": "Spike Spiegel" }, { "id": "146133595436195", "name": "Kamina" }, { "id": "12534674842", "name": "Albert Einstein" }, { "id": "184049470633", "name": "Bruce Lee" } ], "gender": "male", "email": "XXXXXX@XXXXXX.com", "timezone": -4, "locale": "en_US", "verified": true, "updated_time": "2011-11-07T21:17:55+0000" }';    
class facebookUser
    {
        public string id;
        public string name;
        public string first_name;
        public string last_name;
        public string link;
        public string username;
        public string about;
        public string birthday;
        public string gender;
        public string email;
        public string timezone;
        public string locale;
        public string verified;
        public string updated_time;
        public list<dataItem> hometown;
        public list<dataItem> location;
        public list<dataItem> inspirational_people;
        
        public facebookUser(string id, string name, string first_name, string last_name, string link, string username, string about, string birthday, string gender, string email, string timeZone, string locale, string verified, string updated_time)
        {
            this.id = id;
            this.name = name;
            this.first_name = first_name;
            this.last_name = last_name;
            this.link = link;
            this.username = username;
            this.about = about;
            this.birthday = birthday;
            this.gender = gender;
            this.email = email;
            this.timeZone = timeZone;
            this.locale = locale;
            this.verified = verified;
            this.updated_time = updated_time;
            this.hometown =  new list<dataItem>();
            this.location =  new list<dataItem>();
            this.inspirational_people = new list<dataItem>();      
        }
    }
    
    class dataItem 
    {
        public string id;
        public string name;
        
        public dataItem(string id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }

//I have tried deserializing to a list, as well as a single object list<facebookUser> d = (list<facebookUser>)JSON.deserialize( jsonData,facebookUser.class);

//This fails too
facebookUser d = (facebookUser)JSON.deserialize( jsonData,facebookUser.class); 

 

Any thoughts would be much appreciated. Thank you.

Hey all,

Being somewhat a java style programming language novice, this is something that escapes me. Say I don't know what kind of data is going to returned via a call to a remote webservice. All I know is that is is going to contain JSON encoded data. I don't know what fields may be there, or if it may also contain nested arrays, etc. Is there a way to just have a generic deserialzation process, without having to cast to a specifc class type? In ColdFusion for example, there is just a deserializeJson function which can take any kind of JSON string as long as it is valid and create a logical structure out of it. You have no need to know ahead of time anything about the structure of the JSON and it is extremely handy, and much more robust than having to manually define a data type for the expected return. Is this possible in Apex as well, or not due to the statically typed nature of the language?

Hey all,

Simple syntax question here. When I need to create an sObject to be inserted, but I don't know what kind it will be ahead of time, how can I create an sObject of a certain type given a name? So say the string contact was passed in, how would I create a contact object? Thanks!

Hey all,

This is similar to my thread from last night, but the question has changed a bit. So I have a visualforce page with a regular old file input. When the form is submitted, it posts to a visualforce page attached to an apex controller. When the apex controller evaluates the file form field, it gets a reference to a temporary file, like 

/home/sfdc/salesforce/sfdc/jsp/form/form1091191222.tmp

How would I take that file reference and do something with it? Like actually get the contents of it so I can create an attachment. Or extract the name of it? Any thoughts are much appreciated as I am a bit stuck. Thanks ahead of time! 

Hey all,

I am working on a multiple file uploader component and have hit a bit of a wall. My component will post each file to a visualfroce page. That visualforce page must in turn read the data that was posted (serialized as binary/base64) and create an attachment out of that. I just get a bit confused about the interplay between binary/base64/blob data. So if you know the answers to any of these questions, please let me know.

 

1) When data is in a regular "file" type form field, and that form is submitted, how is that file data encoded?
 

2) When creating an attachment object would the body be base64/binary/blob?

 

Currently I have a simple class that takes the data passed in the Files field and attempts to convert the content and attach it to the log object i makes.. It runs, but the attachment just displays the raw content of whatever it was passed (in this case I passed in the string (linebreaks removed of course)

TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1b

GFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQg

YnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhY

mxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55I

GNhcm5hbCBwbGVhc3VyZS4=

 

This is my method

 

    public void attachToObject()
    {
        
        Map<string,string> params = ApexPages.currentPage().getParameters();
        string fileData = params.get('Files');
        blob fileContent = blob.valueOf(fileData);      
        Data_Log__c log = new Data_Log__c();          
        log.trace__c = fileData;
        insert log;
        
        Attachment a = new Attachment(parentId = log.id, name='Data', body = fileContent);
        insert a;
        
        jsonString = '[{"delete_url":"NOT AVAILABLE","thumbnail_url":"The File","name":"'+log.id+'","delete_type":"DELETE","url":"theFile","size":'+fileContent.size()+'}]';
        
    }

 

Any help is appreciate. I feel like I have a loose understanding of what I need to do, but it's still a little foggy. If anyone could even just outline the steps I'd need to take to make this happen that would be awesome. 

 

TL;DR: How would I take data posted from a file form field and turn it into an attachment of the same type of file as the original?

Yup, it's me again.

I dunno if I just suck, or if I'm really pushing this parser. I am making a call to facebook to get user data. The user data comes back as JSON. Most of it is simple string data. There are 3 fields that are arrays. Those arrays contain only 2 items (id and name). I have attempted to create the class based on the JSON and deserialize into it. I am receiving another salesforce system error.

 

System.UnexpectedException: Salesforce System Error: 996229906-358 (-433257328) (-433257328) 
An unexpected error has occurred. Your solution provider has been notified. (system)

Here is the json I am attempting to parse (cleaned up a bit)

{
    "id": "XXXXX",
    "name": "XXXXXX XXXXXXX",
    "first_name": "XXXXXX",
    "last_name": "XXXXXX",
    "link": "http://www.facebook.com/XXXXXX",
    "username": "XXXXXX",
    "about": "some data about the person.",
    "birthday": "00/00/0000",
    "hometown": {
        "id": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "name": "Somewhere, New York"
    },
    "location": {
        "id": "XXXXXXXXXXXXXXXXXXXXXXXX",
        "name": "Nowhere, Nevada"
    },
    "bio": "This is some demo text",
    "inspirational_people": [
        {
            "id": "109425469076258",
            "name": "Miyamoto Musashi"
        },
        {
            "id": "112377255503169",
            "name": "Kenshin Himura"
        },
        {
            "id": "135952326470380",
            "name": "Spike Spiegel"
        },
        {
            "id": "146133595436195",
            "name": "Kamina"
        },
        {
            "id": "12534674842",
            "name": "Albert Einstein"
        },
        {
            "id": "184049470633",
            "name": "Bruce Lee"
        }
    ],
    "gender": "male",
    "email": "XXXXXX@XXXXXX.com",
    "timezone": -4,
    "locale": "en_US",
    "verified": true,
    "updated_time": "2011-11-07T21:17:55+0000"
}


OR EASILY PASTEABLE VERSION
{ "id": "XXXXX", "name": "XXXXXX XXXXXXX", "first_name": "XXXXXX", "last_name": "XXXXXX", "link": "http://www.facebook.com/XXXXXX", "username": "XXXXXX", "about": "some data about the person.", "birthday": "00/00/0000", "hometown": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Somewhere, New York" }, "location": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Nowhere, Nevada" }, "bio": "This is some demo text", "inspirational_people": [ { "id": "109425469076258", "name": "Miyamoto Musashi" }, { "id": "112377255503169", "name": "Kenshin Himura" }, { "id": "135952326470380", "name": "Spike Spiegel" }, { "id": "146133595436195", "name": "Kamina" }, { "id": "12534674842", "name": "Albert Einstein" }, { "id": "184049470633", "name": "Bruce Lee" } ], "gender": "male", "email": "XXXXXX@XXXXXX.com", "timezone": -4, "locale": "en_US", "verified": true, "updated_time": "2011-11-07T21:17:55+0000" } 

 

 Here is the code I am trying to run. You should be able to run this in execute anonymous. I have tried running it regular as well (being invoked by the page, which has the class as a controller) and get the same error either way.



string jsonData = '{ "id": "XXXXX", "name": "XXXXXX XXXXXXX", "first_name": "XXXXXX", "last_name": "XXXXXX", "link": "http://www.facebook.com/XXXXXX", "username": "XXXXXX", "about": "some data about the person.", "birthday": "00/00/0000", "hometown": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Somewhere, New York" }, "location": { "id": "XXXXXXXXXXXXXXXXXXXXXXXX", "name": "Nowhere, Nevada" }, "bio": "This is some demo text", "inspirational_people": [ { "id": "109425469076258", "name": "Miyamoto Musashi" }, { "id": "112377255503169", "name": "Kenshin Himura" }, { "id": "135952326470380", "name": "Spike Spiegel" }, { "id": "146133595436195", "name": "Kamina" }, { "id": "12534674842", "name": "Albert Einstein" }, { "id": "184049470633", "name": "Bruce Lee" } ], "gender": "male", "email": "XXXXXX@XXXXXX.com", "timezone": -4, "locale": "en_US", "verified": true, "updated_time": "2011-11-07T21:17:55+0000" }';    
class facebookUser
    {
        public string id;
        public string name;
        public string first_name;
        public string last_name;
        public string link;
        public string username;
        public string about;
        public string birthday;
        public string gender;
        public string email;
        public string timezone;
        public string locale;
        public string verified;
        public string updated_time;
        public list<dataItem> hometown;
        public list<dataItem> location;
        public list<dataItem> inspirational_people;
        
        public facebookUser(string id, string name, string first_name, string last_name, string link, string username, string about, string birthday, string gender, string email, string timeZone, string locale, string verified, string updated_time)
        {
            this.id = id;
            this.name = name;
            this.first_name = first_name;
            this.last_name = last_name;
            this.link = link;
            this.username = username;
            this.about = about;
            this.birthday = birthday;
            this.gender = gender;
            this.email = email;
            this.timeZone = timeZone;
            this.locale = locale;
            this.verified = verified;
            this.updated_time = updated_time;
            this.hometown =  new list<dataItem>();
            this.location =  new list<dataItem>();
            this.inspirational_people = new list<dataItem>();      
        }
    }
    
    class dataItem 
    {
        public string id;
        public string name;
        
        public dataItem(string id, string name)
        {
            this.id = id;
            this.name = name;
        }
    }

//I have tried deserializing to a list, as well as a single object list<facebookUser> d = (list<facebookUser>)JSON.deserialize( jsonData,facebookUser.class);

//This fails too
facebookUser d = (facebookUser)JSON.deserialize( jsonData,facebookUser.class); 

 

Any thoughts would be much appreciated. Thank you.

Hey all,

Being somewhat a java style programming language novice, this is something that escapes me. Say I don't know what kind of data is going to returned via a call to a remote webservice. All I know is that is is going to contain JSON encoded data. I don't know what fields may be there, or if it may also contain nested arrays, etc. Is there a way to just have a generic deserialzation process, without having to cast to a specifc class type? In ColdFusion for example, there is just a deserializeJson function which can take any kind of JSON string as long as it is valid and create a logical structure out of it. You have no need to know ahead of time anything about the structure of the JSON and it is extremely handy, and much more robust than having to manually define a data type for the expected return. Is this possible in Apex as well, or not due to the statically typed nature of the language?

Hey all,

Simple syntax question here. When I need to create an sObject to be inserted, but I don't know what kind it will be ahead of time, how can I create an sObject of a certain type given a name? So say the string contact was passed in, how would I create a contact object? Thanks!

Hey all,

This is similar to my thread from last night, but the question has changed a bit. So I have a visualforce page with a regular old file input. When the form is submitted, it posts to a visualforce page attached to an apex controller. When the apex controller evaluates the file form field, it gets a reference to a temporary file, like 

/home/sfdc/salesforce/sfdc/jsp/form/form1091191222.tmp

How would I take that file reference and do something with it? Like actually get the contents of it so I can create an attachment. Or extract the name of it? Any thoughts are much appreciated as I am a bit stuck. Thanks ahead of time! 

Hey all,

I am working on a multiple file uploader component and have hit a bit of a wall. My component will post each file to a visualfroce page. That visualforce page must in turn read the data that was posted (serialized as binary/base64) and create an attachment out of that. I just get a bit confused about the interplay between binary/base64/blob data. So if you know the answers to any of these questions, please let me know.

 

1) When data is in a regular "file" type form field, and that form is submitted, how is that file data encoded?
 

2) When creating an attachment object would the body be base64/binary/blob?

 

Currently I have a simple class that takes the data passed in the Files field and attempts to convert the content and attach it to the log object i makes.. It runs, but the attachment just displays the raw content of whatever it was passed (in this case I passed in the string (linebreaks removed of course)

TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1b

GFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQg

YnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhY

mxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55I

GNhcm5hbCBwbGVhc3VyZS4=

 

This is my method

 

    public void attachToObject()
    {
        
        Map<string,string> params = ApexPages.currentPage().getParameters();
        string fileData = params.get('Files');
        blob fileContent = blob.valueOf(fileData);      
        Data_Log__c log = new Data_Log__c();          
        log.trace__c = fileData;
        insert log;
        
        Attachment a = new Attachment(parentId = log.id, name='Data', body = fileContent);
        insert a;
        
        jsonString = '[{"delete_url":"NOT AVAILABLE","thumbnail_url":"The File","name":"'+log.id+'","delete_type":"DELETE","url":"theFile","size":'+fileContent.size()+'}]';
        
    }

 

Any help is appreciate. I feel like I have a loose understanding of what I need to do, but it's still a little foggy. If anyone could even just outline the steps I'd need to take to make this happen that would be awesome. 

 

TL;DR: How would I take data posted from a file form field and turn it into an attachment of the same type of file as the original?