Redwoods Car Insurance is a fictional end-user mobile application for iOS built using Swift and the Mobile SDK for iOS. The application shows a rich user experience for an end-user on iOS while demonstrating key features of the SDK version 7.0.
- Prerequisites
- Source Control Setup
- Salesforce Metadata Setup
- Salesforce Manual Setup
- Xcode Setup
- Additional Resources
In order to experience, and experiment with this sample app you'll need:
- A working installation of Git.
- An Apple Computer with Xcode 10.1 (or possibly higher) installed.
- If you want to install the sample app on a physical iOS device, you'll need an Apple Developer Account.
- A Salesforce Scratch Org. (More info on that later)
This project makes use of git submodules, in addition to Xcode build dependencies to incorporate the SDK. This means you must not only clone this repository, but the submodule repositories as well. If you have not yet cloned this repository, this clone command will clone not only this repo, but the submodules as well.
git clone --recurse-submodules https://github.com/trailheadapps/redwoods-insurance.git
If you've already cloned this repository, please initialize the submodules using this command
git submodule update --init --recursive
The redwoods-insurance-salesforce
folder in this repository contains most of the necessary metadata to setup a Salesforce Scratch Org for use with this mobile app. However, there are several manual steps you must accomplish using the Salesforce UI to finalize your scratch org with this metadata:
-
Set up your environment. Follow the steps in the Quick Start: Salesforce DX Trailhead Project.
-
If you haven't already done so, authenticate with your dev hub org and provide it with an alias (devHub):
sfdx auth:web:login -d -a devHub
-
cd to Salesforce Org Setup folder in a command line:
cd redwoods-insurance-salesforce
-
Create a scratch org and provide it with an alias (redwoods-insurance):
sfdx force:org:create -s -f config/project-scratch-def.json -a redwoods-insurance
-
Push the app to your scratch org:
sfdx force:source:push
-
Create a new Role named
redwoods-insuranceAdjuster
:sfdx force:data:record:create -s userRole -v Name='redwoods-insuranceAdjuster'
Take note of the UserRoleId that's returned, it will start with '00E'.
-
Find the default users' ID and assign that user the new Role:
sfdx force:user:display
Identify the users' Id, it will start with '005':
-
Set the default User's Role to the newly created role:
sfdx force:data:record:update -s user -i <<<USER-ID>>> -v "userRoleId=<<<USER-ROLE-ID>>>"
-
Assign the redwoods_insurance_mobile permission set to the default user:
sfdx force:user:permset:assign -n redwoods_insurance_mobile
-
Open your new scratch org, to the communities setup page in a web browser:
sfdx force:org:open -p /lightning/setup/SetupNetworks/home
The mobile application is configured to allow only Customer Community Login users to log in. You'll need to manually setup, activate and publish a community through the UI.
- Create the Community:
- If opening the org didn't take you to the 'All Communities' setup page, navigate there via Setup -> Feature Settings -> Communities -> All Communities.
- Click the 'New Community' Button.
- Select the 'Customer Account Portal' experience.
- Click 'Get Started'.
- When prompted, enter 'Redwoods Car Insurance' as the name.
- Click 'Create'.
- Allow the community wizard to finish.
- Adding a Profile for community users:
- In the upper left-hand menu, select 'Salesforce Setup' which will open in a new tab/window.
- Using either the menu, or the quick find bar, navigate to Profiles:
- Click 'New Profile'.
- Select 'Customer Community Login User' as the profile to clone from.
- Give the profile the name 'redwoods_insurance_mobileUser'.
- Click 'Save'.
- On the newly created profile screen, click the 'Edit' button.
- Under 'Administrative Permissions' find the checkbox labeled: 'API Enabled' and check it.
- Click 'Save'.
- Add the profile to your Community:
- Navigate to your original tab -- where you're configuring your community -- and using the menu on the left, click 'Administration'.
- Using the menu on the left hand side of the screen, select 'Members'
- On the members page, use the drop down to select 'Customer' from the list of available profile groups. If you do not see 'redwoods_insurance_mobileUser' listed, please ensure you created the profile as a clone of 'Customer Community Login User' profile.
- Select 'redwoods_insurance_mobileUser' on the left side, and click the 'Add' button.
- Scroll to the bottom of the page and click 'Save'
- Activate the Community:
- Using the menu on the left, click 'Settings'.
- You'll see the URL of your community listed just above an 'Activate Community' button. Copy that url as you'll need it later.
- Click the 'Activate Community' button.
- Publish the Community:
- Using the drop-down menu in the upper left, click on the 'Builder' workspace.
- Click the 'Publish' button in the upper right of the Community Builder.
- Click 'Publish' to confirm.
- Create a Community User:
- From the Builder screen, click the upper left drop down menu, and select 'Salesforce Setup'.
- Using the App Launcher, select 'Service'.
- Click on the 'Accounts' tab, and create a new account. Populate the information as you see fit.
- From your newly created Account's detail page, click 'New' button on the Contacts related list view.
- Create a new contact.
- From the Account detail page, click on the name of your newly created contact to navigate to the Contact detail page.
- Click the disclosure icon in the upper right of the contact's Highlights Panel, and select 'Enable Customer User'.
- Make sure to fill in an email address you can check, as you'll need to verify your user's email before you can login.
- Select 'Customer Community Login' as the User License.
- Select 'redwoods_insurance_mobileUser' as the Profile.
- Populate all other required fields.
- Click 'Save', and click 'OK' to acknowledge that the user will receive an email.
- Finalize your Customer Community Login User:
- You'll soon receive an email from Salesforce welcoming your user to the community. Click the provided link to verify your email and set your user's password.
- Assign your new Customer Community Login User the 'Redwoods-Insurance Mobile' permission set:
- Navigate to Setup -> Users -> Permission Sets.
- Click on 'Redwoods-Insurance Mobile'.
- Click on 'Manage Assignments'.
- Click on 'Add Assignment'.
- Click the checkbox next to your Redwoods-Insurance Mobile' username.
- Click 'Assign'.
- Click 'Done'.
Note: Salesforce Communities Users can only authenticate to the community they're part of. Thus, when writing apps with the Salesforce mobile SDK for iOS it's best practice to manually set the login host for your application as part of your build.
- Open the file
info.plist
found in the 'Supporting Files' group in Xcode. - Locate the key
SFDCOAuthLoginHost
, which by default sayslogin.salesforce.com
. Edit the default value, replacing it with the community url you copied down earlier. Please note, while the community url likely starts withhttps://
DO NOT include thehttps://
portion of the URL in thisplist
value.
Note: The source ships with a valid connected app consumer key. However, if you'd like to use your own, ensure it has the following oAuth scopes:
- Access your basic information (id, profile, email, address, phone)
- Access and manage your data (api)
- Provide access to your data via the Web (web)
- Access and manage your Chatter data (chatter_api)
- Perform requests on your behalf at any time (refresh_token, offline_access)
Once you have established your connected app, copy the consumer key into the TrailIsurance/bootconfig.plist file using Xcode.
To load the project in Xcode, open the redwoods-insurance.xcodeproj file.
This project should build and run on the simulator 'out of the box' if the submodules have been properly initialized. However, if you would like to run this on a physical iOS device, you'll need to specify your Team name in the project's settings.
Note: If you're running this in the simulator, and everything seems really slow, check to ensure you've not accidentally toggled 'Slow Animations' in the Debug menu of the simulator app. It's hotkey is
Cmd-t
, so it can be accidentally toggled fairly easily.
For more information on the Salesforce Mobile SDK for iOS check out these resources: