Sharing is caring!
We are Salesforce Experts and we channelize our energy by documenting all the industry-specific technical problems we solve in Salesforce CRM world. Here I am going to explain the Salesforce™ Android Attendance Management App. I was closely involved as a Salesforce Developer. And we have done it successfully.
We live in the age of mobility and there are no signs of any decrease in the number of smartphone users. As per a study conducted by Statista, there will be 2.87 billion smartphone users in 2020. The number of Android phone users are increasing exponentially- all over the globe.
In this changing times, when the smartphone users would like to access information from their devices – anywhere and anytime. There are many app development companies who consider this time as ripe – for a fast and easy way to to keep track of your employees – with a CRM software of the like of Salesforce. This is the reason probably why we chose to create the Salesforce™ Android Attendance Management App, to be used for the employees. First, let us find what is this Attendance Management app all about?
About Salesforce™ Android Attendance Management App
This is an Attendance management app integrated with Salesforce™ Rest API and Google Map API. We have developed this app, for the client organization – to update the daily Attendance with inputs like In-time and Out-Time of the employees. Moreover, the app is accessible through a login that needs Username and Password from the employees. There were some requirements from the client side. Let us now concentrate on the requirements of the client that we had.
The Requirements of the Client
The requirements of the client are:
- The attendance app is about managing attendance for the employees. It should be working on the Android platform and must be managed by Salesforce™.
- There were some conditions that were laid down. The employee is allowed to be logged in, only if they were within 100 meters from the office premises.
- There is the best path from the current location and the user can view the office location and the distance from the office.
- All the employees will have credentials like a username and password. It might be so that the client might not need to login – whenever the app is opened on their respective devices.
- The user cannot log out, once the user is logged in.
- There is a restriction on the time for putting the attendance – only between 8 AM and up to 11:59 PM.
- The employee records will be stored in the Salesforce database.
- There is another feature that counts the total hours of the employees – every day.
Next, is the time to find “What is the solution that we offer?
Our Solution
The employee clicks on ATTENDANCE IN button, a record will be created in Salesforce™ object and while leaving office to click on ATTENDANCE OUT button same record will be updated with Time outfield. The user will not be able to log in and log out from 100 meters away from the company. “What happens, if the user forgets to log out while leaving the office ?”.
Many a time the user may simply forget to log out of the app. In such an event, when the employee forgets to log out while leaving the office – all that the employee needs to do is to open the app – the very next day. No sooner than the user does that, the last record will get updated and total hours will be counted as 5 hours.
This, in other words, means that, when confronted with such a situation, a half day will be counted – for the employees. Another advantage that we can state about the app is that we are using a Username and Password credential flow for directly starting the app. This eliminates the need for any Org. credential.
The app that we have developed is an Android app for attendance management and the record is stored in the Salesforce database. The app is integrated with Google Map and Salesforce™ Rest API in this application.
The below flowchart explains the Salesforce Android Attendance Management app in a nutshell.
Now, let us find what are the solutions that we provide as per the client requirements – stated above.
- Using this app, the user can view the distance between the office and their current location with the best path. This is possible through the integration with the Google API.
- Each and every employee has login credentials – with the help of login feature in the app. However, there is no logout button as per the client requirements. The user will not be able to log out, once logged in because they cannot exit the app – without uninstalling the app.
- We have created login credentials like Username and Password flow – to start the app right away, This ensures that the org, credentials for Salesforce are not required every time.
- First. The user enters the username and password taken from one of the records from the org. and these credentials are taken as what we take as shown in the below screen.
- The employee needs to enter the username and password as in the below figure and click on the login button.
- As we click on the LOGIN button, the ATTENDANCE IN button appears enabled and the ATTENDANCE OUT appears disabled.
- However the user can mark their attendance once in a day between 08:00 AM to 11:59 PM.
- The user just needs to click on the ATTENDANCE OUT button and that ensures a record is generated in Salesforce org. for the specific employee. This is what is displayed by the below screen – shown in the attendances section.
When the user clicks on the ATTENDANCE OUT button then the Out time is displayed in the below figure.
- In this screenshot, you can see google map integration with App.
- It will show the path and distance from the source to a fix destination.
Here are few code snippets
******XML code where you want to show the map
<com.google.android.gms.maps.MapView
android:id=”@+id/map”
android:layout_width=”match_parent”
android:layout_height=”400dp” />
Retrieve location :-
@Override
public void onMapReady(GoogleMap googleMap) {
mGoogleMap=googleMap;
mGoogleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
//Initialize Google Play Services
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(getContext(),
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
//Location Permission already granted
buildGoogleApiClient();
mGoogleMap.setMyLocationEnabled(true);
} else {
//Request Location Permission
checkLocationPermission();
}
}
else {
buildGoogleApiClient();
mGoogleMap.setMyLocationEnabled(true);
}
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mGoogleApiClient.connect();
}
- Now let us find “What happens when when the user is located at 100 m from the company ?”. Then both the above buttons – ATTENDANCE IN and ATTENDANCE OUT are made inactive, as the user is prohibited to login when at a distance – more than the predefined range of 100 m.
Here is a code snippet on how the user is barred from any access to the attendance app when located at a distance more than 100 m – away from the employee’s office.
This code snippet is as follows :
@Override
public void onLocationChanged(Location location) {
boolean connected = false;
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
//we are connected to a network
connected = true;
} else {
connected = false;
runOnUiThread(new Runnable() {
@Override
public void run() {
//perform own function when we are not connected to a network
}
});
}
Double lat1 = location.getLatitude();
Double lon2 = location.getLongitude();
Double caLat1 = cloudAnalogyLocation.getLatitude();// give your location Latitude
Double caLong1 = cloudAnalogyLocation.getLongitude();// give your location Longitude
float[] results = new float[1];
Location.distanceBetween(lat1, lon2,
caLat1, caLong1, results);
distanceDiffrence = Math.round(results[0]);
if (distanceDiffrence < 100 ){
runOnUiThread(new Runnable() {
@Override
public void run() {
//perform own function when under 100m
}
});
}else {
runOnUiThread(new Runnable() {
@Override
public void run() {
//perform own function when out of 100m
}
});
}
}
}
}
- The database in Salesforce will store the time, out time as well as the number of hours calculated for each employee.
Summary
It is an Attendance Management App that is integrated with Salesforce REST API and Google Map API. It is about managing the attendance of employees of the client organization that records the In-time and the Out-time. The app must work on an Android device.
The employee is able to login into the app, with a Username and Password credentials only within a predefined distance of 100 m. It also displays the best path location and the distance from the office the employee is located. All the employee records are saved with details on In time and Out time as well as the number of hours for each of the employees- in a Salesforce database.
Read Also : Challenges of Undertaking Salesforce Integration
Ajay Dubedi
CEO | Founder
Ajay Dubedi, the founder and CEO of Cloud Analogy, is a prominent Salesforce Sales, Service, and Marketing cloud Consultant with a rich expertise in handling challenging business models. Ajay has assisted and implemented solutions in industries comprising Banking, Health Care, Networking, Education, Telecommunication and Manufacturing. Ajay is globally acclaimed for his extensive experience in APEX Programming, VisualForce pages, Triggers, Workflows, Page Layouts, Roles, Profiles, Reports & Dashboards.Hire the best Salesforce Implementation Partner. Choose Cloud Analogy, the world's most preferred Salesforce Implementation Company that provides custom CRM Implementation services.