-
ChatterFeed
-
4Best Answers
-
0Likes Received
-
0Likes Given
-
14Questions
-
30Replies
can any one help me out with testclass for visualforce custom controller class
Hi guys. I am learning force.com and currently i am using developer account so I necessarily don't have to write testclass for a now but when i will be on project i have to write down test method to deployee it to production envirionment from developer environment. I have written some test classes for triggers but i don't know how to write testmethod for visualforce custome controller class. my code is successfully working but I also want to write test class with cover more than 75%. i am pasting my code bellow can you guys help me out with its test class.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public with sharing class searchPatientAccount {
// the soql without the order and limit
private String soql {get;set;}
// the collection of contacts to display
public List<Account> accounts {get;set;}
// the current sort direction. defaults to asc
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField {
get { if (sortField == null) {sortField = 'name'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public searchPatientAccount() {
soql = 'select a.id, a.name, a.accountnumber,a.phone from account a where a.name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
accounts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String accountname = Apexpages.currentPage().getParameters().get('accountname');
String accountnumber = Apexpages.currentPage().getParameters().get('accountnumber');
String phone = Apexpages.currentPage().getParameters().get('phone');
// String technology = Apexpages.currentPage().getParameters().get('technology');
soql = 'select a.id, a.name, a.accountnumber,a.phone from account a where a.name != null';
if (!accountname.equals(''))
soql += ' and a.name LIKE \''+String.escapeSingleQuotes(accountname)+'%\'';
if (!accountnumber.equals(''))
soql += ' and a.accountnumber LIKE \''+String.escapeSingleQuotes(accountnumber)+'%\'';
if (!phone.equals(''))
soql += ' and a.phone LIKE \''+String.escapeSingleQuotes(phone)+'%\'';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> technologies {
get {
if (technologies == null) {
technologies = new List<String>();
Schema.DescribeFieldResult field = Contact.interested_technologies__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
technologies.add(f.getLabel());
}
return technologies;
}
set;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- :) :) :) :) :)
- July 20, 2012
- Like
- 0
<apex:inputfile> issues...Body is always null
I'm having the hardest time doing something that should be relatively simple. I have a VF component that is displaying a list of custom objects and a penel that will display details about each object. For each child object in the details, I want the ability to upload an attachment. I have used a wrapper class to help with this. The issue is I am getting a VF error: Required field missig [Body] : [Body] every time.
Here is the relevant section of VF
<apex:repeat value="{!formWraps}" var="fWrap"> <tr> <td style="font-weight:bold"><apex:outputField value="{!fWrap.form.Form_Template__r.Name}"/></td> <td><apex:inputfield value="{!fWrap.form.Collected_Paper_Form__c}"/></td> <td><apex:inputfield value="{!fWrap.form.Attached_in_SalesForce__c}"/></td> <td><apex:outputLabel value="File: " for="file" style="font-weight:bold"/> <apex:inputText value="{!fWrap.attachment.Name}"/> <apex:inputFile value="{!fWrap.attachment.Body}" filename="{!fWrap.attachment.Name}"/></td> </tr> </apex:repeat>
<apex:pageblockButtons location="bottom"> <apex:commandButton value="Save Changes" action="{!saveChanges}"/> </apex:pageblockButtons>
Here are the controller properties, methods, and wrapperClass that apply
public Contact con {get;set;} public Event_Affiliation__c currentEvent {get;set;} private list<Form__c> forms {get;set;} public list<formWrapper> formWraps {get;set;} .......... Id eventId = System.currentPageReference().getParameters().get('event');
currentEvent = [Select Id, Name, Pre_Registered__c, Attended__c, Fishing_Partnership_Event__c,
Fishing_Partnership_Event__r.Name, (Select Id, Name From Attachments), Fishing_Partnership_Event__r.Location__c,
Fishing_Partnership_Event__r.Event_Date__c From Event_Affiliation__c Where Id = : eventId]; forms = [Select Id, Name, Form_Template__c, Form_Template__r.Name, Collected_Paper_Form__c, Attached_in_SalesForce__c,
Attachment_ID__c, Event_Affiliation__c From Form__c Where Event_Affiliation__c =: currentEvent.Id]; for(Form__c f : forms){ formWraps.add(new formWrapper(f)); } ............... public PageReference saveChanges(){ for(formWrapper wrap : formWraps){ wrap.attachment.Name = wrap.form.Form_Template__r.Name + ' ' + con.Name; wrap.attachment.ParentId = wrap.form.Event_Affiliation__c; wrap.attachment.OwnerId = UserInfo.getUserId(); wrap.attachment.Body = fileBody; system.debug('attachment Name: ' + wrap.attachment.Name);
system.debug('attachment OwnerID: ' + wrap.attachment.OwnerId);
system.debug('attachment ParentID: ' + wrap.attachment.ParentId); system.debug('attachment Body: ' + wrap.attachment.Body); insert wrap.attachment; } try{ update currentEvent; update healthInts; }catch(Exception e){ ApexPages.addMessages(e); } PageReference page = new PageReference('/' + currentEvent.Id); page.setRedirect(true); return page; } .................. /*WRAPPER CLASS*/ public class formWrapper{ public Form__c form {get;set;} public string attachmentID {get;set;} public Attachment attachment {get;set;} public formWrapper(Form__c f){ form = f; attachmentID = ''; attachment = new Attachment(); } public formWrapper(Form__c f, string aID, Attachment a){ form = f; attachmentID = aID; attachment = a; } }
Here is the Debug logs...for some reason the body of the attachment is not being bound from the input file to the attachment within the wrapper class, all the other attributes are being set....I've been pouding my head on the wall for a while with this one
09:58:45.341 (341358000)|SYSTEM_METHOD_ENTRY|[63]|System.debug(ANY) 09:58:45.341 (341376000)|USER_DEBUG|[63]|DEBUG|attachment Name: Signed Consent Form Johnny Appleseed 09:58:45.341 (341384000)|SYSTEM_METHOD_EXIT|[63]|System.debug(ANY) 09:58:45.341 (341403000)|METHOD_ENTRY|[64]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341422000)|METHOD_EXIT|[64]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341466000)|SYSTEM_METHOD_ENTRY|[64]|String.valueOf(Object) 09:58:45.341 (341480000)|SYSTEM_METHOD_EXIT|[64]|String.valueOf(Object) 09:58:45.341 (341492000)|SYSTEM_METHOD_ENTRY|[64]|System.debug(ANY) 09:58:45.341 (341502000)|USER_DEBUG|[64]|DEBUG|attachment OwnerID: 005d00000011zsxAAA 09:58:45.341 (341510000)|SYSTEM_METHOD_EXIT|[64]|System.debug(ANY) 09:58:45.341 (341524000)|METHOD_ENTRY|[65]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341542000)|METHOD_EXIT|[65]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341620000)|SYSTEM_METHOD_ENTRY|[65]|String.valueOf(Object) 09:58:45.341 (341640000)|SYSTEM_METHOD_EXIT|[65]|String.valueOf(Object) 09:58:45.341 (341661000)|SYSTEM_METHOD_ENTRY|[65]|System.debug(ANY) 09:58:45.341 (341676000)|USER_DEBUG|[65]|DEBUG|attachment ParentID: a0gK00000011xBeIAI 09:58:45.341 (341686000)|SYSTEM_METHOD_EXIT|[65]|System.debug(ANY) 09:58:45.341 (341701000)|METHOD_ENTRY|[66]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341721000)|METHOD_EXIT|[66]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341734000)|SYSTEM_METHOD_ENTRY|[66]|String.valueOf(Object) 09:58:45.341 (341741000)|SYSTEM_METHOD_EXIT|[66]|String.valueOf(Object) 09:58:45.341 (341753000)|SYSTEM_METHOD_ENTRY|[66]|System.debug(ANY) 09:58:45.341 (341762000)|USER_DEBUG|[66]|DEBUG|attachment Body: null 09:58:45.341 (341769000)|SYSTEM_METHOD_EXIT|[66]|System.debug(ANY)
I know this is bits and pieces, and totaly not best practices with SOQL in for loops and such, but that wouldnt cause the Body of the attachment to be null. I figure I want to get it working before worrying about optimizing the code.
Any help would be greatly appreciated. Just hoping there is something obvious that I am missing that someone could point out. PLEASE HELP
Chris
- cduncombe44
- December 06, 2012
- Like
- 0
Rerender with jqGrid issue. PLEASE HELP
I am pulling my hair out with this one.
I have a few jqGrids on my VF page. I now have a select list Im using to try to filter one of the jqGrids. If I hardcode an ID in the controller to filter with, it works, and the grid reloads, but if i try to use the parameter that I am passing in via an ActionFunction, the logs show my parameter as null.
jquery change method
jQuery('[id$=htmlSelect]').change(function(e) { filterPage(this.value); var commGrid = jQuery('#commList'); commGrid.trigger("reloadGrid"); });
Action Function
<apex:actionFunction name="filterPage" action="{!makeNewCommJSON}" > <apex:param name="acc" value="" assignTo="{!stringID}"/>
</apex:actionFunction>
Controller function to filter list
public void makeNewCommJSON(){ Id acc = system.currentPageReference().getParameters().get('acc'); system.debug('accountid Parameter: ' + acc); system.debug('stringID Value: ' + stringID); list<Commitment__c> comms = [select id, Name, Due_Date__c, Status__c, Account__c, Account__r.Name, Owner__c, Owner__r.Alias from Commitment__c where Owner__c = :Userinfo.getuserid() and Status__c != 'Completed' and Account__c =: acc]; //and Account__c = '001M000000JKGcNIAX']; if(comms != null && comms.size() > 0) { newCommJSON = '{"page":"1","total":"' + ( 1 + ( comms.size() / 10 )) + '","records":"' + String.valueOf(comms.size()) + '","rows":['; for(Commitment__c c : comms ) { newCommJSON += '{"id":"' + c.id + '","cell":['; newCommJSON += JqGridDataController.parseCell(c.Due_Date__c); newCommJSON += JqGridDataController.parseCell('<a href=/'+ c.Account__c + '>'+ c.Account__r.Name +'</a>') newCommJSON += JqGridDataController.parseCell(c.Owner__r.Alias); newCommJSON += JqGridDataController.parseCell('<a href=/'+ c.Id + '>' + c.Name + '</a>'); newCommJSON = newCommJSON.subString(0,newCommJSON.length() - 1); newCommJSON += ']},'; } newCommJSON = newCommJSON.subString(0,newCommJSON.length() - 1); newCommJSON += ']}'; } else { //no records were retrieved newCommJSON = '{"page":"1","total":1,"records":"' + String.valueOf('0') + '","rows":['; newCommJSON += '],"userdata":{"amount":3220,"tax":342,"total":3564,"name":"Totals:"}}'; } DashIdCarrier.commJSONString = newCommJSON; }
This all works fine, but as I said, when I check the logs, the parameter isnt being passed properly. see below
17:56:00.082 (82279000)|SYSTEM_METHOD_EXIT|[33]|String.valueOf(Object) 17:56:00.082 (82302000)|SYSTEM_METHOD_ENTRY|[33]|System.debug(ANY) 17:56:00.082 (82313000)|USER_DEBUG|[33]|DEBUG|accountid Parameter: null 17:56:00.082 (82320000)|SYSTEM_METHOD_EXIT|[33]|System.debug(ANY) 17:56:00.082 (82341000)|METHOD_ENTRY|[34]|01pM00000009QmO|CommitmentDashboardController.__sfdc_stringID() 17:56:00.082 (82377000)|METHOD_EXIT|[34]|01pM00000009QmO|CommitmentDashboardController.__sfdc_stringID() 17:56:00.082 (82395000)|SYSTEM_METHOD_ENTRY|[34]|System.debug(ANY) 17:56:00.082 (82403000)|USER_DEBUG|[34]|DEBUG|stringID Value: null 17:56:00.082 (82410000)|SYSTEM_METHOD_EXIT|[34]|System.debug(ANY)
If i dont use the parameter, and hard code an ID of an account, it works fine and the grid reloads perfectly. Am i doing something wrong? What am I missing here, why is the parameter not being passed properly?
Any help would be hugely appreciated.
Chris
- cduncombe44
- November 29, 2012
- Like
- 0
Activity Count Trigger not working on Update
I have created an activity count trigger for a custom object based on a few forum posts. I have a few custom objects, process__c, and Process_Step__c. As you might imagine my Proccess__c is made up of 1 or more Process _Step__c.
This trigger works fine for inset and for update only if you are changing the task to meet the criteria (WhatId is a process_Step__c and Status = 'Completed').
It does not however work to decrement the activity count if the task is updated and no longer meets the criteria. I know I dont account for this, I am stuck in how to check for this and how to handle it.
Any help would be greatly appreciated.
trigger UpdateActivityCountForProcessAndSteps on Task (after insert, after update) { List<Process_Step__c> stepUpdateList=new List<Process_Step__c>(); List<Process_Step__c> stepList=[select id, Process__c, Process__r.Activity_Count__c, Activity_Count__c from Process_Step__c]; List<Process__c> processUpdateList=new List<Process__c>(); List<AggregateResult> TasksPerStep = new List<AggregateResult>(); TasksPerStep=[Select count(Id),WhatId, Status From Task Where id=:Trigger.new and What.Type = 'Process_Step__c' and Status = 'Completed' group by WhatId, Status]; for(Integer i=0;i<TasksPerStep.size();i++) { for(Process_Step__c step : stepList) { if(step.id==TasksPerStep[i].get('WhatId')) { step.Activity_Count__c = (Integer)TasksPerStep[i].get('expr0') + step.Activity_Count__c; step.Process__r.Activity_Count__c = (Integer)TasksPerStep[i].get('expr0') + step.Process__r.Activity_Count__c; stepUpdateList.add(step); processUpdateList.add(step.Process__r); } } } update stepUpdateList; update processUpdateList; }
Thanks in advance,
Chris
- cduncombe44
- August 20, 2012
- Like
- 0
IE9 issue with JS and actionFunction
I really hope someone can help me because I have been banging my head over this one for far too long. I have a VF page to override the contact view. Its tabbed and most tabs are made of their own cutom component.
On this particular component, I have a list of wrapperClass custom objects so users can mass copy Insurances (custom object). The popup allows them to choose which contact to copy the insurances to, and when you click select, the JS calls a function on the parent page that simply calls an actionFunction to insert the new records, and refreshes the list and adds a page message. Works great with every browser except IE. I really wish I could just force users to not use IE, but not an option at this point.
I have looked over the boards and tried every suggestion I could find from previous posts. I have taken out the showHeader="false", I have tried nesting the entire page in <body> tags, I tried immediate="true" in the actionFunction, I have added the following to the controller
Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
Nothing seems to work. It is actually closing the window, but it is not calling the actionFunction and rerendering the page at all. I just dont know how to fix this please help
Popup VF Page
<apex:form id="form"> <table cellpadding="5px" cellspacing="0" style="margin: 10px;"> <tr> <td colspan="3" align="center"><apex:commandButton value="Select" action="{!save}" oncomplete="fun();" rerender="panel1,panel2"/> <apex:commandButton value="Cancel" onclick="window.top.close();" /></td> </tr> <tr> </tr> <tr> <td width="50px"></td> <td width="400px" class="cts_th">Which Family Member(s) would you like to copy selected Insurances to?</td> <td width="50px"></td> </tr> <tr> <td width="20px"></td> </tr> <tr> <td width="20px"></td> </tr> <tr></tr> </table> <table cellpadding="5px" cellspacing="0" style="margin: 10px;"> <apex:repeat value="{!conWrappers}" var="con"> <tr> <td width="50px" align="right"><apex:inputCheckbox value="{!con.checked}" id="check"/></td> <td width="200px">{!con.cntact.Full_Name__c}</td> </tr> </apex:repeat> </table> <apex:outputpanel id="panel2"> <apex:pageblock id="block"> <apex:inputHidden value="{!saved}" id="saved"/> <apex:inputHidden value="{!sel}" id="sel"/> </apex:pageblock> </apex:outputpanel> </apex:form> <script> function fun() { var item = document.getElementById('page:form:block:saved'); if(item.value == 'false'){ alert('You didn\'t choose anyone'); } if(item.value == 'true') { Close(); } } function Close() { var winMain=window.opener; if (null==winMain) { winMain=window.parent.opener; } item = document.getElementById('page:form:block:sel'); var sel = item.value; winMain.userSelected(sel); } </script>
Snippets from Parent Page
<apex:actionfunction name="copyInsurance" action="{!copyInsurance}" immediate="true" rerender="insurances,table,dataTable"/> <apex:inputhidden value="{!sel}" id="selected"/> <script> function userSelected(sel) { var tag = document.getElementById('{!$Component.com.block.section.selected}'); tag.value = sel; copyInsurance(); closePopup(); } function closePopup() { if (null!=newWin) { newWin.close(); } } </script>
Its pretty straight forward and works perfectly on every other browser. Just dont get it. Please help
Chris
- cduncombe44
- July 19, 2012
- Like
- 0
Possible inefficient SOQL queries HELP
Hello,
I have created a page that is really just a big list of Processes (custom object) where the user can go and take ownership of the process, it is then removed from the master queue.
The page has 5 buttons to change the view View All, View Mine (open), View Mine (Completed), View Oither (open), View Others (Completed). All this is really doing is changes a controller property that sets the visibility of my tables.
The problem is it takes FOREVER to render the different lists when pressing buttons. It works fine testing in the sandbox with only a few dummy processes, but in production with 1000 or so, it takes forever. I think I am doing something wrong with the SOQL queries perhaps. Is there a more efficient way of accomplishing this?
VF
<apex:sectionHeader title="Insurance Profile Campaign" subtitle="Master List"/> <apex:form > <apex:outputpanel id="container"> <apex:outputpanel id="table"> <apex:pageblock > <apex:pageBlockButtons location="top"> <apex:commandLink action="{!viewAll}" value="View All Unassigned" styleClass="btn" style="text-decoration:none" id="all" rerender="table,mine,container"/> <apex:commandLink action="{!viewMine}" value="View Mine (Open)" styleClass="btn" style="text-decoration:none" id="viewMine" rerender="table,mine,container"/> <apex:commandLink action="{!viewOthers}" value="View Others (Open)" styleClass="btn" style="text-decoration:none" id="others" rerender="table,mine,container"/> <apex:commandLink action="{!viewMyCompleted}" value="View Mine (Completed)" styleClass="btn" style="text-decoration:none" id="myComp" rerender="table,mine,container"/> <apex:commandLink action="{!viewOtherCompleted}" value="View Others (Completed)" styleClass="btn" style="text-decoration:none" id="otherComp" rerender="table,mine,container"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!allProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show All'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!myProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Mine'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!otherProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Others'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!myCompletedProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show My Completed'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!otherCompletedProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Other Completed'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> </apex:pageblock> </apex:outputpanel> </apex:form> </apex:page>
Controller
List<Process__c> allPros; List<Process__c> myPros; List<Process__c> otherPros; List<Process__c> myCompletedPros; List<Process__c> otherCompletedPros; Transient List<Task> acts; Public Process__c selectedProcess {get;set;} Public String Filter {get;set;} Public boolean showStep {get;set;} Public Process_Step__c step; Public Contact con {get;set;} public InsuranceCampaignMasterController() { acts = new List<Task>(); selectedProcess = new Process__c(); step = new Process_Step__c(); Filter = 'Show All'; ShowStep = false; con = new Contact(); } public List<Process__c> getAllProcesses() { if(allPros == null) { allPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__r.Name = 'Chris Duncombe' and Status__c != 'Completed' Order By Contact__r.MailingCity ASC]; }return allPros; } public List<Process__c> getMyProcesses() { if(myPros == null) { myPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c, Start_Date__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c =: userinfo.getUserId() and Status__c != 'Completed' Order By Start_Date__c ASC]; }return myPros; } public List<Process__c> getOtherProcesses() { if(otherPros == null) { otherPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c !=: userinfo.getUserId() and Process_Owner__r.Name != 'Chris Duncombe' and Status__c != 'Completed' Order By Process_Owner__r.Name, Start_Date__c ASC]; }return otherPros; } public List<Process__c> getMyCompletedProcesses() { if(myCompletedPros == null) { myCompletedPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c =: userinfo.getUserId() and Status__c = 'Completed' Order By Completion_Date__c]; }return myCompletedPros; } public List<Process__c> getOtherCompletedProcesses() { if(otherCompletedPros == null) { otherCompletedPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c !=: userinfo.getUserId() and Process_Owner__r.Name != 'Chris Duncombe' and Status__c = 'Completed' Order By Process_Owner__r.Name, Completion_Date__c ASC]; }return otherCompletedPros; } public void takeOwnership() { selectedProcess = [Select Id, Name, Process_Owner__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Id =: system.currentPageReference().getParameters().get('proId')]; step = [Select Id, Name, Assigned_To__c From Process_Step__c Where Process__c =: selectedProcess.id]; selectedProcess.Process_Owner__c = userinfo.getUserId(); selectedProcess.Start_Date__c = system.today(); step.Assigned_To__c = userinfo.getUserId(); update selectedProcess; update step; myPros = null; } public void setStep() { showStep = true; selectedProcess = [Select Id, Name, Contact__c, Process_Owner__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Id =: system.currentPageReference().getParameters().get('proId')]; step = [Select Id, Name, Process__c, Complete_Step_From_Process__c, Log_Activity_From_Process__c, Create_Task_From_Process__c, Status__c, Completed_By__c, Date_Completed__c, Assigned_To__c From Process_Step__c Where Process__c =: selectedProcess.id]; con = [Select Id, Name From Contact Where id =: SelectedProcess.Contact__c]; } public process_Step__c getMyStep() { return step; } public List<Task> getStepActivities() { acts = [Select Id, Subject, Navigator_Subject__c, ActivityDate, Description, WhoId, OwnerId, WhatId From Task Where WhatId =: step.id]; return acts; } public void saveProcessChanges() { update selectedProcess; } public void viewMine() { Filter = 'Show Mine'; showStep = false; } public void viewAll() { Filter = 'Show All'; showStep = false; } public void viewOthers() { Filter = 'Show Others'; showStep = false; } public void viewMyCompleted() { Filter = 'Show My Completed'; showStep = false; } public void viewOtherCompleted() { Filter = 'Show Other Completed'; showStep = false; } }
Any help would be greatly appreicated
Chris
- cduncombe44
- July 12, 2012
- Like
- 0
SOQL inside FOR loop.....need help
Hello all,
So I have a simple trigger that does not work for bulk inserts because I have a SOQL statement inside of a for loop. I know this is the reason, I just can't figure out how to accomplish it without the SOQL in the FOR loop.
I have created a few custom objects to create repeatable processes. There are Process Templates, Process Template Steps, Processes, and Process Steps. As you can guess, you create a process Template, which has process template steps, so you can then create processes that are based on those templates.
I have wrote a simple trigger that each time you create a process, it creates the process steps based on the template steps.
trigger CreateStepsForProcess on Process__c (after insert) { List<Process_Step__c> StepList = new List<Process_Step__c>(); Process_Template__c proTemp = new Process_Template__c(); For (Process__c pro: trigger.new){ proTemp = [Select Id, Name From Process_Template__c Where id =: pro.Process_Template__c]; For (Process_Template_Step__c tempStep: [Select Id, Name, Sequence__c, Process_Template__c, Details__c, Assign_To__c From Process_Template_Step__c Where Process_Template__c =: proTemp.id]) { Process_Step__c step = new Process_Step__c( Name = tempStep.Name, Step_Details__c = tempStep.Details__c, Process__c = pro.Id, Sequence__c = tempStep.Sequence__c, Task_Created__c = 'N' ); if(step.Sequence__c == 1){ step.Status__c = 'Open'; } else { step.Status__c = 'Not Started'; } StepList.add(step); } } insert StepList; }
I'm sure this can be accomplished with a few different Lists and/or Maps outside of the FOR loop, I have just had no luck in accomplishing this. Any help is greatly appreciated. Thanks so much
Chris
- cduncombe44
- July 02, 2012
- Like
- 0
Task & Event Field ID's not working
Hello,
We have activated the Summer 12 option to allow multiple contacts for activities. We had buttons and links that would prefill some of the task and event fields as seen below
} else if (calledFor == 'logActivity') { url = '/' + R.getKeyPrefix() + '/e?email=0&retURL=' + pro.id + '&saveURL=%2Fapex/saveTaskForProcess%3Fprocess_id%3D' + pro.id + '%26id%3D' + step.Id +'%26retURL%3D%2F' + pro.id + '%26called%5Ffrom%3D' + calledFrom + '&tsk1=' + system.Userinfo.getName() + '&tsk1_lkid=' + system.Userinfo.getUserId() + '&tsk2=' + myContact.Name + '&tsk2_lkid=' + myContact.id + '&tsk3=' + step.Name + '&tsk3_lkid=' + step.id + '&what_id=' + step.id + '&tsk4=' + system.today().format() + '&tsk5=Call' + '&tsk12=Completed' + '&00Nd0000004brj5=Health+Insurance';
The button that uses this code still works, but the tsk2 field doesnt seem to be working. The task2_lkid seems to work because the task is related to the contact, but the Text name of that person is not showing up, which is very confusing to the user.
I can't find any documentation on any new field ID's because of the new Task and TaskRelation Object that allow this multiple contact per activity (most likely because SalesForce doesnt support this URL hacking), but does anyone know of how I can get the Name to show, not just the underlying ID to be related?
Basically, does anyone know if there is a new set of Field ID's for activities?
Any help is greatly appreciated
Chris
- cduncombe44
- June 29, 2012
- Like
- 0
View State Size Exceeded
I have a somewhat interesting problem. I have a VF page and a controller that I came up with as a solution to not being able to queue tasks, basically, its just a big list of processes (custom object) that are all assigned to me. The user can then go in, and take ownership of them, and they are removed from this master list or queue. The page seems to work great for me and the other sys admin, but when we try to test it logged in as our end users we get the error
Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 190.75KB
I dont understand why this is only happoening to that profiel, and doesnt give the error when I use the page. Anyway, here is the code. I'm not sure where I could use the transient keyword to help or if my SOQL could be improved, but any help woul dbe greatly appreciated
VF Page
<apex:page controller="InsuranceCampaignMasterController"> <apex:sectionHeader title="Insurance Profile Campaign" subtitle="Master List"/> <apex:form > <apex:outputpanel id="container"> <apex:outputpanel id="table"> <apex:pageblock > <apex:pageBlockButtons location="top"> <apex:commandLink action="{!viewAll}" value="View All" styleClass="btn" style="text-decoration:none" id="all" rerender="table,mine,container"/> <apex:commandLink action="{!viewMine}" value="View Mine" styleClass="btn" style="text-decoration:none" id="mine" rerender="table,mine,container"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!myProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;"> <apex:column style="width:120px; padding-top:10px; padding-bottom:10px; text-align:center;" rendered="{!Filter == 'Show All'}"> <apex:commandLink action="{!takeOwnership}" value="Take Ownership" styleClass="btn" style="text-decoration:none" rerender="table"> <apex:param name="proId" value="{!pro.id}" /> </apex:commandLink> </apex:column> <apex:column style="width:120px; padding-top:10px; padding-bottom:10px; text-align:center;" rendered="{!Filter == 'Show Mine'}"> <apex:commandLink action="{!setStep}" value="View" styleClass="btn" style="text-decoration:none" rerender="table,mine"> <apex:param name="proId" value="{!pro.id}" /> </apex:commandLink> </apex:column> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> <apex:column headerValue="Reason for no Insurance" value="{!pro.Contact__r.Reason_for_no_Insurance__c}"/> <apex:column headerValue="Street Address" value="{!pro.Contact__r.MailingStreet}"/> <apex:column headerValue="City" value="{!pro.Contact__r.MailingCity}"/> <apex:column headerValue="Phone" value="{!pro.Contact__r.Phone}"/> </apex:pageBlockTable> </apex:pageblock> </apex:outputpanel> <apex:outputPanel id="mine"> <apex:pageBlock title="Complete Insurance Profile for {!con.Name}" rendered="{!showStep == true}"> <apex:pageBlockTable value="{!MyStep}" var="step" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Mine'}"> <apex:column headerValue="Name" value="{!step.Name}"/> <apex:column headerValue="Assigned To" value="{!step.Assigned_To__c}"/> <apex:column headerValue="Status" value="{!step.Status__c}"/> <apex:column headerValue="Complete" > <apex:outputtext value="{!step.Complete_Step_From_Process__c}" escape="false"/> </apex:column> <apex:column headerValue="Log Activity" > <apex:outputtext value="{!step.Log_Activity_From_Process__c}" escape="false"/> </apex:column> <apex:column headerValue="Create Task" > <apex:outputtext value="{!step.Create_Task_From_Process__c}" escape="false"/> </apex:column> <apex:column headerValue="Completed By" value="{!step.Completed_by__c}"/> <apex:column headerValue="Date Completed" value="{!step.Date_Completed__c}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:pageBlock title="Activities" rendered="{!showStep == true}"> <apex:pageBlockTable value="{!stepActivities}" var="act" style="width:100%; border:1px solid #D4DADC;" rendered="{!stepActivities.size != 0}"> <apex:column headerValue="Date" value="{!act.ActivityDate}"/> <apex:column headerValue="Owner" value="{!act.OwnerId}"/> <apex:column headerValue="Type" value="{!act.Subject}"/> <apex:column headerValue="Subject" value="{!act.Navigator_Subject__c}"/> <apex:column headerValue="Description" value="{!act.Description}"/> </apex:pageBlockTable> <apex:outputText value="No Activities Recorded Yet" style="font-weight:bold;font-size:large;" rendered="{!stepActivities.size==0}"/> </apex:pageblock> </apex:outputPanel> </apex:outputpanel> </apex:form> </apex:page>
Controller
public with sharing class InsuranceCampaignMasterController { List<Process__c> myPros; List<Task> acts; Process__c selectedProcess; Public String Filter {get;set;} Public boolean showStep {get;set;} Public Process_Step__c step; Public Contact con {get;set;} public InsuranceCampaignMasterController() { myPros = new List<Process__c>(); acts = new List<Task>(); selectedProcess = new Process__c(); step = new Process_Step__c(); Filter = 'Show All'; ShowStep = false; con = new Contact(); } public List<Process__c> getMyProcesses() { if(Filter == 'Show All') { myPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__r.Name = 'Chris Duncombe']; } else { myPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c =: userinfo.getUserId()]; } return myPros; } public void takeOwnership() { selectedProcess = [Select Id, Name, Process_Owner__c From Process__c Where Id =: system.currentPageReference().getParameters().get('proId')]; step = [Select Id, Name, Assigned_To__c From Process_Step__c Where Process__c =: selectedProcess.id]; selectedProcess.Process_Owner__c = userinfo.getUserId(); step.Assigned_To__c = userinfo.getUserId(); update selectedProcess; update step; } public void setStep() { showStep = true; selectedProcess = [Select Id, Name, Contact__c, Process_Owner__c From Process__c Where Id =: system.currentPageReference().getParameters().get('proId')]; step = [Select Id, Name, Process__c, Complete_Step_From_Process__c, Log_Activity_From_Process__c, Create_Task_From_Process__c, Status__c, Completed_By__c, Date_Completed__c, Assigned_To__c From Process_Step__c Where Process__c =: selectedProcess.id]; con = [Select Id, Name From Contact Where id =: SelectedProcess.Contact__c]; } public process_Step__c getMyStep() { return step; } public List<Task> getStepActivities() { acts = [Select Id, Subject, Navigator_Subject__c, ActivityDate, Description, WhoId, OwnerId, WhatId From Task Where WhatId =: step.id]; return acts; } public void viewMine() { Filter = 'Show Mine'; showStep = false; getMyProcesses(); } public void viewAll() { Filter = 'Show All'; showStep = false; getMyProcesses(); } }
Thanks again,
Chris
- cduncombe44
- June 01, 2012
- Like
- 0
commandbutton JS issues
Please help. I have searched these forums for days and am still unable to fix my issue.
I have a VF page, that calls a popup VF page where a new contact is created. On that pop up page, I have a commandButton, that calls a custom save that performs some logic and inserts the new contact. That command button also has a JS function called in the 'oncomplete'. The function simply has an alert, and then closes the window
The issue that I am having is I can't get the JS function to get the right value of the property that is set in my save method. So it is displaying the alert and closing the window, even when there are errors on the page. The page messages are appearing as they should, the alert just comes anyway. I am setting a controller property in the save method to 1 if errors are found. But the JS function is only getting the 'old' value of the property. I assume this is because it is grabbing the property before the savemethod is executed, but I can;t figure out how to solve this issue
CommandButton
<apex:commandButton action="{!createContact}" oncomplete="CloseWindow();" id="saveButton" value="Create New Contact" rerender="page"/>
JS function
<script> function CloseWindow() { var x = '{!hasError}'; if(x != 1) { alert('New Contact Created'); window.top.close(); } else { alert('Some alert to fix errors'); } } </script>
controller
public integer hasError{get;set;} public PageReference createContact() { hasError = 0; if(newCon.FirstName == null || newCon.FirstName == '') { hasError = 1; } if(newCon.LastName == null || newCon.LastName == '') { hasError = 1; } if(newCon.Relationship_to_Subscriber__c == null || newCon.Relationship_to_Subscriber__c == '') { hasError = 1; } try{ insert newCon; }Catch (DMLException e) { } }
Ideally, what I would like is if there are errors (any of those 3 fields checked in the controller are blank) the normal pagemessages appear ad the user fixes them. If there arent errors, I would like to have an alert it was sucessful, close the window, and refresh the parent page. I would also appreciate some help with the proper way to refresh the parent page.
Any help would be greatly appreciated.
Thanks,
Chris
- cduncombe44
- May 14, 2012
- Like
- 0
ReRender issue with tab events....
I am having the hardest time getting this to work. I have created a tabbed view page for contacts. One of these tabs shows a list of interventions (custom object). I have made these into output links that cause a partial page refresh to show the details of the intervention that was clicked. This works great and I am happy. Except that when the user navigates to a different tab, and then returns to the interventions tab, the last intervention that was choosen is still being rendered.
I have been toiling over how to 'Clear' this output panel that holds the deatils using tab events but havent had any luck. This is what I have....
VF Page....
<apex:tab label="Interventions" name="Interventions" id="tabInterventions" onTabEnter="resetIntTab" ontableave="resetIntTab" onclick="resetIntTab"> <apex:form > <apex:actionFunction immediate="true" name="resetIntTab" action="{!resetIntTab}" reRender="intPanelContainer,interventionBlock" /> <apex:pageBlock > <apex:facet name="header"> <apex:dataTable columns="2" rows="1" value="{!Contact}" var="i" style="margin-top:3px;"> <apex:column style="width:360px;"> <apex:outputText value="Interventions" style="font-weight:bold; font-size:small"></apex:outputText> </apex:column> <apex:column > <apex:outputLink value="{!interventionPageRef}" styleClass="btn" style="text-decoration:none"> New Intervention<apex:param name="00Nd000000308OV" value="{!contact.id}"/> </apex:outputLink> </apex:column> </apex:dataTable> </apex:facet> <apex:dataTable value="{!MyInterventions}" var="int" columns="4" style="width:800px; border:1px solid #D4DADC;" rules="rows" cellpadding="3px;3px;" id="myInts"> <apex:column headerClass="myHead" > <apex:facet name="header"><b>Intervention</b></apex:facet> <apex:commandLink action="{!invokeService}" value="{!int.name}" rerender="intPanelContainer"> <apex:param name="cid" value="{!int.id}"/> </apex:commandLink> </apex:column> <apex:column headerValue="Intervention Type" headerClass="myHead"> {!int.recordtype.name} </apex:column> <apex:column headerValue="Status" headerClass="myHead"> {!int.Status__c} </apex:column> <apex:column headerValue="Current Stage" headerClass="myHead"> {!int.Current_Stage__c} </apex:column> </apex:dataTable> </apex:pageBlock> </apex:form> <apex:form > <apex:outputPanel id="intPanelContainer"> <apex:pageBlock title="{!fetchedData.Name}" tabStyle="Intervention__c" mode="inlineEdit" id="interventionBlock" rendered="{!NOT(ISNULL(fetchedData))}"> <apex:pageBlockButtons location="top" rendered="{!NOT(ISNULL(fetchedData))}"> <apex:commandButton action="{!saveInterventionChanges}" id="saveButton" value="Save" rerender="intPanelContainer,myInts"/> <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/> </apex:pageBlockButtons> <apex:outputpanel id="intPanel" rendered="{!NOT(ISNULL(fetchedData))}"> <apex:pageBlockSection columns="2" title="Intervention Details"> <apex:outputField value="{!fetchedData.Name}"/> <apex:inputField value="{!fetchedData.Status__c}"/> <apex:outputField value="{!fetchedData.RecordType.Name}" label="Type"/> <apex:outputField value="{!fetchedData.Current_Stage__c}"/> <apex:outputField value="{!fetchedData.Contact__c}"/> </apex:pageBlockSection> <apex:pageBlockSection columns="2" title="Intervention Age"> <apex:outputField value="{!fetchedData.Enrollment_Start__c}"/> <apex:outputField value="{!fetchedData.Enrollment_End__c}"/> <apex:outputField value="{!fetchedData.Time_on_Current_Stage__c}"/> <apex:outputField value="{!fetchedData.Total_Time_on_Enrollment__c}"/> </apex:pageBlockSection> <apex:pageBlockSection columns="2" title="Intervention Stages" rendered="{!isInsEnroll}"> <apex:outputField value="{!fetchedData.Ins_Stage_1_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_1_Completed_by__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_2_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_2_Completed_by__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_3_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_3_Completed_by__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_4_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_4_Completed_by__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_5_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_5_Completed_by__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_6_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_6_Completed_by__c}"/> </apex:pageBlockSection> <apex:pageBlockSection columns="2" title="Intervention Stages" rendered="{!isFinEnroll}"> <apex:outputField value="{!fetchedData.Ins_Stage_2_Completion__c}"/> <apex:outputField value="{!fetchedData.Ins_Stage_2_Completed_by__c}"/> </apex:pageBlockSection> </apex:outputpanel> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:tab>
Controller Extension....
public class tabbedContactExtension { private List<Contact> members; private List<Intervention__c> myInts; private Member_Profile__c myProf; private Contact cntact; public Intervention__c result; public string recType; public tabbedContactExtension(ApexPages.StandardController controller) { this.cntact= (Contact)controller.getRecord(); } public List<Contact> getMembers() { Contact con = [Select id, npo02__Household__r.id FROM Contact where id = :cntact.id]; members = [Select id, Household_Role__c, Name, Birthdate, HomePhone from Contact where npo02__Household__r.id = :con.npo02__Household__r.id]; return members; } public Member_Profile__c getProfile() { myProf = [Select id, name, Total_Savings__c, Total_Cost__c, Contact__c FROM Member_Profile__c where Contact__c = :cntact.id]; return myProf; } public List<Intervention__c> getMyInterventions() { myInts = [select Name, id, recordtype.name, Status__c, Current_Stage__c from Intervention__c where Contact__c =:cntact.id]; return myInts; } public Intervention__c getFetchedData(){ return result; } public void resetIntTab() { result = null; } public void invokeService() { Id id = System.currentPageReference().getParameters().get('cid'); result = [SELECT Name, Current_Stage__c, Contact__c, RecordType.Name, Status__c, Enrollment_Start__c, Enrollment_End__c, Time_on_Current_Stage__c, Total_Time_on_Enrollment__c, Ins_Stage_1_Completion__c, Ins_Stage_2_Completion__c, Ins_Stage_3_Completion__c, Ins_Stage_4_Completion__c, Ins_Stage_5_Completion__c, Ins_Stage_6_Completion__c, Ins_Stage_1_Completed_by__c, Ins_Stage_2_Completed_by__c, Ins_Stage_3_Completed_by__c, Ins_Stage_4_Completed_by__c, Ins_Stage_5_Completed_by__c, Ins_Stage_6_Completed_by__c FROM Intervention__c WHERE id=:id]; recType = result.RecordType.Name; } public pageReference saveInterventionChanges() { UPDATE result; return null; } public PageReference getInterventionPageRef() { return System.Page.Intervention; }
As you can see I have tried to add my actionfunction to every tab event that I thought was relevant, but still it does nothing. Am I wrong to think that all I have to do is set my controller variable 'result' to NULL. After all it gets set to null, and then getFetchedData() is returning result, so it should be returning NULL and thus my output panel is looking at that in its rendered property.
Please help as I just can;t seem to see where I am going wrong. Thanks in advance.
Chris
- cduncombe44
- March 21, 2012
- Like
- 0
Organization Affiliations Help
I have been working with the NPSP now and everything seems to be goig well until I hit a fairly simple, but annoying issue. I have created a Tabbed VF page to override contact view. I am able to get all the related info on the page either through <apex:relatedList> or using querying within the controller.
The one problem I am having is accessing the affiliations related list. I know I could query within the controller if I wanted to, but isnt there a simple relationship that I should be able to find? Something like..
<apex:tab label="Organizations" name="OrgAffiliation" id="tabOrgs"> <apex:relatedList list="Affiliations__r" /> </apex:tab>
I know that Orgs are taking the place of Accounts and it's SF's way of being able to have the one-to-many relationship so that may be why I'm having trouble, but the standard contact view has a related list of affiliated organizations. Am I just not using the right relationshipname or what? Please help as this is very frustrating and seems like a simple thing to want to accomplish.
Thank you
Chris
- cduncombe44
- March 02, 2012
- Like
- 0
Simple custom extension test method
I have what I believe is a very simple controller extension, and I cant seem to get any higher the 66% coverage on my test.
The page is a page for creating a new custom object (Intervention__c), this page is called from a button on a contact page. I pass the contact id as a param for this page.
I would apprecitae any help.
public class newInterventionCONT { Public String ConID = System.currentPagereference().getParameters().get('00Nd000000308OV'); public Contact myCon; public newInterventionCONT(ApexPages.StandardController controller) { myCon= [SELECT Name, Id FROM Contact WHERE Id = :System.currentPagereference().getParameters().get('00Nd000000308OV')]; } public Contact getMyCon(){ return myCon; } static testMethod void testgetConMethod() { PageReference pg = Page.intervention; Test.setCurrentPage(pg); Contact myContact = new Contact(); myContact.firstName = 'Joe'; myContact.lastName = 'Schmoe'; insert myContact; ApexPages.StandardController stanCont = new ApexPages.standardController(myContact); newInterventionCONT controller = new newInterventionCONT(stanCont); string conFirstName = controller.getmyCon().FirstName; string conLastName = controller.getmyCon().LastName; string conID = controller.getmyCon().ID; } }
Thanks,
Chris
- cduncombe44
- February 24, 2012
- Like
- 0
Help with some simple AJAX re-rendering
Hello,
I have used various boards and forums to come up with a fairly simple output panel to rerender some areas of a VF page.
I have a created a tabbed contact view VF page. I have a 'Interventions' tab that lists the interventions (custom object) associated with this contact. Here is the code for the tab...
<apex:tab label="Interventions" name="Interventions" id="tabInterventions"> <apex:form> <apex:pageBlock title="Interventions"> <apex:dataTable value="{!MyInterventions}" var="int" columns="2"> <apex:column> <apex:facet name="header"><b>Name</b></apex:facet> <apex:commandLink action="{!invokeService}" value="{!int.name}" rerender="resultPanel"> <apex:param name="id" value="{!int.id}"/> </apex:commandLink> </apex:column> <apex:column headerValue="Current Stage"> {!int.Current_Stage__c} </apex:column> </apex:dataTable> </apex:pageBlock> </apex:form> <apex:pageBlock> <apex:outputPanel id="resultPanel" layout="block"> <apex:detail subject="{!fetchedData}"/> </apex:outputPanel> </apex:pageBlock> </apex:tab>
and here are the corresponding methods from the controller extension
public List<Intervention__c> getMyInterventions() { myInts = [select Name, id, Current_Stage__c from Intervention__c where Contact__c =:cntact.id]; return myInts; } public Intervention__c getFetchedData(){ return result; } public PageReference invokeService() { Id id = System.currentPageReference().getParameters().get('id'); result = [SELECT Name, Current_Stage__c FROM Intervention__c WHERE Contact__c=:id]; return null; }
This works wonderfully if I have only 1 intervention assiociated witht the contact, but if there is more than 1, I get the following error
System.QueryException: List has more than 1 row for assignment to SObject
I know what is causing my issue, my invokeService is returning a list of all the interventions associated with that Contact. I just don't know how to fix it. How do I make sure that I am querying only the intervention that was clicked on. How do I get that Id of the intervention that was clicked so that I can query for it in my invokeService method?
Or if I'm way off on all of this, how do I accomplish this better?
Also have a part 2 of the question.
Once this is fixed, how do I reset the output panel every time the user navigates away from teh interventions tab. Right now (assuming I have only 1 intervention for that contact, which is the only way it works) once I click on the intervention, the output panel re renders to that intervention. Which is great, but I want to make sure if they navigate to another tab on the tabpanel, that output panel resets itself, because right now it stays on the selected intervention. Basically I want to blank it out if the user navigates away from the interventions tab.
Thanks a million in advance for any help.
Chris
- cduncombe44
- February 21, 2012
- Like
- 0
Custom Button issue
Hi,
I'm somewhat new to VF and am running into a very simple (i assume) issue. I have created a custom object Member Profile that has a master detail relationship with contacts.
I wrote a trigger that creates a new profile each time a new contact is created, and made sure each contact can have 1 and only 1 profile.
Right now the profile is shown in a related list on the contact page. I want to create a button that brings the user to the detail page of the member profile.
I created a very simple VF member_profile page here
<apex:page standardController="Member_Profile__c"> <apex:detail relatedList="false"/> </apex:page>
Then I added a custom button to the contacts page simply directing to a URL of....
/apex/member_profile?id={!Contact.Member_Profile__c}
but when I click on the button, it brings me to a new page and gives me this error
Insufficient Privileges |
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary. |
But if I look at the URL, it doesnt have the id of the member profile, it has the name of the profie. If i try to add the .id like below
/apex/member_profile?id={!Contact.Member_Profile__c.Id}
It tells me that that field doesnt exist.
I'm sure that I'm doing something simple and stupid, but its driving me crazy that I can't figure it out. It seems like such a simple thing to want to have a button navigate to another objects detail page. PLEASE HELP
Thanks,
Chris
- cduncombe44
- February 08, 2012
- Like
- 0
<apex:inputfile> issues...Body is always null
I'm having the hardest time doing something that should be relatively simple. I have a VF component that is displaying a list of custom objects and a penel that will display details about each object. For each child object in the details, I want the ability to upload an attachment. I have used a wrapper class to help with this. The issue is I am getting a VF error: Required field missig [Body] : [Body] every time.
Here is the relevant section of VF
<apex:repeat value="{!formWraps}" var="fWrap"> <tr> <td style="font-weight:bold"><apex:outputField value="{!fWrap.form.Form_Template__r.Name}"/></td> <td><apex:inputfield value="{!fWrap.form.Collected_Paper_Form__c}"/></td> <td><apex:inputfield value="{!fWrap.form.Attached_in_SalesForce__c}"/></td> <td><apex:outputLabel value="File: " for="file" style="font-weight:bold"/> <apex:inputText value="{!fWrap.attachment.Name}"/> <apex:inputFile value="{!fWrap.attachment.Body}" filename="{!fWrap.attachment.Name}"/></td> </tr> </apex:repeat>
<apex:pageblockButtons location="bottom"> <apex:commandButton value="Save Changes" action="{!saveChanges}"/> </apex:pageblockButtons>
Here are the controller properties, methods, and wrapperClass that apply
public Contact con {get;set;} public Event_Affiliation__c currentEvent {get;set;} private list<Form__c> forms {get;set;} public list<formWrapper> formWraps {get;set;} .......... Id eventId = System.currentPageReference().getParameters().get('event');
currentEvent = [Select Id, Name, Pre_Registered__c, Attended__c, Fishing_Partnership_Event__c,
Fishing_Partnership_Event__r.Name, (Select Id, Name From Attachments), Fishing_Partnership_Event__r.Location__c,
Fishing_Partnership_Event__r.Event_Date__c From Event_Affiliation__c Where Id = : eventId]; forms = [Select Id, Name, Form_Template__c, Form_Template__r.Name, Collected_Paper_Form__c, Attached_in_SalesForce__c,
Attachment_ID__c, Event_Affiliation__c From Form__c Where Event_Affiliation__c =: currentEvent.Id]; for(Form__c f : forms){ formWraps.add(new formWrapper(f)); } ............... public PageReference saveChanges(){ for(formWrapper wrap : formWraps){ wrap.attachment.Name = wrap.form.Form_Template__r.Name + ' ' + con.Name; wrap.attachment.ParentId = wrap.form.Event_Affiliation__c; wrap.attachment.OwnerId = UserInfo.getUserId(); wrap.attachment.Body = fileBody; system.debug('attachment Name: ' + wrap.attachment.Name);
system.debug('attachment OwnerID: ' + wrap.attachment.OwnerId);
system.debug('attachment ParentID: ' + wrap.attachment.ParentId); system.debug('attachment Body: ' + wrap.attachment.Body); insert wrap.attachment; } try{ update currentEvent; update healthInts; }catch(Exception e){ ApexPages.addMessages(e); } PageReference page = new PageReference('/' + currentEvent.Id); page.setRedirect(true); return page; } .................. /*WRAPPER CLASS*/ public class formWrapper{ public Form__c form {get;set;} public string attachmentID {get;set;} public Attachment attachment {get;set;} public formWrapper(Form__c f){ form = f; attachmentID = ''; attachment = new Attachment(); } public formWrapper(Form__c f, string aID, Attachment a){ form = f; attachmentID = aID; attachment = a; } }
Here is the Debug logs...for some reason the body of the attachment is not being bound from the input file to the attachment within the wrapper class, all the other attributes are being set....I've been pouding my head on the wall for a while with this one
09:58:45.341 (341358000)|SYSTEM_METHOD_ENTRY|[63]|System.debug(ANY) 09:58:45.341 (341376000)|USER_DEBUG|[63]|DEBUG|attachment Name: Signed Consent Form Johnny Appleseed 09:58:45.341 (341384000)|SYSTEM_METHOD_EXIT|[63]|System.debug(ANY) 09:58:45.341 (341403000)|METHOD_ENTRY|[64]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341422000)|METHOD_EXIT|[64]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341466000)|SYSTEM_METHOD_ENTRY|[64]|String.valueOf(Object) 09:58:45.341 (341480000)|SYSTEM_METHOD_EXIT|[64]|String.valueOf(Object) 09:58:45.341 (341492000)|SYSTEM_METHOD_ENTRY|[64]|System.debug(ANY) 09:58:45.341 (341502000)|USER_DEBUG|[64]|DEBUG|attachment OwnerID: 005d00000011zsxAAA 09:58:45.341 (341510000)|SYSTEM_METHOD_EXIT|[64]|System.debug(ANY) 09:58:45.341 (341524000)|METHOD_ENTRY|[65]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341542000)|METHOD_EXIT|[65]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341620000)|SYSTEM_METHOD_ENTRY|[65]|String.valueOf(Object) 09:58:45.341 (341640000)|SYSTEM_METHOD_EXIT|[65]|String.valueOf(Object) 09:58:45.341 (341661000)|SYSTEM_METHOD_ENTRY|[65]|System.debug(ANY) 09:58:45.341 (341676000)|USER_DEBUG|[65]|DEBUG|attachment ParentID: a0gK00000011xBeIAI 09:58:45.341 (341686000)|SYSTEM_METHOD_EXIT|[65]|System.debug(ANY) 09:58:45.341 (341701000)|METHOD_ENTRY|[66]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341721000)|METHOD_EXIT|[66]|01pK00000001Qv8|EventAffiliationListController.formWrapper.__sfdc_attachment() 09:58:45.341 (341734000)|SYSTEM_METHOD_ENTRY|[66]|String.valueOf(Object) 09:58:45.341 (341741000)|SYSTEM_METHOD_EXIT|[66]|String.valueOf(Object) 09:58:45.341 (341753000)|SYSTEM_METHOD_ENTRY|[66]|System.debug(ANY) 09:58:45.341 (341762000)|USER_DEBUG|[66]|DEBUG|attachment Body: null 09:58:45.341 (341769000)|SYSTEM_METHOD_EXIT|[66]|System.debug(ANY)
I know this is bits and pieces, and totaly not best practices with SOQL in for loops and such, but that wouldnt cause the Body of the attachment to be null. I figure I want to get it working before worrying about optimizing the code.
Any help would be greatly appreciated. Just hoping there is something obvious that I am missing that someone could point out. PLEASE HELP
Chris
- cduncombe44
- December 06, 2012
- Like
- 0
Rerender with jqGrid issue. PLEASE HELP
I am pulling my hair out with this one.
I have a few jqGrids on my VF page. I now have a select list Im using to try to filter one of the jqGrids. If I hardcode an ID in the controller to filter with, it works, and the grid reloads, but if i try to use the parameter that I am passing in via an ActionFunction, the logs show my parameter as null.
jquery change method
jQuery('[id$=htmlSelect]').change(function(e) { filterPage(this.value); var commGrid = jQuery('#commList'); commGrid.trigger("reloadGrid"); });
Action Function
<apex:actionFunction name="filterPage" action="{!makeNewCommJSON}" > <apex:param name="acc" value="" assignTo="{!stringID}"/>
</apex:actionFunction>
Controller function to filter list
public void makeNewCommJSON(){ Id acc = system.currentPageReference().getParameters().get('acc'); system.debug('accountid Parameter: ' + acc); system.debug('stringID Value: ' + stringID); list<Commitment__c> comms = [select id, Name, Due_Date__c, Status__c, Account__c, Account__r.Name, Owner__c, Owner__r.Alias from Commitment__c where Owner__c = :Userinfo.getuserid() and Status__c != 'Completed' and Account__c =: acc]; //and Account__c = '001M000000JKGcNIAX']; if(comms != null && comms.size() > 0) { newCommJSON = '{"page":"1","total":"' + ( 1 + ( comms.size() / 10 )) + '","records":"' + String.valueOf(comms.size()) + '","rows":['; for(Commitment__c c : comms ) { newCommJSON += '{"id":"' + c.id + '","cell":['; newCommJSON += JqGridDataController.parseCell(c.Due_Date__c); newCommJSON += JqGridDataController.parseCell('<a href=/'+ c.Account__c + '>'+ c.Account__r.Name +'</a>') newCommJSON += JqGridDataController.parseCell(c.Owner__r.Alias); newCommJSON += JqGridDataController.parseCell('<a href=/'+ c.Id + '>' + c.Name + '</a>'); newCommJSON = newCommJSON.subString(0,newCommJSON.length() - 1); newCommJSON += ']},'; } newCommJSON = newCommJSON.subString(0,newCommJSON.length() - 1); newCommJSON += ']}'; } else { //no records were retrieved newCommJSON = '{"page":"1","total":1,"records":"' + String.valueOf('0') + '","rows":['; newCommJSON += '],"userdata":{"amount":3220,"tax":342,"total":3564,"name":"Totals:"}}'; } DashIdCarrier.commJSONString = newCommJSON; }
This all works fine, but as I said, when I check the logs, the parameter isnt being passed properly. see below
17:56:00.082 (82279000)|SYSTEM_METHOD_EXIT|[33]|String.valueOf(Object) 17:56:00.082 (82302000)|SYSTEM_METHOD_ENTRY|[33]|System.debug(ANY) 17:56:00.082 (82313000)|USER_DEBUG|[33]|DEBUG|accountid Parameter: null 17:56:00.082 (82320000)|SYSTEM_METHOD_EXIT|[33]|System.debug(ANY) 17:56:00.082 (82341000)|METHOD_ENTRY|[34]|01pM00000009QmO|CommitmentDashboardController.__sfdc_stringID() 17:56:00.082 (82377000)|METHOD_EXIT|[34]|01pM00000009QmO|CommitmentDashboardController.__sfdc_stringID() 17:56:00.082 (82395000)|SYSTEM_METHOD_ENTRY|[34]|System.debug(ANY) 17:56:00.082 (82403000)|USER_DEBUG|[34]|DEBUG|stringID Value: null 17:56:00.082 (82410000)|SYSTEM_METHOD_EXIT|[34]|System.debug(ANY)
If i dont use the parameter, and hard code an ID of an account, it works fine and the grid reloads perfectly. Am i doing something wrong? What am I missing here, why is the parameter not being passed properly?
Any help would be hugely appreciated.
Chris
- cduncombe44
- November 29, 2012
- Like
- 0
How to query for opportunity from contact
hi guys,
Please help me in with the query.
My contact will have only one opportunity 1-1 relation ship:-1 account ,1 contact 1, opportunity.
for(Comments__c cs:trigger.New){
cms=cs;
if(cms.Opportunity__c==null && cms.Contact__c!=null ){
sobjectSetOfIds.add(cms.Contact__c);
}
}
Map<Id,Contact>smap1= new Map<Id, Contact>([Select id
,Name
,Opportunities__r.id // error
from Contact
where Id in : sobjectSetOfIds]);
for(Comments__c s: trigger.new){
if(smap1.containsKey(s.Contact__c)){
s.Opportunity__c=smap1.get(s.Contact__c).Opportunities.id; //error
}
}
Thanks
Anil.B
- @anilbathula@
- July 25, 2012
- Like
- 0
Sorting string like a summary
Hello all,
I've been trying to sort a list of strings like a summary but I have no idea about what to try now.
There is my problem:
I have string that represents positions in a summary, example: "1", '1.1", "1.1.1", "1.1.2", etc.
And I want to sort those in order like a structured things in the Microsoft project.
But for strings, "4" is not greater than "1.1". So things won't be in correctly order.
Searching in Google and here I tried to make a Wrapper. That looks like this:
global class PacoteWrapper implements Comparable {
public Pacote__c pac;
public PacoteWrapper(Pacote__c pc) {
pac = pc;
}
global Integer compareTo(Object compareTo) {
PacoteWrapper compareToPac = (PacoteWrapper)compareTo;
Integer returnValue = 0;
Double posDouble = Double.valueOf(pac.Posicao_EDT__c);
Double posCompareDoulb = Double.valueOf(compareToPac.pac.Posicao_EDT__c);
if (posDouble > posCompareDoulb) {
returnValue = 1;
} else if (posDouble < posCompareDoulb) {
returnValue = -1;
}
return returnValue;
}
And i use pacWrapperList.sort() to make things works.
But it will only works if my string is not greater than 2 dots.
That means, it works great for strings like "1", "1.2", "2.3", etc.
It will fail for strings using 2 dots, of course. There is no double number with 2 dots, hahaha.
So, if anyone has a tip or a piece of code that can help me, i will be very glad.
Thank you all for attention. Best regards!
- tfoil
- July 20, 2012
- Like
- 0
can any one help me out with testclass for visualforce custom controller class
Hi guys. I am learning force.com and currently i am using developer account so I necessarily don't have to write testclass for a now but when i will be on project i have to write down test method to deployee it to production envirionment from developer environment. I have written some test classes for triggers but i don't know how to write testmethod for visualforce custome controller class. my code is successfully working but I also want to write test class with cover more than 75%. i am pasting my code bellow can you guys help me out with its test class.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
public with sharing class searchPatientAccount {
// the soql without the order and limit
private String soql {get;set;}
// the collection of contacts to display
public List<Account> accounts {get;set;}
// the current sort direction. defaults to asc
public String sortDir {
get { if (sortDir == null) { sortDir = 'asc'; } return sortDir; }
set;
}
// the current field to sort by. defaults to last name
public String sortField {
get { if (sortField == null) {sortField = 'name'; } return sortField; }
set;
}
// format the soql for display on the visualforce page
public String debugSoql {
get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
set;
}
// init the controller and display some sample data when the page loads
public searchPatientAccount() {
soql = 'select a.id, a.name, a.accountnumber,a.phone from account a where a.name != null';
runQuery();
}
// toggles the sorting of query from asc<-->desc
public void toggleSort() {
// simply toggle the direction
sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
// run the query again
runQuery();
}
// runs the actual query
public void runQuery() {
try {
accounts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
} catch (Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
}
}
// runs the search with parameters passed via Javascript
public PageReference runSearch() {
String accountname = Apexpages.currentPage().getParameters().get('accountname');
String accountnumber = Apexpages.currentPage().getParameters().get('accountnumber');
String phone = Apexpages.currentPage().getParameters().get('phone');
// String technology = Apexpages.currentPage().getParameters().get('technology');
soql = 'select a.id, a.name, a.accountnumber,a.phone from account a where a.name != null';
if (!accountname.equals(''))
soql += ' and a.name LIKE \''+String.escapeSingleQuotes(accountname)+'%\'';
if (!accountnumber.equals(''))
soql += ' and a.accountnumber LIKE \''+String.escapeSingleQuotes(accountnumber)+'%\'';
if (!phone.equals(''))
soql += ' and a.phone LIKE \''+String.escapeSingleQuotes(phone)+'%\'';
// run the query again
runQuery();
return null;
}
// use apex describe to build the picklist values
public List<String> technologies {
get {
if (technologies == null) {
technologies = new List<String>();
Schema.DescribeFieldResult field = Contact.interested_technologies__c.getDescribe();
for (Schema.PicklistEntry f : field.getPicklistValues())
technologies.add(f.getLabel());
}
return technologies;
}
set;
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- :) :) :) :) :)
- July 20, 2012
- Like
- 0
How to Refresh custom VF page after delete
Hello I have PageBlockTable with in line editing and a link to delete the selected row.
The delete works fine, however I cannot figure our how to refresh the page or even just the
pageblocktable to show that the row has been deleted.
Thanks in Advance
Delete method:
public string SelectedDetailId { get; set; }
public void DeleteDetail()
{
if (SelectedDetailId == null) {
return;
}
Product_Detail__c toBeDeleted = [SELECT name FROM Product_Detail__c WHERE Name = :SelectedDetailId LIMIT 1];
if (toBeDeleted != null) delete toBeDeleted;
//refreshTable();
}
Apex Code:
<apex:pageBlockTable id="annTable" value="{!AnnuityProducts}" var="item" Title="Annuity Detail">
<apex:column >
<a href="javascript:if (window.confirm('Are you sure?')) DeleteDetail('{!item.name}');" style="font-weight:bold">Del</a>
</apex:column>
<apex:column headerValue="Carrier">
<apex:outputField value="{!item.Name__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:column headerValue="Type">
<apex:outputField value="{!item.Type__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:column headerValue="Verified Assets">
<apex:outputField value="{!item.Asset_Total__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:column headerValue="Portability">
<apex:outputField value="{!item.Portability__c}">
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" hideOnEdit="editButton" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
</apex:outputField>
</apex:column>
<apex:column headerValue="Product Detail Name">
<apex:outputField value="{!item.Name}">
</apex:outputField>
</apex:column>
</apex:pageBlockTable>
<apex:actionFunction action="{!DeleteDetail}" name="DeleteDetail" reRender="test" >
<apex:param name="name" value="" assignTo="{!SelectedDetailId}"/>
</apex:actionFunction>
- law
- July 20, 2012
- Like
- 0
rerender doesn't get the updated value of a field.
The code below rerenders the time on the "randompanel" but it doesn't shows the new value of the case status when clicking on the Reopen case button. The random panel and the NOW function were added just to test. The action {!ReOpenCase} sets the status of the case to "reopened" and this is happening but the rerender doesn't display that value. I opened a case with salesforce about this and is escalated to tier 3.....any ideas?
<apex:outputPanel id="randompanel" >
<apex:outputtext value="{!NOW()}"/>
<apex:outputtext value="{!case.status}"></apex:outputtext>
</apex:outputPanel>
<apex:form >
<apex:commandButton action="{!ReOpenCase}" value="Reopen Case" id="ReopenCaseButton" reRender="randompanel" rendered="{!IF(case.Status == 'Resolved' || case.Status == 'Closed',true,false)}"/>
</apex:form>
Thanks in advance for any help on this. I have spent a lot of time trying to make it work :(
- InternalServerError
- July 20, 2012
- Like
- 0
Creating Columns
Hi All,
Is there an alternate way to create columns in visual force page apart from using <apex:columns>?
Thanks and Regards,
Vijay
- vjai
- July 20, 2012
- Like
- 0
IE9 issue with JS and actionFunction
I really hope someone can help me because I have been banging my head over this one for far too long. I have a VF page to override the contact view. Its tabbed and most tabs are made of their own cutom component.
On this particular component, I have a list of wrapperClass custom objects so users can mass copy Insurances (custom object). The popup allows them to choose which contact to copy the insurances to, and when you click select, the JS calls a function on the parent page that simply calls an actionFunction to insert the new records, and refreshes the list and adds a page message. Works great with every browser except IE. I really wish I could just force users to not use IE, but not an option at this point.
I have looked over the boards and tried every suggestion I could find from previous posts. I have taken out the showHeader="false", I have tried nesting the entire page in <body> tags, I tried immediate="true" in the actionFunction, I have added the following to the controller
Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
Nothing seems to work. It is actually closing the window, but it is not calling the actionFunction and rerendering the page at all. I just dont know how to fix this please help
Popup VF Page
<apex:form id="form"> <table cellpadding="5px" cellspacing="0" style="margin: 10px;"> <tr> <td colspan="3" align="center"><apex:commandButton value="Select" action="{!save}" oncomplete="fun();" rerender="panel1,panel2"/> <apex:commandButton value="Cancel" onclick="window.top.close();" /></td> </tr> <tr> </tr> <tr> <td width="50px"></td> <td width="400px" class="cts_th">Which Family Member(s) would you like to copy selected Insurances to?</td> <td width="50px"></td> </tr> <tr> <td width="20px"></td> </tr> <tr> <td width="20px"></td> </tr> <tr></tr> </table> <table cellpadding="5px" cellspacing="0" style="margin: 10px;"> <apex:repeat value="{!conWrappers}" var="con"> <tr> <td width="50px" align="right"><apex:inputCheckbox value="{!con.checked}" id="check"/></td> <td width="200px">{!con.cntact.Full_Name__c}</td> </tr> </apex:repeat> </table> <apex:outputpanel id="panel2"> <apex:pageblock id="block"> <apex:inputHidden value="{!saved}" id="saved"/> <apex:inputHidden value="{!sel}" id="sel"/> </apex:pageblock> </apex:outputpanel> </apex:form> <script> function fun() { var item = document.getElementById('page:form:block:saved'); if(item.value == 'false'){ alert('You didn\'t choose anyone'); } if(item.value == 'true') { Close(); } } function Close() { var winMain=window.opener; if (null==winMain) { winMain=window.parent.opener; } item = document.getElementById('page:form:block:sel'); var sel = item.value; winMain.userSelected(sel); } </script>
Snippets from Parent Page
<apex:actionfunction name="copyInsurance" action="{!copyInsurance}" immediate="true" rerender="insurances,table,dataTable"/> <apex:inputhidden value="{!sel}" id="selected"/> <script> function userSelected(sel) { var tag = document.getElementById('{!$Component.com.block.section.selected}'); tag.value = sel; copyInsurance(); closePopup(); } function closePopup() { if (null!=newWin) { newWin.close(); } } </script>
Its pretty straight forward and works perfectly on every other browser. Just dont get it. Please help
Chris
- cduncombe44
- July 19, 2012
- Like
- 0
Possible inefficient SOQL queries HELP
Hello,
I have created a page that is really just a big list of Processes (custom object) where the user can go and take ownership of the process, it is then removed from the master queue.
The page has 5 buttons to change the view View All, View Mine (open), View Mine (Completed), View Oither (open), View Others (Completed). All this is really doing is changes a controller property that sets the visibility of my tables.
The problem is it takes FOREVER to render the different lists when pressing buttons. It works fine testing in the sandbox with only a few dummy processes, but in production with 1000 or so, it takes forever. I think I am doing something wrong with the SOQL queries perhaps. Is there a more efficient way of accomplishing this?
VF
<apex:sectionHeader title="Insurance Profile Campaign" subtitle="Master List"/> <apex:form > <apex:outputpanel id="container"> <apex:outputpanel id="table"> <apex:pageblock > <apex:pageBlockButtons location="top"> <apex:commandLink action="{!viewAll}" value="View All Unassigned" styleClass="btn" style="text-decoration:none" id="all" rerender="table,mine,container"/> <apex:commandLink action="{!viewMine}" value="View Mine (Open)" styleClass="btn" style="text-decoration:none" id="viewMine" rerender="table,mine,container"/> <apex:commandLink action="{!viewOthers}" value="View Others (Open)" styleClass="btn" style="text-decoration:none" id="others" rerender="table,mine,container"/> <apex:commandLink action="{!viewMyCompleted}" value="View Mine (Completed)" styleClass="btn" style="text-decoration:none" id="myComp" rerender="table,mine,container"/> <apex:commandLink action="{!viewOtherCompleted}" value="View Others (Completed)" styleClass="btn" style="text-decoration:none" id="otherComp" rerender="table,mine,container"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!allProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show All'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!myProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Mine'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!otherProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Others'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!myCompletedProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show My Completed'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> <apex:pageBlockTable value="{!otherCompletedProcesses}" var="pro" style="width:100%; border:1px solid #D4DADC;" rendered="{!Filter == 'Show Other Completed'}"> <apex:column headerValue="Contact" value="{!pro.Contact__c}"/> </apex:pageBlockTable> </apex:pageblock> </apex:outputpanel> </apex:form> </apex:page>
Controller
List<Process__c> allPros; List<Process__c> myPros; List<Process__c> otherPros; List<Process__c> myCompletedPros; List<Process__c> otherCompletedPros; Transient List<Task> acts; Public Process__c selectedProcess {get;set;} Public String Filter {get;set;} Public boolean showStep {get;set;} Public Process_Step__c step; Public Contact con {get;set;} public InsuranceCampaignMasterController() { acts = new List<Task>(); selectedProcess = new Process__c(); step = new Process_Step__c(); Filter = 'Show All'; ShowStep = false; con = new Contact(); } public List<Process__c> getAllProcesses() { if(allPros == null) { allPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__r.Name = 'Chris Duncombe' and Status__c != 'Completed' Order By Contact__r.MailingCity ASC]; }return allPros; } public List<Process__c> getMyProcesses() { if(myPros == null) { myPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c, Start_Date__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c =: userinfo.getUserId() and Status__c != 'Completed' Order By Start_Date__c ASC]; }return myPros; } public List<Process__c> getOtherProcesses() { if(otherPros == null) { otherPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c !=: userinfo.getUserId() and Process_Owner__r.Name != 'Chris Duncombe' and Status__c != 'Completed' Order By Process_Owner__r.Name, Start_Date__c ASC]; }return otherPros; } public List<Process__c> getMyCompletedProcesses() { if(myCompletedPros == null) { myCompletedPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c =: userinfo.getUserId() and Status__c = 'Completed' Order By Completion_Date__c]; }return myCompletedPros; } public List<Process__c> getOtherCompletedProcesses() { if(otherCompletedPros == null) { otherCompletedPros = [Select Id, Name, Process_Owner__r.Name, Contact__c, Contact__r.MailingStreet, Contact__r.MailingCity, Contact__r.Phone, Process_Template__r.Name, Progress__c, Contact__r.Reason_for_no_Insurance__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Process_Template__r.Name = 'Insurance Profile Campaign' and Process_Owner__c !=: userinfo.getUserId() and Process_Owner__r.Name != 'Chris Duncombe' and Status__c = 'Completed' Order By Process_Owner__r.Name, Completion_Date__c ASC]; }return otherCompletedPros; } public void takeOwnership() { selectedProcess = [Select Id, Name, Process_Owner__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Id =: system.currentPageReference().getParameters().get('proId')]; step = [Select Id, Name, Assigned_To__c From Process_Step__c Where Process__c =: selectedProcess.id]; selectedProcess.Process_Owner__c = userinfo.getUserId(); selectedProcess.Start_Date__c = system.today(); step.Assigned_To__c = userinfo.getUserId(); update selectedProcess; update step; myPros = null; } public void setStep() { showStep = true; selectedProcess = [Select Id, Name, Contact__c, Process_Owner__c, Start_Date__c, Completion_Date__c, Total_Process_Time__c, Outcome__c From Process__c Where Id =: system.currentPageReference().getParameters().get('proId')]; step = [Select Id, Name, Process__c, Complete_Step_From_Process__c, Log_Activity_From_Process__c, Create_Task_From_Process__c, Status__c, Completed_By__c, Date_Completed__c, Assigned_To__c From Process_Step__c Where Process__c =: selectedProcess.id]; con = [Select Id, Name From Contact Where id =: SelectedProcess.Contact__c]; } public process_Step__c getMyStep() { return step; } public List<Task> getStepActivities() { acts = [Select Id, Subject, Navigator_Subject__c, ActivityDate, Description, WhoId, OwnerId, WhatId From Task Where WhatId =: step.id]; return acts; } public void saveProcessChanges() { update selectedProcess; } public void viewMine() { Filter = 'Show Mine'; showStep = false; } public void viewAll() { Filter = 'Show All'; showStep = false; } public void viewOthers() { Filter = 'Show Others'; showStep = false; } public void viewMyCompleted() { Filter = 'Show My Completed'; showStep = false; } public void viewOtherCompleted() { Filter = 'Show Other Completed'; showStep = false; } }
Any help would be greatly appreicated
Chris
- cduncombe44
- July 12, 2012
- Like
- 0
SOQL inside FOR loop.....need help
Hello all,
So I have a simple trigger that does not work for bulk inserts because I have a SOQL statement inside of a for loop. I know this is the reason, I just can't figure out how to accomplish it without the SOQL in the FOR loop.
I have created a few custom objects to create repeatable processes. There are Process Templates, Process Template Steps, Processes, and Process Steps. As you can guess, you create a process Template, which has process template steps, so you can then create processes that are based on those templates.
I have wrote a simple trigger that each time you create a process, it creates the process steps based on the template steps.
trigger CreateStepsForProcess on Process__c (after insert) { List<Process_Step__c> StepList = new List<Process_Step__c>(); Process_Template__c proTemp = new Process_Template__c(); For (Process__c pro: trigger.new){ proTemp = [Select Id, Name From Process_Template__c Where id =: pro.Process_Template__c]; For (Process_Template_Step__c tempStep: [Select Id, Name, Sequence__c, Process_Template__c, Details__c, Assign_To__c From Process_Template_Step__c Where Process_Template__c =: proTemp.id]) { Process_Step__c step = new Process_Step__c( Name = tempStep.Name, Step_Details__c = tempStep.Details__c, Process__c = pro.Id, Sequence__c = tempStep.Sequence__c, Task_Created__c = 'N' ); if(step.Sequence__c == 1){ step.Status__c = 'Open'; } else { step.Status__c = 'Not Started'; } StepList.add(step); } } insert StepList; }
I'm sure this can be accomplished with a few different Lists and/or Maps outside of the FOR loop, I have just had no luck in accomplishing this. Any help is greatly appreciated. Thanks so much
Chris
- cduncombe44
- July 02, 2012
- Like
- 0