# Save & update records in objects

There is always a need to ensure records are kept up to date and have the latest contact details, sales figures, or case details. The Salesforce *Save* or *Update* methods allow you to update records in Salesforce directly from your mobile device.

## Examples and code snippets

{% hint style="warning" %}
Examples are based on test data in a Jigx demo Salesforce environment. Copying the sample code must be adjusted to represent your own Salesforce environment.
{% endhint %}

{% columns %}
{% column %}

<figure><img src="/files/mcTQGSQ6QUKHLUjOUgsO" alt="Update opportunity amount" width="188"><figcaption><p>Update opportunity amount</p></figcaption></figure>
{% endcolumn %}

{% column %}
This example shows how to update a Salesforce Opportunity record. From the list of opportunities using the `onPress` action the jig opens a form showing the opportunity name and amount. Edit the amount field. Using the Salesforce Providers `save` method the opportunity is updated.
{% endcolumn %}
{% endcolumns %}

:::CodeblockTabs

{% tabs %}
{% tab title="Salesforce-opp-update.jigx" %}

```yaml
title: Opportunity Update
description: Update the opportunity Amount
type: jig.default

header:
  type: component.jig-header
  options:
    children:
      type: component.image
      options:
        source:
          uri: https://images.unsplash.com/photo-1509228627152-72ae9ae6848d?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80   
    height: medium
  
datasources:
  opp-amount:
    type: datasource.sqlite
    options:
      provider: DATA_PROVIDER_LOCAL
      entities:
        - entity: Opportunity
      query: SELECT id, '$.Name', '$.Amount' FROM [Opportunity] WHERE id = @id
      queryParameters:
        id: =@ctx.jig.inputs.id
    
children:
  - type: component.form
    instanceId: opp-form
    options:
      children:              
        - type: component.text-field
          instanceId: id
          options:
            initialValue: =@ctx.jig.inputs.id
            isHidden: true
            label: id   
        - type: component.text-field
          instanceId: Name
          options:
            label: Opportunity Name
            initialValue: =@ctx.datasources.opp-amount.Name
        - type: component.number-field
          instanceId: Amount
          options:
            label: Amount 
            initialValue: =@ctx.datasources.opp-amount.Amount
       
actions:
  - children:
      - type: action.submit-form
        options:
          title: Update Amount
          provider: DATA_PROVIDER_SALESFORCE
          entity: Opportunity
          formId: opp-form
          method: save
          data:
            id: =@ctx.components.id.state.value
            Amount: =@ctx.components.Amount.state.value
          onSuccess: 
            type: action.go-back  
```

{% endtab %}

{% tab title="salesforce-opp-list.jigx" %}

```yaml
title: List Salesforce opportunities
type: jig.default

header:
  type: component.jig-header
  options:
    height: medium
    children:
      type: component.image
      options:
        source:
          uri: https://images.unsplash.com/photo-1454165804606-c3d57bc86b40?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1170&q=80

onFocus:
  type: action.action-list
  options:
    actions:
      - type: action.sync-entities
        options:
          provider: DATA_PROVIDER_SALESFORCE
          entities:
            - entity: Opportunity

datasources:
  salesforce-opp-list: 
    type: datasource.sqlite
    options:
      provider: DATA_PROVIDER_LOCAL
      entities:
        - entity: Opportunity
      query: SELECT id, '$.Name', '$.Amount' FROM [Opportunity]
                 
children:
  - type: component.list
    instanceId: account-list
    options:
      data: =@ctx.datasources.salesforce-opp-list
      
      item:
        type: component.list-item
        options:
          title: =@ctx.current.item.Name
          leftElement:
            element: avatar
            text: SF
          rightElement: 
            element: value
            text:
              format:
                currency: USD
                numberStyle: currency
              text: =@ctx.current.item.Amount
          onPress: 
            type: action.go-to
            options:
              linkTo: salesforce-opp-update
              inputs:
                id: =@ctx.current.item.id
                entity: Opportunity
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.jigx.com/examples/readme/data-providers/salesforce/save-_-update-records-in-objects.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
