forcedotcom / SalesforceMobileSDK-Templates

BSD 3-Clause "New" or "Revised" License
52 stars 56 forks source link

SyncUp Not Working(data is not getting syncedUp to the salesforce server) #412

Closed Dev-Pradeep-NS closed 3 months ago

Dev-Pradeep-NS commented 4 months ago
import { smartstore, net, mobilesync, forceUtil } from "react-native-force";
const syncUp = forceUtil.promiserNoRejection(mobilesync.syncUp);
const syncDown = forceUtil.promiserNoRejection(mobilesync.syncDown);
const registerSoup = forceUtil.promiser(smartstore.registerSoup);
``
const syncContacts = () => {
    const soupSpec = {
        name: "contacts",
        indexes: [
            { path: "Id", type: "string" },
            { path: "FirstName", type: "full_text" },
            { path: "LastName", type: "full_text" },
            { path: "__local__", type: "string" }
        ]
    };

    registerSoup(false, soupSpec.name, soupSpec.indexes, () => {
        console.log("Soup registered successfully.");
    }, (error) => {
        console.log("Error registering soup: " + error);
    });

    smartstore.clearSoup(false, soupSpec.name, () => {
        console.log("Soup cleared successfully.");
    }, (error) => {
        console.log("Error clearing soup: " + error);
    })

    const data = [{
        Id: `local_${(new Date()).getTime()}`,
        FirstName: "Test",
        LastName: "User",
        attributes: { type: "Contact" },
        __locally_created__: true,
        __locally_updated__: false,
        __locally_deleted__: false,
        __local__: true,
    }];

    smartstore.upsertSoupEntries(false, soupSpec.name, data, (res) => {
        console.log("Data upserted to soup.", res);
    }, (error) => {
        console.log("error", error)
    })

    const querySpec = smartstore.buildSmartQuerySpec("SELECT {contacts:Id}, {contacts:FirstName},{contacts:LastName} FROM {contacts}", 100);

    smartstore.runSmartQuery(false, querySpec, (data) => {
        console.log("Data retrieved from soup: ", data);
    }, (error) => {
        console.log("Error querying soup: " + error);
    });

    const fieldlist = ["Id", "FirstName", "LastName", "Title", "Email", "MobilePhone","Department", "LastModifiedDate"];
    const target = { type: "soql", query: `SELECT ${fieldlist.join(",")} FROM Contact` };

    syncDown(false, target, soupSpec.name, { mergeMode: mobilesync.MERGE_MODE.OVERWRITE }, (data) => {
        console.log("Data synced down: ", data);
    }, (error) => {
        console.log("Error syncing down: ", error);
    });

    const fieldListSyncUp = ["FirstName", "LastName", "Title", "Email", "MobilePhone","Department"];
    syncUp(false, {}, soupSpec.name, { mergeMode: mobilesync.MERGE_MODE.OVERWRITE, fieldListSyncUp }, (sync) => {
        console.log("Data synced up: ", sync);
    }, (error) => {
        console.log("Error syncing up: ", error);
    })
}
export default syncContacts;

i have added new contact using upsert, but when i try to syncup the data, getting as Data synced up: {"_soupEntryId": 156, "endTime": 1716295212931, "error": "", "maxTimeStamp": -1, "options": {"mergeMode": "OVERWRITE"}, "progress": 100, "soupName": "contacts", "startTime": 1716295211726, "status": "DONE", "target": {"androidImpl": "com.salesforce.androidsdk.mobilesync.target.CollectionSyncUpTarget", "idFieldName": "Id", "maxBatchSize": 200, "modificationDateFieldName": "LastModifiedDate"}, "totalSize": 0, "type": "syncUp"} where total size is 0

wmathurin commented 4 months ago

I can't see anything wrong with your code. What do you see in the logs? Have you tried running MobileSyncExplorerReactNative in your org? (To create the application, simply do forcereact createwithtemplate --templaterepouri=MobileSyncExplorerReactNative)

Dev-Pradeep-NS commented 4 months ago

@wmathurin I don't know why, suddenly its started working now. Thanks

wmathurin commented 4 months ago

Could you try it to and use your connected app and login to the same org with the same user? I want to make sure it is not a configuration issue.

Dev-Pradeep-NS commented 4 months ago

Could you try it to and use your connected app and login to the same org with the same user? I want to make sure it is not a configuration issue.

Its working fine now

wmathurin commented 4 months ago

What did you have to change? Can we close the issue?

wmathurin commented 3 months ago

It looks like the problem has been resolved. Open a new issue if we misunderstood.