Created
November 13, 2018 12:31
-
-
Save simpluslabs/c9205de3f57c8cb887576ff4caf1a37c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit: function(component, event, helper) { | |
// Prepare a new record from template | |
component.find("contactRecordCreator").getNewRecord( | |
"Contact", // sObject type (objectApiName) | |
null, // recordTypeId | |
false, // skip cache? | |
$A.getCallback(function() { | |
var rec = component.get("v.newContact"); | |
var error = component.get("v.newContactError"); | |
if(error || (rec === null)) { | |
console.log("Error initializing record template: " + error); | |
return; | |
} | |
console.log("Record template initialized: " + rec.sobjectType); | |
}) | |
); | |
}, | |
handleSaveContact: function(component, event, helper) { | |
if(helper.validateContactForm(component)) { | |
component.set("v.simpleNewContact.AccountId", component.get("v.recordId")); | |
component.find("contactRecordCreator").saveRecord(function(saveResult) { | |
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") { | |
console.log('record saved successfully'); | |
var resultsToast = $A.get("e.force:showToast"); | |
resultsToast.setParams({ | |
"type": "SUCCESS", | |
"title": "Saved", | |
"message": "The record was saved." | |
}); | |
resultsToast.fire(); | |
} else if (saveResult.state === "INCOMPLETE") { | |
// handle the incomplete state | |
console.log("User is offline, device doesn't support drafts."); | |
} else if (saveResult.state === "ERROR") { | |
// handle the error state | |
console.log('Problem saving contact, error: ' + JSON.stringify(saveResult.error)); | |
} else { | |
console.log('Unknown problem, state: ' + saveResult.state + ', error: ' + JSON.stringify(saveResult.error)); | |
} | |
}); | |
} | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment