我创建了一个移动应用程序页面salesforce mobilesdk,当我刷新页面时它没有刷新错误是什么?代码在下面,因为我已经获取了潜在客户并转换了它们,并且我成功转换了它们,但是在转换了潜在客户之后,即使我刷新了页面,该潜在客户也再次显示在潜在客户列表中,还有什么错误?
潜在客户
<script type="text/javascript">
var $j = jQuery.noConflict();
var client = new remotetk.Client();
Force.init(null,null,client,null);
var Leads = new SObjectData();
Leads.errorHandler = displayError;
$j(document).ready(function() {
regBtnClickHandlers();
getAllLeads();
});
function getAllLeads() {
Leads.fetch('soql','SELECT id, firstName, lastName, company, phone from Lead LIMIT 100',function() {
showLeads(Leads.data());
});
}
function showLeads(records) {
$j('#cList').empty();
$j.each(Leads.data(),
function() {
var newLi = $j('<li></li>');
var newLink = $j('<a id="' +this.Id+ '" data-transition="flip">' +this.FirstName+ ' '+this.LastName+ '</a>');
newLink.click(function(e) {
e.preventDefault();
$j.mobile.showPageLoadingMsg();
$j('#fName').val(Leads.findRecordById([this.id]).FirstName);
$j('#lName').val(Leads.findRecordById([this.id]).LastName);
$j('#company').val(Leads.findRecordById([this.id]).Company);
$j('#phone').val(Leads.findRecordById([this.id]).Phone);
$j('#leadId').val(Leads.findRecordById([this.id]).Id);
$j('#error').html('');
$j.mobile.changePage('#detailpage', {changeHash: true});
});
newLi.append(newLink);
newLi.appendTo('#cList');
// x++;
});
$j.mobile.hidePageLoadingMsg();
$j('#cList').listview('refresh');
}
function addUpdateLead(e){
e.preventDefault();
var cId = $j('#leadId').val();
var record = Leads.findRecordById(cId);
if(record == null) { //new record
record = Leads.create();
}
record.FirstName = $j('#fName').val();
record.LastName = $j('#lName').val();
record.Company = $j('#company').val();
record.Phone = $j('#phone').val();
Leads.sync(record,successCallback);
}
function deleteLead(e){
e.preventDefault();
Leads.remove(Leads.findIndexById($j('#leadId').val()),successCallback);
}
//Convert Lead into Account, Contact and Opportunity
function convertLead(){
var leadToConvert = $j('#leadId').val();
//Invoke JavaScript Remoting function convertLead in Apex controller to convert Lead into Account, Contact and Opportunity
SalesforceMobileApp.convertLead(leadToConvert,
//Show the details of new Account created by convet Lead process
function(result, e){
$j.mobile.showPageLoadingMsg("b", "Converting Lead ...", true);
$j('#acctName').val(result.Name);
$j('#acctType').val(result.Type);
$j('#acctId').val(result.Id);
$j.mobile.hidePageLoadingMsg();
$j.mobile.changePage('#convertedpage', {changeHash: true});
getUser(result);
getContact(result);
getOpportunity(result);
});
}
//Get and show the User Name associated with the Account Owner Id
function getUser(result){
var acctOwnerId = result.OwnerId;
//Invoke JavaScript Remoting function getUser in Apex controller to get the User Name associated with the Account Owner Id
SalesforceMobileApp.getUser(acctOwnerId,
//Show the User Name associated with the Account Owner Id
function(result, e){
$j.mobile.showPageLoadingMsg("b", "Converting Lead ...", true);
$j('#acctOwner').val(result.Name);
$j.mobile.hidePageLoadingMsg();
$j.mobile.changePage('#convertedpage', {changeHash: true});
});
}
//Get and show the details of new Contact created by convet Lead process
function getContact(result){
var newacctId = result.Id;
//Invoke JavaScript Remoting function getContact in Apex controller to get the details of new Contact created by convet Lead process
SalesforceMobileApp.getContact(newacctId,
//Show the details of new Contact created by convet Lead process
function(result, e){
$j.mobile.showPageLoadingMsg("b", "Converting Lead ...", true);
$j('#contFirstName').val(result.FirstName);
$j('#contLastName').val(result.LastName);
$j('#contTitle').val(result.Title);
$j('#contPhone').val(result.Phone);
$j('#contEmail').val(result.Email);
$j('#contId').val(result.Id);
$j.mobile.hidePageLoadingMsg();
$j.mobile.changePage('#convertedpage', {changeHash: true});
});
}
//Get and show the details of new Opportunity created by convet Lead process
function getOpportunity(result){
var newacctId = result.Id;
//Invoke JavaScript Remoting function getOpportunity in Apex controller to get the details of new Opportunity created by convet Lead process
SalesforceMobileApp.getOpportunity(newacctId,
//Show the details of new Opportunity created by convet Lead process
function(result, e){
$j.mobile.showPageLoadingMsg("b", "Converting Lead ...", true);
$j('#opptyName').val(result.Name);
$j('#opptyStageName').val(result.StageName);
$j('#opptyCloseDate').val(result.Close_Date__c);
$j('#opptyAmount').val(result.Amount);
$j('#opptyId').val(result.Id);
$j.mobile.hidePageLoadingMsg();
$j.mobile.changePage('#convertedpage', {changeHash: true});
});
}
function refreshThePage(){
$.mobile.loadPage("/apex/new");
}
function successCallback(r){
getAllLeads();
$j.mobile.changePage('#listpage', {changeHash: true});
}
function displayError(e){
console.log(e);
$j('#error').html(e[0].message);
}
function regBtnClickHandlers() {
$j('#add').click(function(e) {
e.preventDefault();
$j.mobile.showPageLoadingMsg();
$j('#fName').val('');
$j('#lName').val('');
$j('#company').val('');
$j('#phone').val('');
$j('#error').html('');
$j('#leadId').val('');
$j.mobile.changePage('#detailpage', {changeHash: true});
$j.mobile.hidePageLoadingMsg();
});
$j('#save').click(function(e) {
addUpdateLead(e);
});
$j('#delete').click(function(e) {
deleteLead(e);
});
$j('#convertlead').click(function(e) {
convertlead(e);
});
}
</script>
</head>
<body>
<div data-role="page" data-theme="b" id="listpage">
<div data-role="header" data-position="fixed">
<h2>Leads</h2>
<a href='#' id="add" class='ui-btn-right' data-icon='add' data-theme="b">Add Lead</a>
</div>
<div data-role="content" id="leadList">
<ul id="cList" data-filter="true" data-inset="true" data-role="listview"
data-theme="c" data-dividertheme="b">
</ul>
</div>
</div>
<div data-role="page" data-theme="b" id="detailpage">
<div data-role="header" data-position="fixed">
<a href='#listpage' id="back2leadList" class='ui-btn-left' data-icon='arrow-l' data-direction="reverse" data-transition="flip">Back</a>
<h1>Lead Details</h1>
</div>
<div data-role="content">
<div data-role="fieldcontain">
<label for="fName">First Name:</label>
<input name="fName" id="fName" />
</div>
<div data-role="fieldcontain">
<label for="lName">Last Name:</label>
<input name="lName" id="lName" />
</div>
<div data-role="fieldcontain">
<label for="company">Company:</label>
<input name="company" id="company"/>
</div>
<div data-role="fieldcontain">
<label for="phone">Phone:</label>
<input name="phone" id="phone"/>
</div>
<h2 style="color:red" id="error"></h2><br/>
<input type="hidden" id="leadId" />
<button id="save" data-role="button" data-icon="check" data-inline="true" data-theme="b" class="save">Save</button>
<button id="delete" data-role="button" data-icon="delete" data-inline="true" class="destroy">Delete</button>
<a href="#convertedpage" id="convertLead" data-theme="b" data-role="button" data-icon="star" data-direction="reverse" data-transition="flip" class='ui-btn-left' onClick="convertLead();" >Convert Lead</a>
</div>
</div>
<div data-role="page" data-theme="b" id="convertedpage">
<div data-role="header" data-position="fixed" data-theme="b">
<h1>Converted Lead Detail</h1>
<a href='#listpage' id="back2Home" data-role="button" class='ui-btn-left' data-icon="home" data-transition="slide" onClick="refreshThePage();">Back to Home</a>
</div>
<!-- Show detal of new Account created by convert Lead process -->
<div data-role="content">
<a href="#" data-role="button" data-icon="star" data-iconpos="left" style="background: #236EBC; color: white;">Account</a>
<div data-role="fieldcontain">
<table>
<tr>
<th>Account Owner</th>
<td><output name="acctOwner" id="acctOwner"></output></td>
</tr>
<tr>
<th>Account Name</th>
<td><output name="acctName" id="acctName"></output></td>
</tr>
<tr>
<th>Account Type</th>
<td><output name="acctType" id="acctType"></output></td>
</tr>
</table>
</div>
<h2 style="color:red" id="error"></h2><br/>
<input type="hidden" id="acctId" />
</div>
<hr size="2"/>
<!-- Show detal of new Contact created by convert Lead process -->
<div data-role="content">
<a href="#" data-role="button" data-icon="star" data-iconpos="left" style="background: #236EBC; color: white;">Contact</a>
<div data-role="fieldcontain">
<table>
<tr>
<th>First Name</th>
<td><output name="contFirstName" id="contFirstName"></output></td>
</tr>
<tr>
<th>Last Name</th>
<td><output name="contLastName" id="contLastName"></output></td>
</tr>
<tr>
<th>Title</th>
<td><output name="contTitle" id="contTitle"></output></td>
</tr>
<tr>
<th>Phone</th>
<td><output name="contPhone" id="contPhone"></output></td>
</tr>
<tr>
<th>Email</th>
<td><output name="contEmail" id="contEmail"></output></td>
</tr>
</table>
</div>
<h2 style="color:red" id="error"></h2><br/>
<input type="hidden" id="contId"/>
</div>
<hr size="2"/>
<!-- Show detal of new Opportunity created by convert Lead process -->
<div data-role="content">
<a href="#" data-role="button" data-icon="star" data-iconpos="left" style="background: #236EBC; color: white;">Opportunity</a>
<div data-role="fieldcontain">
<table>
<tr>
<th>Opportunity Name</th>
<td><output name="opptyName" id="opptyName"></output></td>
</tr>
<tr>
<th>Opportunity Stage</th>
<td><output name="opptyStageName" id="opptyStageName"></output></td>
</tr>
<tr>
<th>Opportunity Close Date</th>
<td><output name="opptyCloseDate" id="opptyCloseDate"></output></td>
</tr>
<tr>
<th>Opportunity Amount</th>
<td><output name="opptyAmount" id="opptyAmount"></output></td>
</tr>
</table>
</div>
<h2 style="color:red" id="error"></h2><br/>
<input type="hidden" id="opptyId" />
</div>
<center>
<a href='#listpage' id="back2Home" data-role="button" class='ui-btn-left' data-icon="home" data-transition="slide" onClick="refreshThePage();">Back to Home</a>
</center>
</div>
</body>