0

Hello team I am retriving user details by id from User object. I am refering to offline code template given by forcereact (forcereact createwithtemplate --templaterepouri=MobileSyncExplorerReactNative) Following is the code with issue that I am facing.

import EventEmitter from "../../events";
import { smartstore, mobilesync, forceUtil } from "react-native-force";

const registerSoup = forceUtil.promiser(smartstore.registerSoup);
const getSyncStatus = forceUtil.promiser(mobilesync.getSyncStatus);
const syncDown = forceUtil.promiserNoRejection(mobilesync.syncDown);
const syncUp = forceUtil.promiserNoRejection(mobilesync.syncUp);
const reSync = forceUtil.promiserNoRejection(mobilesync.reSync);

const syncName = "User-mobileSyncExplorerSyncDown";
let syncInFlight = false;
let lastStoreQuerySent = 0;
let lastStoreResponseReceived = 0;
const eventEmitter = new EventEmitter();

const SMARTSTORE_CHANGED = "smartstoreChanged";

function emitSmartStoreChanged() {
    eventEmitter.emit(SMARTSTORE_CHANGED, {});
}

function syncDownUser() {
    if (syncInFlight) {
        console.log("Not starting syncDown - sync already in fligtht");
        return Promise.resolve();
    }

    console.log("Starting syncDown User");
    syncInFlight = true;
    const fieldlist = [
        "Id",
        "FirstName",
        "LastName",
        "Title",
        "Email",
        "MobilePhone",
        "Department",
        "LastModifiedDate",
    ];
    const target = {
        type: "soql",
        query: `SELECT ${fieldlist.join(",")} FROM User WHERE Id = ?005L0000006cGD1IAMs`
    };
    //https:developer.salesforce.com/docs/atlas.en-us.noversion.mobile_sdk.meta/mobile_sdk/entity_framework_plugin_methods.htm?search_text=syncDown
    //syncDown(isGlobalStore(optional),storeConfig(optional),target,soupName,options,successCB,errorCB)
    return syncDown(
        false,
        target,
        "user",
        { mergeMode: mobilesync.MERGE_MODE.OVERWRITE },
        syncName
    ).then(() => {
        console.log("syncDown completed or failed");
        syncInFlight = false;
        emitSmartStoreChanged();
    }).catch(err => {
        console.log(err)
    });
}

function reSyncUser() {
    if (syncInFlight) {
        console.log("Not starting reSync - sync already in fligtht");
        return Promise.resolve();
    }

    console.log("Starting reSync");
    syncInFlight = true;
    return reSync(false, syncName).then(() => {
        console.log("reSync completed or failed");
        syncInFlight = false;
        emitSmartStoreChanged();
    }).catch(err => {
        console.log(err)
    });
}

function syncUpUser() {
    if (syncInFlight) {
        console.log("Not starting syncUp - sync already in fligtht");
        return Promise.resolve();
    }

    console.log("Starting syncUp User");
    syncInFlight = true;
    const fieldlist = [
        "FirstName",
        "LastName",
        "Title",
        "Email",
        "MobilePhone",
        "Department",
    ];

    const target = {
        type: "soql",
        query: `SELECT ${fieldlist.join(",")} FROM User WHERE Id = ?005L0000006cGD1IAMs`
    };

    return syncUp(false, target, "user", {
        mergeMode: mobilesync.MERGE_MODE.OVERWRITE,
        fieldlist,
    }).then((res) => {
        console.log("syncUp completed or failed", res);
        syncInFlight = false;
        emitSmartStoreChanged();
    }).catch(err => {
        console.log(err)
    });
}

function firstTimeSyncData() {
    console.log("firstTimeSyncData");
    // smartstore.registerSoup(isGlobalStore,soupName,indexSpecs,successCB,errorCB);
    return registerSoup(false, "user", [
        { path: "Id", type: "string" },
        { path: "FirstName", type: "full_text" },
        { path: "LastName", type: "full_text" },
        { path: "__local__", type: "string" },
    ]).then(syncDownUser).catch(err => {
        console.log(err)
    });
}

function syncData() {
    // https:developer.salesforce.com/docs/atlas.en-us.noversion.mobile_sdk.meta/mobile_sdk/entity_framework_global_smartstore.htm?search_text=getSyncStatus
    //getSyncStatus(isGlobalStore, syncId, successCB, errorCB);
    return getSyncStatus(false, syncName).then((sync) => {
        console.log(sync)
        if (sync == null) {
            return firstTimeSyncData();
        } else {
            return reSyncData();
        }
    });
}

function reSyncData() {
    return syncUpUser().then(reSyncUser);
}

I ssue in debugger following is the screenshot of output by getSyncStatus consoleenter image description here

enter image description here

1
  • Looks like you're passing the braces into the ID filter: SELECT Id ... LastModifiedDate FROM User where Id='{0054x000001GBhdAAG}' – EvanSteeleSFDC Dec 18 '20 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.