I have a multiple filter query like this:
I want to make the checkboxes be selected and then added to the following query:
var db = Database.Open("RMS") ;
var selectCommand = "SELECT * FROM RMS";
var formSSO = "";
var formCase_Status= "";
var fromDate = "";
var toDate = "";
var SQLSELECT = "SELECT * FROM Admins WHERE Email = #0";
var Email = WebSecurity.CurrentUserName;
var data1 = db.QuerySingle(SQLSELECT, Email);
var Name = data1.Name;
formSSO = Request.QueryString["formSSO"];
formCase_Status = Request["formCase_Status[]"];
fromDate = Request.QueryString["fromDate"];
toDate = Request.QueryString["toDate"];
selectCommand = "SELECT * FROM RMS WHERE Assigned_To = #4";
if(!Request.QueryString["formSSO"].IsEmpty() ) {
selectCommand +=" AND SSO LIKE #0";
}
if(!Request.QueryString["formCase_Status"].IsEmpty() ) {
selectCommand +=" AND Case_Status = #1";
}
if(!Request.QueryString["fromDate"].IsEmpty() ) {
selectCommand +=" AND Created >= #2";
}
if(!Request.QueryString["toDate"].IsEmpty() ) {
selectCommand +=" AND Created <= #3";
}
I can get it working if only one checkbox is selected but my main point is to allow multiple checkboxes to be checked. How can I do this either with JS or Jquery I have tried answers on other qts but they don't quite go with what I am doing. I don't want an alert but a way that I can call all checked values in the select statement.
This is the checkbox:
<li class="form-line form-line-column" id="id_20">
<label class="form-label-top" id="label_20" for="input_20"> Status </label>
<div id="cid_20" class="form-input-wide">
<input type="checkbox" checked="#(Request["formCase_Status[]"] == "In Progress")" name="formCase_Status[]" value="In Progress"> In Progress<br>
<input type="checkbox" checked="#(Request["formCase_Status[]"] == "Pending")" name="formCase_Status[]" value="Pending"> Pending<br>
<input type="checkbox" checked="#(Request["formCase_Status[]"] == "Closed")" name="formCase_Status[]" value="Closed"> Closed<br>
</div>
</li>
Related
I have a trigger that sends an email using a VF template. I'm trying to write a unit test for that code, but keep running into a problem when trying to create the test data.
Here is my test method:
static TestMethod void testQuestionAttachment(){
Id profileId = SYSTEM_ADMIN_PROFILE_ID;
List<User> users = TestUtils.createUsers(profileId, 1);
insert users;
string templateText = '<messaging:emailTemplate subject="{!relatedTo.Name}" recipientType="User" relatedToType="Cutom_Object__c"><messaging:htmlEmailBody ><ul><li>test content</li></ul></messaging:htmlEmailBody></messaging:emailTemplate>';
EmailTemplate template = new EmailTemplate(
developerName = 'TestEmailVFTemplate',
TemplateType= 'visualforce',
FolderId = users[0].Id,
Name = 'TestEmailVFTemplate',
IsActive = true);
template.HtmlValue = templateText;
template.Body = templateText;
System.runAs(users[0]){
insert template;
}
...
And it fails with FIELD_INTEGRITY_EXCEPTION, <messaging:emailTemplate> is required and must be the outermost tag in the markup at line 1 column 1: [Markup].
I really don't understand why this isn't working. I must be missing something...
The issue is with your TemplateType = 'Visualforce'. Instead change it to template.Markup=templateText;. Markup field can be used to assign the body of visualforce template. I tried it in my test class.
Refer below example:
static #isTest void myTest () {
Profile pf = [SELECT Id,Name FROM Profile WHERE Name = 'System Administrator' LIMIT 1];
User usr = new User(
Alias = 'usralias',
Email = 'theuser#email.com',
Emailencodingkey = 'UTF-8',
Lastname = 'user_lastname',
Languagelocalekey = 'en_US',
Localesidkey = 'en_US',
Profileid = pf.Id,
Timezonesidkey = 'America/Los_Angeles',
Username = Math.random() + 'test#testuser.com',
CompanyName = 'the company',
UserRoleId='00E28000000zqCy'
);
insert usr;
string templateText = '<messaging:emailTemplate subject="{!relatedTo.Name}" recipientType="User" relatedToType="Custom_Object__c"><messaging:htmlEmailBody ><ul><li>test content</li></ul></messaging:htmlEmailBody></messaging:emailTemplate>';
EmailTemplate template = new EmailTemplate(DeveloperName = 'TestEmailVFTemplate', TemplateType= 'Visualforce', FolderId = UserInfo.getUserId(),
Name = 'TestEmailVFTemplate',
IsActive = true);
template.Markup=templateText;
System.runAs(usr){
insert template;
}
}
public string GetMemberMessages(string ClubId, string acctno)
{
var data = "";
List<Hashtable> StartList = new List<Hashtable>();
string Conn = GetClubConnectionstring(ClubId);
if (Conn != "Invalid Connection")
{
Sconn = new SqlConnection(Conn);
string lsql ="select * from table where acctno='" + no + "' and datecompl is null order by entrydate desc";
Getdataset(lsql, "tblnotes", ds, ref da, Sconn);
if (ds.Tables["tblnotes"] != null && ds.Tables["tblnotes"].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables["tblnotes"].Rows.Count; i++)
{
Hashtable hashtable = new Hashtable();
for (int j = 0; j < ds.Tables["tblnotes"].Columns.Count; j++)
{
hashtable[ds.Tables["tblnotes"].Columns[j].ToString()] = ds.Tables["tblnotes"].Rows[i][j].ToString();
}
StartList.Add(hashtable);
}
return js.Serialize(StartList);
}
else
{
data = null;
}
}
return js.Serialize(data);
}
<div data-bind="foreach: $root.dataSource">
<table > <tr>
<td>
<span data-bind=" text:notes"</span>>
</td>
</tr>
</table>
</div>
I have MSSQL table, in a field i had insert my messages (ex:Have a good day) with external website linkGoogle.
while i bind the data in my html table like this (have a good day www.google.com) values are shows into view, it working fine. but while i click on that external web linkGoogle. it doesn't navigate google page.
I had tried in SQL server with Html different type to link tags, what are that tag i had put into database, those tag also get visible alone with message and link.
I have an issue with a long form I'm doing. If a user fills out the form, and validation is invalid, it erases everything in the form, and doesn't keep the data in the valid forms. How would I make it so it doesn't erase the data upon pressing submit?
#{
Layout = "~/Pages/_SiteLayout.cshtml";
var db = Database.Open("mtarplspd");
Validation.RequireField("TypeOfIncident", "Type of incident is required.");
Validation.RequireField("FirstName", "Firstname is required.");
Validation.RequireField("LastName", "Lastname is required.");
Validation.RequireField("Rank", "Rank is required.");
Validation.RequireField("Badge", "Badge is required.");
Validation.RequireField("SuspectFirstName", "Suspect firstname is required.");
Validation.RequireField("SuspectLastName", "Suspect lastname is required.");
Validation.RequireField("SuspectCharges", "Suspect charges is required.");
Validation.RequireField("Description", "Description of the incident is required.");
var typeOfIncident = "";
var firstName = "";
var lastName = "";
var rank = "";
var badge = "";
var suspectFirstName = "";
var suspectLastName = "";
var suspectAddress = "";
var suspectCharges = "";
var suspectVehicleModel = "";
var suspectVehiclePlates = "";
var suspectVehicleColor = "";
var officersInvolved = "";
var description = "";
var departmentsInvolved = "";
var firearmDischarged = "";
var typeOfFirearm = "";
var roundsFired = "";
var reason = "";
var userId = 0;
var dateTime = "";
var ErrorMessage = "";
if (IsPost) {
typeOfIncident = Request.Form["TypeOfIncident"];
firstName = Request.Form["FirstName"];
lastName = Request.Form["LastName"];
rank = Request.Form["Rank"];
badge = Request.Form["Badge"];
suspectFirstName = Request.Form["SuspectFirstName"];
suspectLastName = Request.Form["SuspectLastName"];
suspectAddress = Request.Form["SuspectAddress"];
suspectCharges = Request.Form["SuspectCharges"];
suspectVehicleModel = Request.Form["SuspectVehicleModel"];
suspectVehiclePlates = Request.Form["SuspectVehiclePlates"];
suspectVehicleColor = Request.Form["SuspectVehicleColor"];
officersInvolved = Request.Form["OfficersInvolved"];
description = Request.Unvalidated["Description"];
departmentsInvolved = Request.Form["DepartmentsInvolved"];
firearmDischarged = Request.Form["FirearmDischarged"];
typeOfFirearm = Request.Form["TypeOfFirearm"];
roundsFired = Request.Form["RoundsFired"];
reason = Request.Form["Reason"];
userId = WebSecurity.CurrentUserId;
dateTime = DateTime.Now.ToString("d MMM yyyy h:mm:ss");
if (ErrorMessage == "" && Validation.IsValid()) {
var insert = "INSERT INTO Reports (Type, FirstName, LastName, Rank, Badge, SuspectFirstName, SuspectLastName, SuspectAddress, SuspectCharges, SuspectVehicleModel, SuspectVehiclePlates, SuspectVehicleColor, OfficersInvolved, Description, DepartmentsInvolved, FirearmDischarged, TypeOfFirearm, RoundsFired, Reason, UserId, DateTime)" + "VALUES (#0, #1, #2, #3, #4, #5, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20)";
db.Execute(insert, typeOfIncident, firstName, lastName, rank, badge, suspectFirstName, suspectLastName, suspectAddress, suspectCharges, suspectVehicleModel, suspectVehiclePlates, suspectVehicleColor, officersInvolved, description, departmentsInvolved, firearmDischarged, typeOfFirearm, roundsFired, reason, userId, dateTime);
Response.Redirect("~/Pages/Reports/Incident/Default");
}
}
}
You need to restore the value for each form control, eg:
<input type="text" name="FirstName" value="#Request.Form["FirstName"]" />
My company has an app that they got off of the app exchange(Note: before I started) that allowed you to follow or unfollow large number of cases/accounts/opportunities etc in salesforce.com. Supposedly it worked before and now it isn't working. I need an idea of what is wrong with the code for each button. If I can't fix them, any ideas for a replacement app? The app is no longer on the app exchange any more.
here's the code for the follow button:
{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")}
//EDIT THE FOLLOWING LINE TO ALTER THE CODE FOR OTHER OBJECTS. USE THE PICKLISTS ABOVE TO SELECT FIELD TYPE = $ObjectType AND THE OBJECT NAME THEN REPLACE "$ObjectType.Case" WITH YOUR NEW OBJECT NAME
var records = {!GETRECORDIDS( $ObjectType.Case)};
function LBox() {
var box = new parent.SimpleDialog("steve"+Math.random(), true);
parent.box = box;`
box.setTitle("Follow Records");
box.createDialog();
box.setWidth(220);
box.setContentInnerHTML("<img src='/img/loading32.gif' alt='' /> Running");
box.setupDefaultButtons();`
box.show();
}
function CBox(){
box.setContentInnerHTML("You are now following "+follow_count+" records<br /><br />Close");
}
if (records[0] == null) {
alert("Please select at least one record.");
}
else {
var follow_count = 0;
LBox();
for (var i = 0; i < records.length; i++){
var fol=new sforce.SObject("EntitySubscription");
fol.ParentId = records[i];
fol.SubscriberId = '{!User.Id}';
try{
sforce.connection.create([fol]);
follow_count++;
}
catch(e){
alert(e);
}
}
CBox();
}
here's the unfollow button:
{!REQUIRESCRIPT("/soap/ajax/18.0/connection.js")}
// EDIT THE FOLLOWING LINE TO ALTER THE CODE FOR OTHER OBJECTS. USE THE PICKLISTS ABOVE TO SELECT FIELD TYPE = $ObjectType AND THE OBJECT NAME THEN REPLACE "$ObjectType.Case" WITH YOUR NEW OBJECT NAME
var records = {!GETRECORDIDS( $ObjectType.Case)};
// display running message popup
function LBox() {
var box = new parent.SimpleDialog("steve"+Math.random(), true);
parent.box = box;`
box.setTitle("Unfollow Records");
box.createDialog();
box.setWidth(220);
box.setContentInnerHTML("<img src='/img/loading32.gif' alt='' /> Running");
box.setupDefaultButtons();
box.show();
}
// display output message
function CBox(){
if (unfollow_count < records.length)
box.setContentInnerHTML("You have now unfollowed "+unfollow_count+" records. You were not following the other selected records. <br /><br />Close");
else
box.setContentInnerHTML("You have now unfollowed "+unfollow_count+" records. <br /><br />Close");
}
if (records[0] == null) {
alert("Please select at least one record.");
}
else {
var unfollow_count = 0;`
LBox();
try {
// find following records
var searchstring = "SELECT Id FROM EntitySubscription WHERE (ParentId IN (";
for (var i = 0; i < records.length - 1; i++) {
searchstring += "'" + records[i] + "',";
}
searchstring += "'" + records[records.length - 1] + "') AND SubscriberId ='{!User.Id}')";
var resultRecords = sforce.connection.query(searchstring).getArray("records");
// delete following records
var recordIds = [];
for (var i = 0; i < resultRecords.length; i++) {
recordIds.push(resultRecords[i].Id);
unfollow_count++;
}
sforce.connection.deleteIds(recordIds);
} catch(e) {
alert(e);
}
CBox();
}
The first error message has to do with permissions, I don't get this error because I have admin rights, the second error is only on the account tab's button. I'm more worried about the permissions problem, is there anything there about permissions. Any help is great!
I think the issue is a throttle in SFDC, you are limited to following only a certain number of records per user. If this app was designed as you described to mass-follow records, it's possible your hitting that throttle, which is kind of the impression I get from the error your co-worker is receiving about at most 1000, also if it worked before, it would make sense that you have maxed out a limit for the org/user
Queries on EntitySubscription by users who aren't system admins must contain a LIMIT. If you change the query code in the button to the following it should work:
// find following records
var searchstring = "SELECT Id FROM EntitySubscription WHERE (ParentId IN (";
for (var i = 0; i < records.length - 1; i++) {
searchstring += "'" + records[i] + "',";
}
searchstring += "'" + records[records.length - 1] + "') AND SubscriberId ='{!User.Id}') LIMIT 1000";
I use c# and ef4.
I have a Model with an Entity with two proprieties int Id and string Title.
I need to write an ESQL query that is able to return bool TRUE if Id and Title are present in the DataSource. Please note Id is a PrimaryKey in my data storage.
Any idea how to do it?
You can do it by each code-snippets below:
1)
using (YourEntityContext context = new YourEntityContext ()) {
var queryString =
#"SELECT VALUE TOP(1) Model FROM YourEntityContext.Models
As Model WHERE Model.Id = #id AND Model.Title = #title";
ObjectQuery<Model> entityQuery = new ObjectQuery<Model>(queryString, context);
entityQuery.Parameters.Add(new ObjectParameter("id", id));
entityQuery.Parameters.Add(new ObjectParameter("title", title));
var result = entityQuery.Any();
}
2)
using (YourEntityContext context = new YourEntityContext ()) {
ObjectQuery<Model> entityQuery =
context.Models
.Where("it.Id = #id AND it.Title = #title"
, new ObjectParameter("id", id)
, new ObjectParameter("title", title)
);
var result = entityQuery.Any();
}
3)
var context = new YourEntityContext();
using (EntityConnection cn = context.Connection as EntityConnection) {
if (cn.State == System.Data.ConnectionState.Closed)
cn.Open();
using (EntityCommand cmd = new EntityCommand()) {
cmd.Connection = cn;
cmd.CommandText = #"EXISTS(
SELECT M FROM YourEntityContext.Models as M
WHERE M.Id == #id AND Model.Title = #title
)";
cmd.Parameters.AddWithValue("id", _yourId);
cmd.Parameters.AddWithValue("title", _yourTitle);
var r = (bool)cmd.ExecuteScalar();
}
}
4)
using (YourEntityContext context = new YourEntityContext ()) {
var queryString =
#"EXISTS(
SELECT M FROM YourEntityContext.Models as M
WHERE M.Id == #id AND Model.Title = #title
)";
ObjectQuery<bool> entityQuery = new ObjectQuery<bool>(queryString, context);
entityQuery.Parameters.Add(new ObjectParameter("id", id));
entityQuery.Parameters.Add(new ObjectParameter("title", title));
var result = entityQuery.Execute(MergeOption.AppendOnly).FirstOrDefault();
}
4 is the best way I suggest you. Good lock
What javad said is true, but another way is:
bool result = entities.Any(x=>x.Id == id && x.Title == title) ;
In fact because Id is primary key, DB prevent from occurrence of this more than one time .