Syncing Metadata and Layouts on Android
Initializing MetadataSyncManager and LayoutSyncManager
1MetadataSyncManager.getInstance();
2LayoutSyncManager.getInstance();1MetadataSyncManager.getInstance(account);
2LayoutSyncManager.getInstance(account);1MetadataSyncManager.getInstance(account, id);
2LayoutSyncManager.getInstance(account, id);1MetadataSyncManager.getInstance(account, id, store);
2LayoutSyncManager.getInstance(account, id, store);Retrieving Metadata
1public void fetchMetadata(String objectType, Constants.Mode mode, MetadataSyncCallback syncCallback);- objectType
- The Salesforce object whose metadata you’re fetching. For example, “Account” or “Opportunity”.
- mode
- This parameter helps determine the data’s source location. Data retrieval modes include:
- CACHE_ONLY (Android) or SFSDKFetchModeCacheOnly (iOS) - Fetches data from the cache. If cached data is not available, returns null.
- CACHE_FIRST (Android) or SFSDKFetchModeCacheFirst (iOS) - Fetches data from the cache. If cached data is not available, fetches data from the server .
- SERVER_FIRST (Android) or SFSDKFetchModeServerFirst (iOS) Fetches data from the server. If server data is not available, fetches data from the cache. Data fetched from the server is automatically cached.
- syncCallback
- Asynchronous block that is executed when the operation completes. You pass the block’s
implementation or handle to this parameter. This block takes the form of a MetadataSyncCallback interface that defines a single method:
1void onSyncComplete(Metadata metadata);
Mobile SDK passes a Metadata object to this callback method. This object contains the true data model of the requested Salesforce object. You can use this metadata to query specific fields. This class defines properties whose names match the field names in the object’s manifest. Class properties represent all custom fields and customizable standard fields.
Retrieving Layouts (Android)
1public void fetchLayout(String objectAPIName, String formFactor,
2 String layoutType, String mode, String recordTypeId,
3 Constants.Mode syncMode, LayoutSyncCallback syncCallback);- objectAPIName
- (Required) Salesforce object whose layout you’re fetching. For example, “Account” or “Opportunity”.
- formFactor
- (Optional) Form factor of the layout you’re fetching. Supported values are “Large”, “Medium”, and “Small”. If not specified, defaults to “Large”.
- layoutType
- (Optional) Type of layout you’re fetching. Supported values are “Compact” and “Full”. If not specified, defaults to “Full”.
- mode
- (Optional) Record mode of the layout you’re fetching. Supported values are “Create”, “Edit”, and “View”. If not specified, defaults to “View”.
- recordTypeId
- (Optional) Record type whose layout you’re fetching. If not specified, uses the default record type.
- syncMode
- Retrieval mode to use while retrieving data. Supported values are:
- CACHE_ONLY—Fetches data from the cache. If cached data is not available, returns null.
- CACHE_FIRST—Fetches data from the cache. If cached data is not available, fetches data from the server.
- SERVER_FIRST—Fetches data from the server. If server data is not available, fetches data from the cache. Data fetched from the server is automatically cached.
-
- syncCallback
- Callback method that executes asynchronously when the operation completes. You
pass either the method’s implementation or its handle to this parameter. This block
implements the following method prototype:
1void onSyncComplete(String objectAPIName, String formFactor, String layoutType, 2 String mode, String recordTypeId, Layout layout);
Mobile SDK passes an SFLayout object to this callback method. This object contains the true data model of the requested Salesforce object’s layout. You can use this object’s properties to query specific fields.
Behind the scenes, LayoutSyncManager uses a Mobile Sync LayoutSyncDownTarget object to automatically create a SmartStore soup that contains the returned data. This soup includes index specs for retrieving layout data when the device is offline.