function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RickoT1031RickoT1031 

Search for old tickets by subject on case create

Heya,


So we have a "QuickTicket" page which basically has some of the  things we require on a ticket on one page then the workflow brings us to the ticket edit page after saving.  I wanted to add a search button to search for other tickets with a similiar subject right on the search page. but it does not referesh with the results. I basically took this code from another page I made which just does searches so I know the code works I just dont understand why my page wont refresh... see below for the vf and apex code.

 

Thanks in advance!

 

Ticket Quickstart Apex Code

public with sharing class ITTicketQuickStart { private final Case c; public ITTicketQuickStart(ApexPages.StandardController stdController) { this.c = (Case)stdController.getRecord(); //Set default page values c.Priority = '3 - Normal'; c.Impact__c = 'Individual'; c.Severity__c = 'Request Low'; c.Origin = 'Phone'; } public PageReference save() { String emailaddress = 'servicedesk@g-6e4a7xxymd5g3ajubobvhnda6.in.salesforce.com'; User loggedInUser = [Select firstname,id,contactId,Contact.AccountId,Email from User where id = :UserInfo.getUserId()]; User sdadmin = [select id, name from user where alias = 'SDAdmin']; insert c; Contact vcon = [select id,firstname,name,Accountid,EMail from Contact where id=:c.ContactId]; c.AccountId = vcon.accountid; c.ownerid = loggedinuser.id; Account alookup = [select id, name, Service_Desk__c, TicketsRecordType__c, Email_From_Name__c from Account where id = :c.AccountId]; c.RecordTypeId = alookup.TicketsRecordType__c; c.ERPRequestedBy__c = loggedInUser.Id; Case clookup = [select id, ownerid, contactid, casenumber, Description, Priority, Impact__c, Subject from case where id = :c.id]; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> toAddresses= new List<String>{vcon.Email}; mail.setToAddresses(toAddresses); String[] BccAddresses = new String[] {loggedInUser.Email}; mail.setBccAddresses(BccAddresses); mail.setReplyTo(emailaddress); mail.setSenderDisplayName(alookup.Email_From_Name__c); mail.setSubject('Ticket (#' + clookup.casenumber + ') Created'); mail.setPlainTextBody(vcon.firstname + ',\n\nYour ticket (#' + clookup.casenumber + ') has been successfully submitted for service. ' + 'A technician will be contacting you shortly.' + '\n\nPriority: ' + clookup.priority + '\nDescription: ' + clookup.description + '\n\nThank you,\n' + Userinfo.getName() + '\n' + alookup.Email_From_Name__c + '\n' + alookup.Service_Desk__c + '\n\nPLEASE DO NOT DELETE ANYTHING BELOW THIS LINE WHEN REPLYING TO THIS E-MAIL.\ncaseid: ' + clookup.id); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); insert new Task(subject = 'Email: ' + mail.getSubject(),Description = mail.getPlainTextBody(),status = 'Completed',IsVisibleInSelfService = True,whatid = c.id,ownerid = sdadmin.id,ActivityDate = utility.DateNow()); return new PageReference('/'+ c.id + '/e?retURL=%2F' + c.id); } public Case CaseResult { get; set; } public List<Case> results {get;set;} public string searchText {get;set{if (value.length() < 3){searchText = '%%';} else {searchText = '%' + value + '%';}}} public PageReference doSearch() { //results.clear(); //if (searchText == '%%'){results= new list<Case>();} else { results = [SELECT Id,CaseNumber,Subject,CreatedById,Priority,Status,Contact.Name,Account.Name,CreatedDate,OwnerId FROM Case where(subject like :searchText)]; return null; } }

 

IT Ticket Quickstart VForce

 

<apex:page standardController="Case" extensions="ITTicketQuickStart"> <style> textarea { width:50%; height:400%; } </style> <style> textbox { width:50%; height:400%; } </style> <apex:sectionHeader title="Create a Ticket" subtitle="All Fields below are required"/> <apex:form > <apex:pageblock > <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Submit"/> </apex:pageBlockButtons> <apex:PageBlockSection title="Contact Info and Severity/Priority" columns="2" collapsible="false"> <apex:inputField value="{!case.Priority}" Required="True"/> <apex:inputField value="{!case.ContactID}" Required="True" id="ContactName" /> <apex:inputField value="{!case.Severity__c}" Required="True" /> <apex:inputField value="{!case.Origin}" Required="True"/> <apex:inputField value="{!case.Impact__c}" Required="True"/> </apex:PageBlockSection> <apex:PageBlockSection title="Details" columns="1" collapsible="false"> <apex:outputLabel style="padding:0px 5px;font-size:95%;font-weight:bold;font-family: 'Verdana','Geneva',sans-serif;" value="Enter search string to begin" for="searchText" /> <apex:inputText id="searchText" value="{!searchText}" size="50" /> <apex:commandButton value="Search" action="{!doSearch}" rerender="results" status="status" /> <apex:actionStatus id="status" startText="requesting..." /> <apex:inputField value="{!case.Description}" Required="True"/> </apex:PageBlockSection> <apex:pageBlockSection title="Case Search Results" id="results" columns="1" collapsible="false"> <apex:pageBlockTable value="{!results}" var="CaseResult" id="thePBTable"> <apex:column headerValue="Ticket Number"><a href="/{!CaseResult.id}">{!CaseResult.CaseNumber}</a></apex:column> <apex:column headervalue="Status">{!CaseResult.Status}</apex:column>> <apex:column headervalue="Subject">{!CaseResult.Subject}</apex:column> <apex:column headervalue="Priority">{!CaseResult.Priority}</apex:column> <apex:column headervalue="Contact Name">{!CaseResult.Contact.Name}</apex:column> <apex:column headervalue="Date Created">{!CaseResult.CreatedDate}</apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageblock> </apex:form> </apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
RickoT1031RickoT1031

So I figured everything out, apparently because I have required fields, it was seeing the button click and the missing fields as not meeting the criteria to submit.  I had to write my own custom code to validate the fields on submit and make them not required to perform the search.

 

I am all set, if anyone wants code for this pm me or reply to this thread.

All Answers

bob_buzzardbob_buzzard

Have you tried adding some debug to check that your search is completing successfully?

 

 

RickoT1031RickoT1031
Not quite sure how I can do that honestly, as I am still new to sf dev.   What kind of things can I add to my code to make sure my search is working properly?
RickoT1031RickoT1031

So I figured everything out, apparently because I have required fields, it was seeing the button click and the missing fields as not meeting the criteria to submit.  I had to write my own custom code to validate the fields on submit and make them not required to perform the search.

 

I am all set, if anyone wants code for this pm me or reply to this thread.

This was selected as the best answer