歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> Salesforce 自定義頁面並實現手機端自適應

Salesforce 自定義頁面並實現手機端自適應

日期:2017/3/1 12:04:47   编辑:關於Linux

一、使用salesforce實現自定義的“任務簽到”頁面,實現了百度地圖地位功能
這裡寫圖片描述
1)首先必須創建一個自定義頁面
這裡寫圖片描述這裡寫圖片描述這裡寫圖片描述
2)創建salesforece對象
這裡寫圖片描述這裡寫圖片描述
3)創建控制器
這裡寫圖片描述這裡寫圖片描述
4)進入頁面寫代碼
這裡寫圖片描述

二、代碼實現
前台頁面代碼<喎?/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>任務簽到

saf

  • 員工工號: {!u.Employee_number__c }
  • 員工姓名: {!u.Name}
  • 簽到地址:
  • 簽到時間:
  • 經度:
  • 緯度:
<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('
  • ' + '' + '' + this.Name +'|'+(this.Field7__c==undefined?'':this.Field7__c) +'|'+(this.Field2__c==undefined?'':this.Field2__r.Name)+'' + '
  • '); }); $('#ui_results a').click(function(e) { $('#attend_tripApplication').val($(this)[0].innerText); $('#attend_tripApplication').attr('aria-activedescendant',$(this)[0].id); $('#attend_tripApplication').attr('aria-expanded','false'); $('#results').css("display","none"); }); } } $('#attend_sendwork__c').mousedown(function(e){ //$('#attend_sendwork__c').attr("placeholder",""); }); $('#attend_sendwork__c').keyup(function(e) { $('#results2').css("display","block"); $('#attend_sendwork__c').attr('aria-expanded','true'); $('#keyword2').text($('#attend_sendwork__c').val()); if($.isBlank($('#attend_sendwork__c').val())){ $('#results2').css("display","none"); $('#ui_results2').empty(); return; } attendanceController.queryCase($('#attend_sendwork__c').val(), function(result, event){ if (event.status) { $('#ui_results2').empty(); populateLookup2(result); } else if (event.type === 'exception') { $('#attend_sendwork__c') = 'ERROR: ' + event.message; } else { $('#attend_sendwork__c') = 'ERROR: ' + event.message; } }, {escape: true} ); }); function populateLookup2(result){ if(result){ $( result ).each(function() { console.log(this); $('#ui_results2').append('
  • ' + '' + '' + this.CaseNumber + '|'+(this.Subject==undefined?'':this.Subject) +'|'+(this.Account.Name==undefined?'':this.Account.Name)+'|'+(this.Status==undefined?'':this.Status)+'' + '
  • '); }); $('#ui_results2 a').click(function(e) { $('#attend_sendwork__c').val($(this)[0].innerText); $('#attend_sendwork__c').attr('aria-activedescendant',$(this)[0].id); $('#attend_sendwork__c').attr('aria-expanded','false'); $('#results2').css("display","none"); }); } } }); function getMap(){ var geolocation = new BMap.Geolocation(); geolocation.getCurrentPosition(function(r){ if(this.getStatus() == BMAP_STATUS_SUCCESS){ var currentPoint = new BMap.Point(r.point.lng,r.point.lat); new BMap.Geocoder().getLocation(currentPoint,function(rs){ address = rs.address; $("#address ").text(address); $("#signTime").text(getNowFormatDate()); $("#longitudes").text(r.point.lng); $("#latitude").text(r.point.lat); }); } else { alert('failed'+this.getStatus()); } },{enableHighAccuracy: true}) } function getNowFormatDate() { var date = new Date(); var seperator1 = "-"; var seperator2 = ":"; var month = date.getMonth() + 1; var strDate = date.getDate(); if (month >= 1 && month <= 9) { month = "0" + month; } if (strDate >= 0 && strDate <= 9) { strDate = "0" + strDate; } var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds(); return currentdate; } function subData1(){ $("#msgDiv").hide(); $("#bt").toggleClass("disabled"); var userId = "{!u.Employee_number__c } "; var name = "{!u.Name}"; var address = $.trim($("#address").text()); var signTime = $.trim($("#signTime").text()); var longitudes = $.trim($("#longitudes").text()); var latitude = $.trim($("#latitude").text()); var signType = null; var type = "任務簽到"; var signMethod = $("#signMethod").val(); var memo = $("#memo").val(); var sendWork = $('#attend_sendwork__c').attr('aria-activedescendant')==undefined?'':$('#attend_sendwork__c').attr('aria-activedescendant'); var tripApplication= $('#attend_tripApplication').attr('aria-activedescendant')==undefined?'':$('#attend_tripApplication').attr('aria-activedescendant'); var dname = "{!u.UserRole.DeveloperName}"; if(dname == "KFJSY" || dname == "servicebusiness" || dname == "servicetech"){ if($.isBlank(sendWork) && $.isBlank(tripApplication)){ $("#msg").text('派工單或出差申請單不能為空!'); $("#msgDiv").show(); $("#bt").toggleClass("disabled"); return false; } }else{ if($.isBlank(tripApplication)){ $("#msg").text('出差申請單不能為空!'); $("#msgDiv").show(); $("#bt").toggleClass("disabled"); return false; } } if($.isBlank(signMethod)||signMethod=='無'){ $("#msg").text('請選擇簽到方式!'); $("#msgDiv").show(); $("#bt").toggleClass("disabled"); return false; } if($.isBlank(address)){ $("#msg").text("正在定位....,請等當前位置的信息顯示後再點擊‘保存任務簽到信息’!"); $("#msgDiv").show(); $("#bt").toggleClass("disabled"); return false; } attendanceController.saveTask(userId, name, address, signTime, longitudes, latitude, type, signMethod ,memo , sendWork , tripApplication, function(result, event){ $("#bt").toggleClass("disabled"); if(result != null){ $("#dataform").hide(); $("#success").show(); // 移動端跳轉 if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) { setTimeout(sforce.one.navigateToSObject(result),2000); } //PC端跳轉 else { setTimeout(parent.parent.location.href='/'+result,2000); } } }) } </script>

    控制器代碼

    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;
        } 
    
    
    
    }
    Copyright © Linux教程網 All Rights Reserved