一、使用salesforce實現自定義的“任務簽到”頁面,實現了百度地圖地位功能
1)首先必須創建一個自定義頁面
2)創建salesforece對象
3)創建控制器
4)進入頁面寫代碼
二、代碼實現 saf
前台頁面代碼<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwcmUgY2xhc3M9"brush:sql;">
<script src="{!URLFOR($Resource.jQuery, 'jquery1.9.js')}" ></script>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=XyV6s136GhZs2fbl2gCpkKfG&s=1"></script>
<script>
var $ = jQuery.noConflict();
$(function(){
var dname = "{!u.UserRole.DeveloperName}";
if(dname == "KFJSY" || dname == "servicebusiness" || dname == "servicetech"){
$("#send").show();
$("#trip").show();
}else{
$("#send").hide();
$("#trip").show();
}
});
</script>任務簽到
<script>
(function($){
$.isBlank = function(obj){
return(!obj || $.trim(obj) === "");
};
})(jQuery);
var address;
var signTime;
var method;
var longitudes;
var latitude;
$(document).ready(function() {
//加載地址信息
getMap();
$('#attend_tripApplication').mousedown(function(e){
//$('#attend_tripApplication').attr("placeholder","");
});
//獲取後台數據
$('#attend_tripApplication').keyup(function(e)
{
$('#results').css("display","block");
$('#attend_tripApplication').attr('aria-expanded','true');
$('#keyword').html($('#attend_tripApplication').val());
if($.isBlank($('#attend_tripApplication').val())){
$('#results').css("display","none");
$('#ui_results').empty();
return;
}
attendanceController.queryCustomObject2($('#attend_tripApplication').val(),
function(result, event){
if (event.status) {
$('#ui_results').empty();
populateLookup(result);
} else if (event.type === 'exception') {
$('#attend_tripApplication') = 'ERROR: ' + event.message;
} else {
$('#attend_tripApplication') = 'ERROR: ' + event.message;
}
},
{escape: true}
);
});
function populateLookup(result){
if(result){
$( result ).each(function() {
console.log(this.Field2__c );
$('#ui_results').append('
控制器代碼
global class attendanceController {
public String userId{set;get;}
public String userName{set;get;}
public User u {set;get;}
public attendance__c attend {set;get;}
public static String fId{set;get;}
public List signTypes{set;get;}
public attendanceController (ApexPages.StandardController controller){
u = [select id,Name,Employee_number__c,UserRole.DeveloperName from User where id=:UserInfo.getUserId()];
signTypes = new List();
Schema.DescribeFieldResult fieldResult = attendance__c.attend_type__c.getDescribe();
List ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple){
signTypes.add(f.getValue());
//System.debug(f.getLabel()+'=='+ f.getValue());
}
}
@RemoteAction
global static String saveData(String userId, String name, String address, String signType, String signTime, double longitudes, double latitude, String type){
Datetime dt = System.now();
attendance__c order = new attendance__c();
order.attend_name__c = name;
order.attend_userid__c = userId;
order.attend_address__c = address;
order.attend_longitudes__c = longitudes;
order.attend_latitude__c = latitude;
order.attend_type__c = signType;
order.attend_time__c = signTime;
order.attend_category__c = type;
order.RecordTypeId = [select id,Name from RecordType where Name='考勤管理'].id;
insert order;
return order.id;
}
@RemoteAction
global static String saveTask(String userId, String name, String address, String signTime, double longitudes, double latitude, String type, String signMethod, String memo,String sendWork , String tripApplication){
//userId, name, address, signType, signTime, longitudes, latitude, type, signMethod ,memo , sendWork , tripApplication
System.debug(tripApplication);
Datetime dt = System.now();
attendance__c order = new attendance__c();
order.attend_name__c = name;
order.attend_userid__c = userId;
order.attend_address__c = address;
order.attend_longitudes__c = longitudes;
order.attend_latitude__c = latitude;
order.attend_time__c = signTime;
order.attend_category__c = type;
order.attend_signMethod__c = signMethod;
order.attend_memo__c = memo;
if(String.isNotBlank(tripApplication)){
order.attend_tripApplication__c = tripApplication;
}
if(String.isNotBlank(sendWork)){
order.attend_sendwork__c = sendWork;
}
order.RecordTypeId = [select id,Name from RecordType where Name='任務簽到'].id;
insert order;
return order.id;
}
public PageReference acc(){
System.debug(fId);
return new PageReference('/'+fId);
}
@RemoteAction
global static List queryCustomObject2(String keyword) {
List CustomObject2List = new List();
if (keyword != null && keyword.trim() != '') {
keyword = '%' + keyword + '%';
CustomObject2List = [select id, Name ,Field2__c ,Field2__r.Name,Field8__c, Field7__c, Field4__c from CustomObject2__c where (Name like :keyword or Field7__c like :keyword or Field2__r.Name like :keyword) and CreatedById=:UserInfo.getUserId() order by createdDate desc limit 20 ];
}
return CustomObject2List;
}
@RemoteAction
global static List queryCase(String keyword){
System.debug(keyword);
List caseList = new List();
if (keyword != null && keyword.trim() != '') {
keyword = '%'+keyword +'%';
caseList = [select id, CaseNumber, Subject, Contact.Name, Account.Name, Status from Case where (CaseNumber like :keyword or Subject like :keyword or Account.Name like :keyword) and id in (select CaseId from CaseShare where UserOrGroupId =:UserInfo.getUserId()) order by createdDate desc limit 20 ];
}
return caseList;
}
}