The Leads SDK provides an embeddable button for iOS apps to make lead capture from native apps incredibly easy. Leads are stored in the Salesforce Sales Cloud for sales teams to quickly action and drive further sales from any mobile application.
To run the example project, clone the repo, and run pod install
from the Example directory first.
leads-sdk is available through CocoaPods. To install it, simply add the following line to your Podfile:
use_frameworks!
pod "leads-sdk"
or, to fetch the latest
use_frameworks!
pod 'leads-sdk' :git => 'https://github.com/quintonwall/leads-sdk.git'
Within your storyboard, drag a standard button from the palette, then change its type to lead button
Then, in the properties editor, add the Salesforce org id provided by your Salesforce administrator. The return url is not really used in mobile apps. You can leave it set to the default. The pod currently does not use it, but future releases may support a webview sort of confirmation.
To add fields to the LeadsButton, create an outlet to your ViewController, and import the leads_sdk module.
import leads_sdk
class ViewController: UIViewController {
@IBOutlet weak var myLeadButton: LeadsButton!
LeadsButton is preconfigured to support the typical standard lead fields (fist name, last name, email, company, city, and state). When using standard fields, Salesforce administrators do no need to create a custom web-to-lead field. As long as web-to-lead is enabled in the Salesforce org, that is all you need.
var d :Dictionary = [String: String]()
//populate the standard fields
d[Leads.StandardFields.FIRST_NAME] = "Quinton"
d[Leads.StandardFields.LAST_NAME] = "Wall"
d[Leads.StandardFields.EMAIL] = "[email protected]"
d[Leads.StandardFields.COMPANY] = "Salesforce"
d[Leads.StandardFields.CITY] = "San Francisco"
d[Leads.StandardFields.STATE] = "CA"
Salesforce Leads also support custom fields. Your administrator will need to use the web-to-lead feature within Salesforce to generate the unique custom field Ids. If you are only collecting standard lead fields, there is no need to generate a web-to-lead form. Once you have these field ids, simply add them to the dictionary object.
//populate custom fields
d["00NG000000CZxsC"] = "MyCustomValue"
Once you have your fields Dictionary create, add the dictionary to the LeadsButton and call sendLead(). SendLead also checks to ensure that you have specified an Org Id throwing an error if it is not set correctly.
myLeadButton.formFields = d
do {
try myLeadButton.sendLead()
}
catch Leads.LeadError.NoOrgId {
print("no org id set!")
}
catch Leads.LeadError.CommsFailure {
//comms problem
}
catch {
//unexpected error
}
Three UI themes have been included in LeadsButton:
You can add a theme with the following command. If you do not specify any theme, you can set colors and styles manually.
LeadsThemeManager.applyTheme(LeadsTheme.[Default | Dark | Graphical], leadsbutton: myLeadButton)
For a complete example of using the LeadsButton, please check out the sample app included in this project.
Quinton Wall, @quintonwall
leads-sdk is available under the MIT license. See the LICENSE file for more info.