Skip to content

Instantly share code, notes, and snippets.

@karanrajs
Last active July 25, 2017 01:39
Show Gist options
  • Save karanrajs/6bd1ffc13252b0a22ae0 to your computer and use it in GitHub Desktop.
Save karanrajs/6bd1ffc13252b0a22ae0 to your computer and use it in GitHub Desktop.
Adding Case Comment from Salesforce1
global class QuickCasecomment
{
public QuickCasecomment(ApexPages.StandardController controller) {
}
@RemoteAction
public static boolean CreateComment(Id CaseId,String comment,string publish){
CaseComment newCom = new CaseComment();
newCom.ParentId = CaseId;
newCom.CommentBody =comment;
if(publish == 'true'){
newCom.isPublished = true;
}else{
newCom.isPublished = false;
}
try{
insert newCom;
return true;
}
catch(Exception ex){
return false;
}
}
}
<apex:page standardController="Case" extensions="QuickCasecomment" docType="html-5.0"
standardStylesheets="false" showheader="false" sidebar="false">
<!--Include Stylsheets for the Mobile look and feel -->
<apex:stylesheet value="{!URLFOR($Resource.Mobile_Design_Templates,
'Mobile-Design-Templates-master/common/css/app.min.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.Mobile_Design_Templates,
'Mobile-Design-Templates-master/common/js/jQuery2.0.2.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.Mobile_Design_Templates,
'Mobile-Design-Templates-master/common/js/jquery.touchwipe.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.Mobile_Design_Templates,
'Mobile-Design-Templates-master/common/js/main.min.js')}"/>
<script type='text/javascript' src='/canvas/sdk/js/publisher.js'></script>
<style>
/* default S1 color styles */
.list-view-header, .data-capture-buttons a {
background: -webkit-linear-gradient(#2a93d5,#107abb);
background: linear-gradient(#2a93d5,#107abb);
box-shadow: 0 1px 3px rgba(0,0,0,.2),inset 0 1px 0 rgba(255,255,255,.21);
color: white;
font-weight: bold;
}
.textareastyle {
font-size : 12pt;
}
#resultPage, #searchPage {
padding-bottom: 50px;
}
</style>
<script>
var caseId;
var comment,private;
$(document).ready(function(){
Sfdc.canvas.publisher.publish({name: "publisher.setValidForSubmit", payload:"true"});
});
function caseComment()
{
caseId = '<apex:outputText value="{!Case.Id}"/>';
comment = $('#case_comment').val();
publish = $('#publish').is(':checked');
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.QuickCasecomment.CreateComment}', caseId,comment,publish,
function(result, event){
if(event.status){
Sfdc.canvas.publisher.publish({name: "publisher.close", payload:{ refresh:"true"}});
} else if (event.type === 'exception'){
console.log(result);
} else {
}
});
}
</script>
<apex:form id="form">
<div>
<section class="border-bottom">
<div class="content">
<h3>Public</h3>
<div class="form-control-group">
<div class="form-control form-control-toggle" data-on-label="yes" data-off-label="no">
<input type="checkbox" name="toggle" id="publish"/>
</div>
</div>
</div>
</section>
<section class="border-bottom">
<div class="content">
<h3>Case comment</h3>
<div class="form-control-group">
<div class="form-control form-control-textarea">
<textarea id="case_comment" class="textareastyle" />
</div>
</div>
</div>
</section>
</div>
</apex:form>
<script type='text/javascript'>
Sfdc.canvas.publisher.subscribe({name: "publisher.post", onData:function(e) {
// This subscribe fires when the user hits 'Submit' in the publisher
caseComment();
}});
</script>
</apex:page>
@sivais040
Copy link

I could see Save and Cancel buttons in my VFP. But Save button is not highlighted and it isn't working. I used the same code as above. Please help.

@aimaj
Copy link

aimaj commented Jul 25, 2017

Replace line 13 in QuickCaseCommentVF.html with

<apex:includeScript value="/canvas/sdk/js/publisher.js" />

@sivais040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment