+ Start a Discussion
JaggyJaggy 

Calling salesforce REST API from EXTJS

Hi,

 

I am using following code to insert an account but it doesnt work. Can anyone tell me what I am missing here.

<apex:page >
    <link rel="stylesheet" type="text/css" href="{!URLFOR($Resource.extjs,'extjs-4.1.0/resources/css/ext-all.css')}"/>
    <script type="text/javascript" src="{!URLFOR($Resource.extjs, 'extjs-4.1.0/ext-all.js')}"></script>

    <script type="text/javascript">
        Ext.define('Jaggy.Account', {
            extend: 'Ext.data.Model',
            fields: [
                'id',
                'name',
                'type',
                'industry',
                'active__c',
                'website',
                'owner'
            ],
            proxy: {
                type: 'rest',
                url: 'https://ap12.salesforce.com/services/proxy',
                headers: {
                    'SalesforceProxy-Endpoint': 'https://ap12.salesforce.com/services/data/v25.0/sobjects/Account',
                    'Authorization': 'OAuth {!GETSESSIONID()}',
                    'Accept': 'application/json'
                },
                format: 'json',
                reader: {
                    type: 'json',
                    root: 'records'
                }
            }
        });
        
        var acc = Ext.create('Jaggy.Account', {
            name: 'Mandeep'
        });
        
        acc.save(); 
      
    
    </script>
</apex:page>