Question:
Elevate function callback not executing in Wix Backend Code when creating contacts for get the contacted(for trigger emails)
Product:
Wix Velo Editor (Backend Code)
What are you trying to achieve:
I’m trying to create a contact using wix-crm-backend in my backend code. While the elevate function itself is being called (as shown in logs), its callback function is never executed. This means the createOrGetContact function is never reached, although no errors are thrown.
What have you already tried:
- Verified the elevate function is properly imported and called (logs show elevate function type: function)
- Implemented detailed logging throughout the code
- Checked that the basic data insertion works correctly
- Used both wix-crm-backend and wix-auth with proper imports
- Removed nested try-catch blocks to simplify error handling
Additional information:
contactId = await elevate(async () => {
console.log("[createTaskWithContact2] Before createOrGetContact");
const result = await createOrGetContact(data.email, data.firstName);
console.log("[createTaskWithContact2] After createOrGetContact", result);
return result;
});
async function createOrGetContact(email, firstName) {
console.log("[createOrGetContact] Starting with params:", { email, firstName });
try {
console.log("[createOrGetContact] Querying existing contacts");
const query = contacts.queryContacts().eq("info.emails.email", email);
console.log("[createOrGetContact] Query built:", query);
const results = await query.find();
console.log("[createOrGetContact] Query results:", results);
if (results.items?.length > 0) {
const contactId = results.items[0]._id;
console.log("[createOrGetContact] Found existing contact:", contactId);
return contactId;
}
console.log("[createOrGetContact] No existing contact found, creating new one");
const contactInfo = {
emails: [{
email: email,
primary: true,
tag: "MAIN"
}],
name: {
first: firstName
}
};
console.log("[createOrGetContact] Contact info prepared:", contactInfo);
const options = {
allowDuplicates: true,
suppressAuth: true
};
console.log("[createOrGetContact] Attempting to create contact");
const newContact = await contacts.createContact(contactInfo, options);
console.log("[createOrGetContact] New contact created:", newContact);
return newContact._id;
} catch (err) {
console.error("[createOrGetContact] Error:", err);
console.error("[createOrGetContact] Error details:", {
message: err.message,
stack: err.stack,
code: err.code
});
throw err;
}
}
The logs show the elevate function is called, but the “Before createOrGetContact” log never appears.
- The basic data insertion into wixData works correctly
- No errors are thrown during execution
- The elevate function is recognized (typeof shows “function”)
- Using wix-crm-backend for contact creation
- The code flow stops after calling elevate, with no error messages
- The database updates complete successfully, but without contact creation