function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Elie RodrigueElie Rodrigue 

Google Data API - Spreadsheet - Attempt to de-reference a null object exception


    we've been using the google data api for some time now and a bug in the library did slowed us down in the beginning. We've been able to work around this problem but we think this should be fixed in the library.

To reproduce, create a spreadsheet document then set a value from a1 to g1.


Then run the included test code (dont forget to replace username, login and spreadsheet name with the proper info).


It will crash everytime when updating cell F1 with a null reference exception.


Keep in mind that this is test code only, cells update should be batched and better exception handling should be made but this is just some sample code to reproduce a problem we saw with the library!


  SpreadSheetService service = new SpreadsheetService();
            service.useClientLogin(username, login);
            GoogleData sheets = service.getSpreadsheets();
            //get spreadsheet
            GoogleData feeda = service.getSpreadsheetsTitle(spreadsheetname)

       xmldom.element ssheet = feeda.entries[0];
        //get worksheet in spreadsheet
        string workSheetFeedUrl = SpreadsheetService.getWorksheetFeedUrl(ssheet);
            GoogleData worksheetsFeed = service.getFeed( workSheetFeedUrl );  
        GoogleData.Worksheet worksheet = new GoogleData.Worksheet( worksheetsFeed.entries[0] );
       //get cell data from worksheet in spreadsheet
       string cellFeedUrl = worksheet.getCellFeedUrl();
            // specify range to avoid data overflow
            GoogleData feed = service.getFeedRange( cellFeedUrl ,'A1:L1'); 
            //get the cell values
            list<GoogleData.Cell> cells = worksheet.cellFactory( feed.entries );                 
            for (GoogleData.Cell cel : cells  )
                        cel.content = '5';
                        service.updateCell(worksheet, cel);
            //get the cell values
            feed = service.getFeedRange( cellFeedUrl ,'M1:N1'); 
            cells = worksheet.cellFactory( feed.entries );                 
            for (GoogleData.Cell cel : cells  )
                 if(cel.title == 'M1')
                 System.debug('CELL M1 is: '+cel.content);

Did you solve the problem.
Set remote access tp following urls.
 Setup | Security Controls | Remote Site Settings
Here is the example for acess spreadsheets.