-
ChatterFeed
-
1Best Answers
-
0Likes Received
-
0Likes Given
-
7Questions
-
11Replies
Test Method for a Lookup Field
Hello
We are looking for assistance on how to write a test class for the below code. If anyone could assist or direct me to another page that would be appreciated. We are using this lookup field and 'converting' it to a pick list type field for ease of use.
public class PropertyStagePL { private MyApp__Property__c property; public PropertyStagePL(ApexPages.StandardController controller) { this.property = (MyApp__Property__c)controller.getRecord(); } public List <SelectOption> getStage { Get{ // GET CURRENT RECORD RECORD TYPE INFO List<RecordType> bList = [SELECT Id, Name,SobjectType,DeveloperName FROM RecordType WHERE Id =:property.RecordTypeId]; // FIND MATCHING STAGE RECORD TYPE FOR CURRENT RECORD List<RecordType> cList = [SELECT Id, Name,SobjectType,DeveloperName FROM RecordType WHERE DeveloperName =:bList[0].DeveloperName AND SobjectType='MyStage__Stage__c']; List <SelectOption> stage = new List <SelectOption>(); for( MyStage__Stage__c st: [SELECT Name, RecordType.Id, RecordType.Name, MyStage__Value__c, MyStage__Order_Number__c FROM MyStage__Stage__c WHERE MyStage__Active__c = TRUE AND RecordTypeId = :cList[0].Id ORDER BY MyStage__Order_Number__c ASC ]) stage.add(new selectOption(st.id, '('+st.MyStage__Order_Number__c +') '+st.MyStage__Value__c)); return stage; } Set; } }
- miiWorks
- October 10, 2012
- Like
- 0
EmailTemplaye native salesforce object
Hello
I am looking to draw data from the native "EmailTemplate" object on a visualforce page. I cannot create a lookup field to the object. Is this possible?
My end result is to essetnailly populate a richt text html field on the record, with that of the field value of an existing email template. The record is a "Ticket Comment" object, which the user should be able to select an email template, and once selected, push in the value of the related EmailTemplate record into the rich html field, i assume using a rerender
Thanks
- miiWorks
- September 07, 2012
- Like
- 0
Help with Test Method Code Coverage >75%
Hello
We are having an issue with getting our code coverage to an acceptable level. Can anyone suggest what to add to the test class to get our code coverage up to 75% (100%)?
Public Class
public with sharing class LoanApplicationOnUpdateHandler{ public String LoanAppId; public Decimal ValuationAmt=0; public void OnAfterInsert(List<MyApp__Property__c> newRecords){ updateLoanApplication(newRecords); } public void OnAfterUpdate(List<MyApp__Property__c> updatedRecords){ updateLoanApplication(updatedRecords); } // updates the loan application with various amounts from all properties assigned to it via the junction private void updateLoanApplication(List<MyApp__Property__c> newRecords) { List<MyApp__Property__c> PropsWithJoins = [select Id, Name, (select Id, MyApp__Loan_Application__c from MyApp__Link_Between_Loan_Application_Property__r) FROM MyApp__Property__c WHERE Id IN :Trigger.newMap.keySet()]; List<MyApp__Loan_Application__c> LoansToUpdate = new List<MyApp__Loan_Application__c>{}; for(MyApp__Property__c b: PropsWithJoins){ // LISTS ALL LINK RECORDS FOR PROPERTY for(MyApp__Link_Between_Loan_Application_Property__c c: b.MyApp__Link_Between_Loan_Application_Property__r){ ValuationAmt=0; // FIND ALL LOAN APPS FROM LINKED PROPERTIES List<MyApp__Loan_Application__c> PropLinkwithLoans = [select Id, Name, (select Id, Name,MyApp__Loan_Application__c,MyApp__Property__c FROM MyApp__Link_Between_Loan_Application_Property__r) FROM MyApp__Loan_Application__c WHERE Id =:c.MyApp__Loan_Application__c]; for(MyApp__Loan_Application__c d: PropLinkwithLoans ){ for(MyApp__Link_Between_Loan_Application_Property__c h: d.MyApp__Link_Between_Loan_Application_Property__r){ // FIND ALL PROPERTIES FOR THAT LOAN APP TO SUM UP INFO List<MyApp__Property__c> PropwithLinkLoans1 = [select Id, Name,MyApp__Valuation_Estimated_Value_Dollars__c, (select Id, Name from MyApp__Link_Between_Loan_Application_Property__r) FROM MyApp__Property__c WHERE Id =:h.MyApp__Property__c]; for(MyApp__Property__c aa: PropwithLinkLoans1){ ValuationAmt=ValuationAmt + aa.MyApp__Valuation_Estimated_Value_Dollars__c; } // RETURN LOAN AND UPDATE List<MyApp__Loan_Application__c> LoanToUpdate= [SELECT i.Id, i.Name,i.MyApp__Total_Security_Amount_Dollars__c FROM MyApp__Loan_Application__c i WHERE i.Id = :c.MyApp__Loan_Application__c LIMIT 1]; for (MyApp__Loan_Application__c LoanToUpdate1: LoanToUpdate) LoanToUpdate1.MyApp__Total_Security_Amount_Dollars__c = ValuationAmt; UPDATE LoanToUpdate; } } } } } }
test class error report, red errors in the test check
8 public with sharing class LoanApplicationOnUpdateHandler{
9 public String LoanAppId;
10 public Decimal ValuationAmt=0;
11 public void OnAfterInsert(List<MyApp__Property__c> newRecords){
12 updateLoanApplication(newRecords);
13 }
14 public void OnAfterUpdate(List<MyApp__Property__c> updatedRecords){
15 updateLoanApplication(updatedRecords);
16 }
17 // updates the loan application with various amounts from all properties assigned to it via the junction
18 private void updateLoanApplication(List<MyApp__Property__c> newRecords) {
19 List<MyApp__Property__c> PropsWithJoins = [select Id, Name,
20 (select Id, MyApp__Loan_Application__c from MyApp__Link_Between_Loan_Application_Property__r)
21 FROM MyApp__Property__c
22 WHERE Id IN :Trigger.newMap.keySet()];
23 List<MyApp__Loan_Application__c> LoansToUpdate = new List<MyApp__Loan_Application__c>{};
24 for(MyApp__Property__c b: PropsWithJoins){
25 // LISTS ALL LINK RECORDS FOR PROPERTY
26 for(MyApp__Link_Between_Loan_Application_Property__c c: b.MyApp__Link_Between_Loan_Application_Property__r){
27 ValuationAmt=0;
28 // FIND ALL LOAN APPS FROM LINKED PROPERTIES
29 List<MyApp__Loan_Application__c> PropLinkwithLoans = [select Id, Name,
30 (select Id, Name,MyApp__Loan_Application__c,MyApp__Property__c
31 FROM MyApp__Link_Between_Loan_Application_Property__r)
32 FROM MyApp__Loan_Application__c
33 WHERE Id =:c.MyApp__Loan_Application__c];
34 for(MyApp__Loan_Application__c d: PropLinkwithLoans ){
35 for(MyApp__Link_Between_Loan_Application_Property__c h: d.MyApp__Link_Between_Loan_Application_Property__r){
36 // FIND ALL PROPERTIES FOR THAT LOAN APP TO SUM UP INFO
37 List<MyApp__Property__c> PropwithLinkLoans1 = [select Id, Name,MyApp__Valuation_Estimated_Value_Dollars__c,
38 (select Id, Name from MyApp__Link_Between_Loan_Application_Property__r)
39 FROM MyApp__Property__c
40 WHERE Id =:h.MyApp__Property__c];
41 for(MyApp__Property__c aa: PropwithLinkLoans1){
42 ValuationAmt=ValuationAmt + aa.MyApp__Valuation_Estimated_Value_Dollars__c;
43 }
44 // RETURN LOAN AND UPDATE
45 List<MyApp__Loan_Application__c> LoanToUpdate= [SELECT i.Id, i.Name,i.MyApp__Total_Security_Amount_Dollars__c
46 FROM MyApp__Loan_Application__c i
47 WHERE i.Id = :c.MyApp__Loan_Application__c LIMIT 1];
48 for (MyApp__Loan_Application__c LoanToUpdate1: LoanToUpdate)
49 LoanToUpdate1.MyApp__Total_Security_Amount_Dollars__c = ValuationAmt;
50 UPDATE LoanToUpdate;
51 }
52 }
53 }
54 }
55 }
56 }
Test class to be posted as limit exceeded on this post
- miiWorks
- August 08, 2012
- Like
- 0
Native Filtered Lookup Causing Error in VF
Hello
I have a class which is being used to display a picklist (from a lookup type field), which has a filtered lookup resitrciton (an Id of another relationship must be the same as the child lookup to the parent). This is to ensure you can only select a product from that financier.
This works ok in native, however in VF i get this error
System.TypeException: Invalid conversion from runtime type SOBJECT:miiHomeLoan__Loan_Split__c to SOBJECT:miiHomeLoan__Loan_Product__c Class.ProductList.: line 5, column 1
How am i able to replicate the lookup behaviour, and make sure the Id from the other field is being used in my class?
Here is my class
public class ProductList {
private miiHomeLoan__Loan_Product__c loanproduct;
public ProductList(ApexPages.StandardController controller) {
this.loanproduct = (miiHomeLoan__Loan_Product__c)controller.getRecord();
}
public List <SelectOption> getLoanProduct {
Get{
List <SelectOption> loanproduct = new List <SelectOption>();
for( miiHomeLoan__Loan_Product__c lp: [Select Name FROM miiHomeLoan__Loan_Product__c WHERE miiHomeLoan__Active__c = TRUE ]){
loanproduct.add(new selectOption(lp.id, lp.Name));
}
return loanproduct;
}
Set;
}
}
Here is my VF
<apex:page showHeader="true" standardController="miiHomeLoan__Loan_Split__c" extensions="FunderList,ProductList" id="thePage"> <apex:form id="theForm"> <apex:sectionHeader title="Loan Split" subtitle="New Loan Split"/> <apex:pageBlock title="New Loan Split"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Financier & Loan Application" columns="2" collapsible="false"> <apex:pageblockSectionItem > <apex:outputLabel value="Financier"/> <apex:ActionRegion > <apex:selectList id="funder" value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier__c}" size="1" title="Financier" required="true" > <apex:selectOptions value="{!getFunder}"/> <apex:actionSupport event="onchange" status="StatusChange" rerender="informationcontainer"/> </apex:selectList> <apex:actionStatus startText="Refreshing..." id="StatusChange"/> </apex:ActionRegion> </apex:pageblockSectionItem> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Application__c}" required="true" /> </apex:pageBlockSection> <apex:outputPanel id="informationcontainer"> <apex:pageBlockSection title="Loan Product" columns="2" collapsible="false" id="information" rendered="{!IF(miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier__c <> '', true, false)}"> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Product__c}" required="true" /> </apex:pageBlockSection> </apex:outputPanel> <apex:pageBlockSection title="Loan Product Details" collapsible="false"> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Amount_Dollars__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Status__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Repay_Type__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Account_Number__c}" required="false" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.Purpose__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier_Split_ID__c}" required="false" /> <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Loan_Purpose_Note__c}" required="false" /> <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Repayment_to_Come_From__c}" required="false" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Deduct_Term__c}" required="true" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
I think i have to store the id from the other field, and refernce it in my query, but im not sure how to do this. I do have this sample code but i couldnt get it to work
public class MilestoneList { private ApexPages.StandardController stdCtrl; public MilestoneList(ApexPages.StandardController controller) { stdCtrl=controller; } List<miiProject__Project_Milestone__c> myList; Public List<miiProject__Project_Milestone__c> getMilestoneList() { myList = [SELECT Id, IsDeleted, Name, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, miiProject__Project__c, miiProject__Account_Name__c, miiProject__Active__c, miiProject__Contact_Name__c, miiProject__Date_Due__c, miiProject__Date_Time_Completed__c, miiProject__Date_Time_Started__c, miiProject__Description__c, miiProject__Is_Closed__c, miiProject__Project_Manager_Name__c, miiProject__Public__c, miiProject__Status__c, miiProject__Subject__c, miiProject__Actual_Hours_Completed__c, miiProject__Actual_Hours_Total__c, miiProject__Number_Of_Project_Tasks_Completed__c, miiProject__Number_Of_Project_Tasks__c, ID_Historic__c, Date_Created_Historic__c, Date_Signed_Off__c, Signed_Off__c, Date_Completed__c FROM miiProject__Project_Milestone__c WHERE miiProject__Project__c=:stdCtrl.getId() ORDER BY miiProject__Date_Due__c ASC ]; /// ORDER BY CAN BE ASC OR DESC return myList; } public static testmethod void Test1() { miiProject__Project_Milestone__c p=new miiProject__Project_Milestone__c(); ApexPages.StandardController sc = new ApexPages.standardController(p); MilestoneList Mil=new MilestoneList (sc); Mil.getMilestoneList(); } }
- miiWorks
- June 05, 2012
- Like
- 0
Rerender not behaving correcly
Hello, i have a rerender setup on the miiHomeLoan__Financier__c field, which will make the miiHomeLoan__Loan_Product__c field (section) display. It works on a new page, and i can select a value (its a class calling on another object, see class), however when i change it back to "- Select Financier -" (which has/should have a null value), the page does not rerender and remove the section id="loanproduct"
Any ideas?
Class
public class FunderList { private miiHomeLoan__Loan_Split__c loansplit; public FunderList(ApexPages.StandardController controller) { this.loansplit = (miiHomeLoan__Loan_Split__c)controller.getRecord(); } public List <SelectOption> getFunder { Get{ List <SelectOption> funder = new List <SelectOption>(); funder.add(new selectOption('','- Select Financier -')); for( miiHomeLoan__Financier__c fu: [Select Name FROM miiHomeLoan__Financier__c WHERE miiHomeLoan__Active__c = TRUE ]){ funder.add(new selectOption(fu.id, fu.Name)); } return funder; } Set; } }
VF
<apex:page showHeader="true" standardController="miiHomeLoan__Loan_Split__c" extensions="FunderList" id="thePage"> <apex:form id="theForm"> <apex:sectionHeader title="Loan Split" subtitle="New Loan Split"/> <apex:pageBlock title="Loan Split Edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="2" collapsible="true"> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Amount_Dollars__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Application__c}" required="true" /> <apex:pageblockSectionItem > <apex:outputLabel value="Financier"/> <apex:actionRegion > <apex:selectList id="funder" value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier__c}" size="1" title="Financier" required="true" > <apex:selectOptions value="{!getFunder}"/> <apex:actionSupport event="onchange" status="StatusChange" rerender="loanproduct"/> </apex:selectList> <apex:actionStatus startText="Refreshing..." id="StatusChange"/> </apex:actionRegion> </apex:pageblockSectionItem> <apex:outputPanel id="loanproduct"> <apex:pageblockSectionItem > <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Product__c}" required="true" /> </apex:pageblockSectionItem> </apex:outputPanel> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Repay_Type__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Account_Number__c}" required="false" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.Purpose__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier_Split_ID__c}" required="false" /> <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Loan_Purpose_Note__c}" required="false" /> <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Repayment_to_Come_From__c}" required="false" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Status__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Deduct_Term__c}" required="false" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- miiWorks
- June 05, 2012
- Like
- 0
Apex Test Class Only 35%
Hello
I am very new to writing test classes, could someone please give me some direction on why this test clasee is only achieving 35% code coverage?
Thank you!
public class PresentationWithTicketTypeController { //added an instance varaible for the standard controller private ApexPages.StandardController controller {get; set;} // add the instance for the variables being passed by id on the url private miiEventV1__Presentation__c pres {get;set;} // set the id of the record that is created -- ONLY USED BY THE TEST CLASS public ID newRecordId {get;set;} // initialize the controller public PresentationWithTicketTypeController(ApexPages.StandardController controller) { //initialize the stanrdard controller this.controller = controller; // load the current record pres = (miiEventV1__Presentation__c)controller.getRecord(); } // method called from the VF's action attribute to clone the pres public PageReference cloneWithItems() { // setup the save point for rollback Savepoint sp = Database.setSavepoint(); miiEventV1__Presentation__c newPRES; try { //copy the project plan - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE pres = [Select Id, RecordTypeId, miiEventV1__Status__c, miiEventV1__Presentation_Type__c, miiEventV1__Active__c, miiEventV1__Actual_Duraction_Mins__c, miiEventV1__Booking_Link__c, miiEventV1__Breaks_and_Refreshments__c, miiEventV1__Date_Publish_Media__c, miiEventV1__Date_of_Presentation__c, miiEventV1__Display_Name__c, miiEventV1__GoToWebinar_Prefix__c, miiEventV1__Long_Description__c, miiEventV1__Media_Description__c, miiEventV1__Media_Duration_MM_SS__c, miiEventV1__Media_URL__c, miiEventV1__Presentation_Times__c, miiEventV1__Presentation_Type_Display_Name__c, miiEventV1__Short_Description__c, miiEventV1__Tags__c, miiEventV1__Time_Zone__c, miiEventV1__Venue_Room__c, miiEventV1__Venue__c, miiEventV1__Video_Domain__c, miiEventV1__Video_Height__c, miiEventV1__Video_Type__c, miiEventV1__Video_Width__c, miiEventV1__Webinar_ID__c, miiEventV1__Webinar_Maximum_Registrations__c, miiEventV1__What_You_Will_Learn__c, Media_Channel_ID__c, Amazon_Bucket__c, Amazon_File_Name__c, Media_Centre_Program_Name__c, YouTube_Video_ID__c, YouTube_Display_in_HD__c, Start_Video_at__c, Record_Type_Custom__c, Viewing_Security__c FROM miiEventV1__Presentation__c where id = :pres.id]; newPRES = pres.clone(false); newPRES.miiEventV1__Status__c = 'Planned'; newPRES.miiEventV1__Active__c = true; newPRES.miiEventV1__Video_Type__c = ''; newPRES.miiEventV1__Media_Description__c = 'TBA'; newPRES.miiEventV1__Media_Duration_MM_SS__c = 00.00; newPRES.miiEventV1__Media_URL__c = ''; newPRES.miiEventV1__Tags__c = ''; newPRES.Start_Video_at__c = NULL; newPRES.miiEventV1__Date_Publish_Media__c = NULL; newPRES.Amazon_File_Name__c = ''; newPRES.YouTube_Video_ID__c = ''; insert newPRES; // set the id of the new pres created for testing newRecordId = newPRES.id; // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Presentation_Ticket_Type__c> tickettypes = new List<miiEventV1__Presentation_Ticket_Type__c>(); for (miiEventV1__Presentation_Ticket_Type__c ptt : [Select Id, Name, miiEventV1__Presentation__c, miiEventV1__Active__c, miiEventV1__Amount_Per_Ticket__c, miiEventV1__Maximum_Tickets_Available__c, miiEventV1__Ticket_Type_Internal_Name__c, miiEventV1__Ticket_Type_Website_Name__c, miiEventV1__Ticket_Type__c, miiEventV1__Total_Expected_Revenue__c, Product_For_Sale__c, Ticket_Image_URL__c, Display_Groups__c FROM miiEventV1__Presentation_Ticket_Type__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Presentation_Ticket_Type__c newPTT = ptt.clone(false); newPTT.miiEventV1__Presentation__c = newPRES.id; tickettypes.add(newPTT); } // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Speaker2Presentation__c> speakers = new List<miiEventV1__Speaker2Presentation__c>(); for (miiEventV1__Speaker2Presentation__c psp : [Select miiEventV1__Presentation__c, miiEventV1__Speaker__c, miiEventV1__Active__c FROM miiEventV1__Speaker2Presentation__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Speaker2Presentation__c newPSP = psp.clone(false); newPSP.miiEventV1__Presentation__c = newPRES.id; speakers.add(newPSP); } insert tickettypes; insert speakers; } catch (Exception e){ // roll everything back in case of error Database.rollback(sp); ApexPages.addMessages(e); return null; } //return new PageReference('/apex/PresentationView?id='+newPRES.id); return new PageReference('/'+newPRES.id); } public static testmethod void Test1() { miiEventV1__Presentation__c p=new miiEventV1__Presentation__c(); ApexPages.StandardController sc = new ApexPages.standardController(p); PresentationWithTicketTypeController pres=new PresentationWithTicketTypeController (sc); pres.cloneWithItems(); } }
- miiWorks
- May 31, 2012
- Like
- 0
Set Static Field Value on Custom Field in Apex Class On New Record Save
Hello. I am hoping this is something simple. I have written a class to do a 'deep cloe' and copy child record. On my parent (Presentation__c) I am wanting to override the clone value of the "miiEventV1__Status__c" field with the value of 'Planned'. I have validation which is conflicting, so each cloned/new record, should have this field set to the static value. The issue is that on my clone, it will usually have another value, thus the reason to statically set the field value.
Here is my Controller, with my commented out attempt prior to the insert of the new record. Can anyone offer a suggestion how to set a fixed value at creation of my new record
Thanks
public class PresentationWithTicketTypeController { //added an instance varaible for the standard controller private ApexPages.StandardController controller {get; set;} // add the instance for the variables being passed by id on the url private miiEventV1__Presentation__c pres {get;set;} // set the id of the record that is created -- ONLY USED BY THE TEST CLASS public ID newRecordId {get;set;} // initialize the controller public PresentationWithTicketTypeController(ApexPages.StandardController controller) { //initialize the stanrdard controller this.controller = controller; // load the current record pres = (miiEventV1__Presentation__c)controller.getRecord(); } // method called from the VF's action attribute to clone the pres public PageReference cloneWithItems() { // setup the save point for rollback Savepoint sp = Database.setSavepoint(); miiEventV1__Presentation__c newPRES; try { //copy the project plan - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE pres = [Select Id, RecordTypeId, miiEventV1__Status__c, miiEventV1__Presentation_Type__c, miiEventV1__Active__c, miiEventV1__Actual_Duraction_Mins__c, miiEventV1__Booking_Link__c, miiEventV1__Breaks_and_Refreshments__c, miiEventV1__Date_Publish_Media__c, miiEventV1__Date_of_Presentation__c, miiEventV1__Display_Name__c, miiEventV1__GoToWebinar_Prefix__c, miiEventV1__Long_Description__c, miiEventV1__Media_Description__c, miiEventV1__Media_Duration_MM_SS__c, miiEventV1__Media_URL__c, miiEventV1__Presentation_Times__c, miiEventV1__Presentation_Type_Display_Name__c, miiEventV1__Short_Description__c, miiEventV1__Tags__c, miiEventV1__Time_Zone__c, miiEventV1__Venue_Room__c, miiEventV1__Venue__c, miiEventV1__Video_Domain__c, miiEventV1__Video_Height__c, miiEventV1__Video_Type__c, miiEventV1__Video_Width__c, miiEventV1__Webinar_ID__c, miiEventV1__Webinar_Maximum_Registrations__c, miiEventV1__What_You_Will_Learn__c, Media_Channel_ID__c, Amazon_Bucket__c, Amazon_File_Name__c, Media_Centre_Program_Name__c, YouTube_Video_ID__c, YouTube_Display_in_HD__c, Start_Video_at__c, Record_Type_Custom__c, Viewing_Security__c FROM miiEventV1__Presentation__c where id = :pres.id]; newPRES = pres.clone(false);
//pres.miiEventV1__Status__c = 'Planned'; insert newPRES; // set the id of the new pres created for testing newRecordId = newPRES.id; // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Presentation_Ticket_Type__c> tickettypes = new List<miiEventV1__Presentation_Ticket_Type__c>(); for (miiEventV1__Presentation_Ticket_Type__c ptt : [Select Id, Name, miiEventV1__Presentation__c, miiEventV1__Active__c, miiEventV1__Amount_Per_Ticket__c, miiEventV1__Maximum_Tickets_Available__c, miiEventV1__Ticket_Type_Internal_Name__c, miiEventV1__Ticket_Type_Website_Name__c, miiEventV1__Ticket_Type__c, miiEventV1__Total_Expected_Revenue__c, Product_For_Sale__c, Ticket_Image_URL__c, Display_Groups__c FROM miiEventV1__Presentation_Ticket_Type__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Presentation_Ticket_Type__c newPTT = ptt.clone(false); newPTT.miiEventV1__Presentation__c = newPRES.id; tickettypes.add(newPTT); } // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Speaker2Presentation__c> speakers = new List<miiEventV1__Speaker2Presentation__c>(); for (miiEventV1__Speaker2Presentation__c psp : [Select miiEventV1__Presentation__c, miiEventV1__Speaker__c, miiEventV1__Active__c FROM miiEventV1__Speaker2Presentation__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Speaker2Presentation__c newPSP = psp.clone(false); newPSP.miiEventV1__Presentation__c = newPRES.id; speakers.add(newPSP); } insert tickettypes; insert speakers; } catch (Exception e){ // roll everything back in case of error Database.rollback(sp); ApexPages.addMessages(e); return null; } return new PageReference('/'+newPRES.id); } public static testmethod void Test1() { miiEventV1__Presentation__c p=new miiEventV1__Presentation__c(); ApexPages.StandardController sc = new ApexPages.standardController(p); PresentationWithTicketTypeController pres=new PresentationWithTicketTypeController (sc); pres.cloneWithItems(); } }
- miiWorks
- May 30, 2012
- Like
- 0
Test Method for a Lookup Field
Hello
We are looking for assistance on how to write a test class for the below code. If anyone could assist or direct me to another page that would be appreciated. We are using this lookup field and 'converting' it to a pick list type field for ease of use.
public class PropertyStagePL { private MyApp__Property__c property; public PropertyStagePL(ApexPages.StandardController controller) { this.property = (MyApp__Property__c)controller.getRecord(); } public List <SelectOption> getStage { Get{ // GET CURRENT RECORD RECORD TYPE INFO List<RecordType> bList = [SELECT Id, Name,SobjectType,DeveloperName FROM RecordType WHERE Id =:property.RecordTypeId]; // FIND MATCHING STAGE RECORD TYPE FOR CURRENT RECORD List<RecordType> cList = [SELECT Id, Name,SobjectType,DeveloperName FROM RecordType WHERE DeveloperName =:bList[0].DeveloperName AND SobjectType='MyStage__Stage__c']; List <SelectOption> stage = new List <SelectOption>(); for( MyStage__Stage__c st: [SELECT Name, RecordType.Id, RecordType.Name, MyStage__Value__c, MyStage__Order_Number__c FROM MyStage__Stage__c WHERE MyStage__Active__c = TRUE AND RecordTypeId = :cList[0].Id ORDER BY MyStage__Order_Number__c ASC ]) stage.add(new selectOption(st.id, '('+st.MyStage__Order_Number__c +') '+st.MyStage__Value__c)); return stage; } Set; } }
- miiWorks
- October 10, 2012
- Like
- 0
Help with Test Method Code Coverage >75%
Hello
We are having an issue with getting our code coverage to an acceptable level. Can anyone suggest what to add to the test class to get our code coverage up to 75% (100%)?
Public Class
public with sharing class LoanApplicationOnUpdateHandler{ public String LoanAppId; public Decimal ValuationAmt=0; public void OnAfterInsert(List<MyApp__Property__c> newRecords){ updateLoanApplication(newRecords); } public void OnAfterUpdate(List<MyApp__Property__c> updatedRecords){ updateLoanApplication(updatedRecords); } // updates the loan application with various amounts from all properties assigned to it via the junction private void updateLoanApplication(List<MyApp__Property__c> newRecords) { List<MyApp__Property__c> PropsWithJoins = [select Id, Name, (select Id, MyApp__Loan_Application__c from MyApp__Link_Between_Loan_Application_Property__r) FROM MyApp__Property__c WHERE Id IN :Trigger.newMap.keySet()]; List<MyApp__Loan_Application__c> LoansToUpdate = new List<MyApp__Loan_Application__c>{}; for(MyApp__Property__c b: PropsWithJoins){ // LISTS ALL LINK RECORDS FOR PROPERTY for(MyApp__Link_Between_Loan_Application_Property__c c: b.MyApp__Link_Between_Loan_Application_Property__r){ ValuationAmt=0; // FIND ALL LOAN APPS FROM LINKED PROPERTIES List<MyApp__Loan_Application__c> PropLinkwithLoans = [select Id, Name, (select Id, Name,MyApp__Loan_Application__c,MyApp__Property__c FROM MyApp__Link_Between_Loan_Application_Property__r) FROM MyApp__Loan_Application__c WHERE Id =:c.MyApp__Loan_Application__c]; for(MyApp__Loan_Application__c d: PropLinkwithLoans ){ for(MyApp__Link_Between_Loan_Application_Property__c h: d.MyApp__Link_Between_Loan_Application_Property__r){ // FIND ALL PROPERTIES FOR THAT LOAN APP TO SUM UP INFO List<MyApp__Property__c> PropwithLinkLoans1 = [select Id, Name,MyApp__Valuation_Estimated_Value_Dollars__c, (select Id, Name from MyApp__Link_Between_Loan_Application_Property__r) FROM MyApp__Property__c WHERE Id =:h.MyApp__Property__c]; for(MyApp__Property__c aa: PropwithLinkLoans1){ ValuationAmt=ValuationAmt + aa.MyApp__Valuation_Estimated_Value_Dollars__c; } // RETURN LOAN AND UPDATE List<MyApp__Loan_Application__c> LoanToUpdate= [SELECT i.Id, i.Name,i.MyApp__Total_Security_Amount_Dollars__c FROM MyApp__Loan_Application__c i WHERE i.Id = :c.MyApp__Loan_Application__c LIMIT 1]; for (MyApp__Loan_Application__c LoanToUpdate1: LoanToUpdate) LoanToUpdate1.MyApp__Total_Security_Amount_Dollars__c = ValuationAmt; UPDATE LoanToUpdate; } } } } } }
test class error report, red errors in the test check
8 public with sharing class LoanApplicationOnUpdateHandler{
9 public String LoanAppId;
10 public Decimal ValuationAmt=0;
11 public void OnAfterInsert(List<MyApp__Property__c> newRecords){
12 updateLoanApplication(newRecords);
13 }
14 public void OnAfterUpdate(List<MyApp__Property__c> updatedRecords){
15 updateLoanApplication(updatedRecords);
16 }
17 // updates the loan application with various amounts from all properties assigned to it via the junction
18 private void updateLoanApplication(List<MyApp__Property__c> newRecords) {
19 List<MyApp__Property__c> PropsWithJoins = [select Id, Name,
20 (select Id, MyApp__Loan_Application__c from MyApp__Link_Between_Loan_Application_Property__r)
21 FROM MyApp__Property__c
22 WHERE Id IN :Trigger.newMap.keySet()];
23 List<MyApp__Loan_Application__c> LoansToUpdate = new List<MyApp__Loan_Application__c>{};
24 for(MyApp__Property__c b: PropsWithJoins){
25 // LISTS ALL LINK RECORDS FOR PROPERTY
26 for(MyApp__Link_Between_Loan_Application_Property__c c: b.MyApp__Link_Between_Loan_Application_Property__r){
27 ValuationAmt=0;
28 // FIND ALL LOAN APPS FROM LINKED PROPERTIES
29 List<MyApp__Loan_Application__c> PropLinkwithLoans = [select Id, Name,
30 (select Id, Name,MyApp__Loan_Application__c,MyApp__Property__c
31 FROM MyApp__Link_Between_Loan_Application_Property__r)
32 FROM MyApp__Loan_Application__c
33 WHERE Id =:c.MyApp__Loan_Application__c];
34 for(MyApp__Loan_Application__c d: PropLinkwithLoans ){
35 for(MyApp__Link_Between_Loan_Application_Property__c h: d.MyApp__Link_Between_Loan_Application_Property__r){
36 // FIND ALL PROPERTIES FOR THAT LOAN APP TO SUM UP INFO
37 List<MyApp__Property__c> PropwithLinkLoans1 = [select Id, Name,MyApp__Valuation_Estimated_Value_Dollars__c,
38 (select Id, Name from MyApp__Link_Between_Loan_Application_Property__r)
39 FROM MyApp__Property__c
40 WHERE Id =:h.MyApp__Property__c];
41 for(MyApp__Property__c aa: PropwithLinkLoans1){
42 ValuationAmt=ValuationAmt + aa.MyApp__Valuation_Estimated_Value_Dollars__c;
43 }
44 // RETURN LOAN AND UPDATE
45 List<MyApp__Loan_Application__c> LoanToUpdate= [SELECT i.Id, i.Name,i.MyApp__Total_Security_Amount_Dollars__c
46 FROM MyApp__Loan_Application__c i
47 WHERE i.Id = :c.MyApp__Loan_Application__c LIMIT 1];
48 for (MyApp__Loan_Application__c LoanToUpdate1: LoanToUpdate)
49 LoanToUpdate1.MyApp__Total_Security_Amount_Dollars__c = ValuationAmt;
50 UPDATE LoanToUpdate;
51 }
52 }
53 }
54 }
55 }
56 }
Test class to be posted as limit exceeded on this post
- miiWorks
- August 08, 2012
- Like
- 0
Rerender not behaving correcly
Hello, i have a rerender setup on the miiHomeLoan__Financier__c field, which will make the miiHomeLoan__Loan_Product__c field (section) display. It works on a new page, and i can select a value (its a class calling on another object, see class), however when i change it back to "- Select Financier -" (which has/should have a null value), the page does not rerender and remove the section id="loanproduct"
Any ideas?
Class
public class FunderList { private miiHomeLoan__Loan_Split__c loansplit; public FunderList(ApexPages.StandardController controller) { this.loansplit = (miiHomeLoan__Loan_Split__c)controller.getRecord(); } public List <SelectOption> getFunder { Get{ List <SelectOption> funder = new List <SelectOption>(); funder.add(new selectOption('','- Select Financier -')); for( miiHomeLoan__Financier__c fu: [Select Name FROM miiHomeLoan__Financier__c WHERE miiHomeLoan__Active__c = TRUE ]){ funder.add(new selectOption(fu.id, fu.Name)); } return funder; } Set; } }
VF
<apex:page showHeader="true" standardController="miiHomeLoan__Loan_Split__c" extensions="FunderList" id="thePage"> <apex:form id="theForm"> <apex:sectionHeader title="Loan Split" subtitle="New Loan Split"/> <apex:pageBlock title="Loan Split Edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Information" columns="2" collapsible="true"> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Amount_Dollars__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Application__c}" required="true" /> <apex:pageblockSectionItem > <apex:outputLabel value="Financier"/> <apex:actionRegion > <apex:selectList id="funder" value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier__c}" size="1" title="Financier" required="true" > <apex:selectOptions value="{!getFunder}"/> <apex:actionSupport event="onchange" status="StatusChange" rerender="loanproduct"/> </apex:selectList> <apex:actionStatus startText="Refreshing..." id="StatusChange"/> </apex:actionRegion> </apex:pageblockSectionItem> <apex:outputPanel id="loanproduct"> <apex:pageblockSectionItem > <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Product__c}" required="true" /> </apex:pageblockSectionItem> </apex:outputPanel> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Repay_Type__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Account_Number__c}" required="false" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.Purpose__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Financier_Split_ID__c}" required="false" /> <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Loan_Purpose_Note__c}" required="false" /> <apex:inputTextarea cols="40" value="{!miiHomeLoan__Loan_Split__c.Repayment_to_Come_From__c}" required="false" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Loan_Split_Status__c}" required="true" /> <apex:inputField value="{!miiHomeLoan__Loan_Split__c.miiHomeLoan__Deduct_Term__c}" required="false" /> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
- miiWorks
- June 05, 2012
- Like
- 0
Apex Test Class Only 35%
Hello
I am very new to writing test classes, could someone please give me some direction on why this test clasee is only achieving 35% code coverage?
Thank you!
public class PresentationWithTicketTypeController { //added an instance varaible for the standard controller private ApexPages.StandardController controller {get; set;} // add the instance for the variables being passed by id on the url private miiEventV1__Presentation__c pres {get;set;} // set the id of the record that is created -- ONLY USED BY THE TEST CLASS public ID newRecordId {get;set;} // initialize the controller public PresentationWithTicketTypeController(ApexPages.StandardController controller) { //initialize the stanrdard controller this.controller = controller; // load the current record pres = (miiEventV1__Presentation__c)controller.getRecord(); } // method called from the VF's action attribute to clone the pres public PageReference cloneWithItems() { // setup the save point for rollback Savepoint sp = Database.setSavepoint(); miiEventV1__Presentation__c newPRES; try { //copy the project plan - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE pres = [Select Id, RecordTypeId, miiEventV1__Status__c, miiEventV1__Presentation_Type__c, miiEventV1__Active__c, miiEventV1__Actual_Duraction_Mins__c, miiEventV1__Booking_Link__c, miiEventV1__Breaks_and_Refreshments__c, miiEventV1__Date_Publish_Media__c, miiEventV1__Date_of_Presentation__c, miiEventV1__Display_Name__c, miiEventV1__GoToWebinar_Prefix__c, miiEventV1__Long_Description__c, miiEventV1__Media_Description__c, miiEventV1__Media_Duration_MM_SS__c, miiEventV1__Media_URL__c, miiEventV1__Presentation_Times__c, miiEventV1__Presentation_Type_Display_Name__c, miiEventV1__Short_Description__c, miiEventV1__Tags__c, miiEventV1__Time_Zone__c, miiEventV1__Venue_Room__c, miiEventV1__Venue__c, miiEventV1__Video_Domain__c, miiEventV1__Video_Height__c, miiEventV1__Video_Type__c, miiEventV1__Video_Width__c, miiEventV1__Webinar_ID__c, miiEventV1__Webinar_Maximum_Registrations__c, miiEventV1__What_You_Will_Learn__c, Media_Channel_ID__c, Amazon_Bucket__c, Amazon_File_Name__c, Media_Centre_Program_Name__c, YouTube_Video_ID__c, YouTube_Display_in_HD__c, Start_Video_at__c, Record_Type_Custom__c, Viewing_Security__c FROM miiEventV1__Presentation__c where id = :pres.id]; newPRES = pres.clone(false); newPRES.miiEventV1__Status__c = 'Planned'; newPRES.miiEventV1__Active__c = true; newPRES.miiEventV1__Video_Type__c = ''; newPRES.miiEventV1__Media_Description__c = 'TBA'; newPRES.miiEventV1__Media_Duration_MM_SS__c = 00.00; newPRES.miiEventV1__Media_URL__c = ''; newPRES.miiEventV1__Tags__c = ''; newPRES.Start_Video_at__c = NULL; newPRES.miiEventV1__Date_Publish_Media__c = NULL; newPRES.Amazon_File_Name__c = ''; newPRES.YouTube_Video_ID__c = ''; insert newPRES; // set the id of the new pres created for testing newRecordId = newPRES.id; // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Presentation_Ticket_Type__c> tickettypes = new List<miiEventV1__Presentation_Ticket_Type__c>(); for (miiEventV1__Presentation_Ticket_Type__c ptt : [Select Id, Name, miiEventV1__Presentation__c, miiEventV1__Active__c, miiEventV1__Amount_Per_Ticket__c, miiEventV1__Maximum_Tickets_Available__c, miiEventV1__Ticket_Type_Internal_Name__c, miiEventV1__Ticket_Type_Website_Name__c, miiEventV1__Ticket_Type__c, miiEventV1__Total_Expected_Revenue__c, Product_For_Sale__c, Ticket_Image_URL__c, Display_Groups__c FROM miiEventV1__Presentation_Ticket_Type__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Presentation_Ticket_Type__c newPTT = ptt.clone(false); newPTT.miiEventV1__Presentation__c = newPRES.id; tickettypes.add(newPTT); } // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Speaker2Presentation__c> speakers = new List<miiEventV1__Speaker2Presentation__c>(); for (miiEventV1__Speaker2Presentation__c psp : [Select miiEventV1__Presentation__c, miiEventV1__Speaker__c, miiEventV1__Active__c FROM miiEventV1__Speaker2Presentation__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Speaker2Presentation__c newPSP = psp.clone(false); newPSP.miiEventV1__Presentation__c = newPRES.id; speakers.add(newPSP); } insert tickettypes; insert speakers; } catch (Exception e){ // roll everything back in case of error Database.rollback(sp); ApexPages.addMessages(e); return null; } //return new PageReference('/apex/PresentationView?id='+newPRES.id); return new PageReference('/'+newPRES.id); } public static testmethod void Test1() { miiEventV1__Presentation__c p=new miiEventV1__Presentation__c(); ApexPages.StandardController sc = new ApexPages.standardController(p); PresentationWithTicketTypeController pres=new PresentationWithTicketTypeController (sc); pres.cloneWithItems(); } }
- miiWorks
- May 31, 2012
- Like
- 0
Set Static Field Value on Custom Field in Apex Class On New Record Save
Hello. I am hoping this is something simple. I have written a class to do a 'deep cloe' and copy child record. On my parent (Presentation__c) I am wanting to override the clone value of the "miiEventV1__Status__c" field with the value of 'Planned'. I have validation which is conflicting, so each cloned/new record, should have this field set to the static value. The issue is that on my clone, it will usually have another value, thus the reason to statically set the field value.
Here is my Controller, with my commented out attempt prior to the insert of the new record. Can anyone offer a suggestion how to set a fixed value at creation of my new record
Thanks
public class PresentationWithTicketTypeController { //added an instance varaible for the standard controller private ApexPages.StandardController controller {get; set;} // add the instance for the variables being passed by id on the url private miiEventV1__Presentation__c pres {get;set;} // set the id of the record that is created -- ONLY USED BY THE TEST CLASS public ID newRecordId {get;set;} // initialize the controller public PresentationWithTicketTypeController(ApexPages.StandardController controller) { //initialize the stanrdard controller this.controller = controller; // load the current record pres = (miiEventV1__Presentation__c)controller.getRecord(); } // method called from the VF's action attribute to clone the pres public PageReference cloneWithItems() { // setup the save point for rollback Savepoint sp = Database.setSavepoint(); miiEventV1__Presentation__c newPRES; try { //copy the project plan - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE pres = [Select Id, RecordTypeId, miiEventV1__Status__c, miiEventV1__Presentation_Type__c, miiEventV1__Active__c, miiEventV1__Actual_Duraction_Mins__c, miiEventV1__Booking_Link__c, miiEventV1__Breaks_and_Refreshments__c, miiEventV1__Date_Publish_Media__c, miiEventV1__Date_of_Presentation__c, miiEventV1__Display_Name__c, miiEventV1__GoToWebinar_Prefix__c, miiEventV1__Long_Description__c, miiEventV1__Media_Description__c, miiEventV1__Media_Duration_MM_SS__c, miiEventV1__Media_URL__c, miiEventV1__Presentation_Times__c, miiEventV1__Presentation_Type_Display_Name__c, miiEventV1__Short_Description__c, miiEventV1__Tags__c, miiEventV1__Time_Zone__c, miiEventV1__Venue_Room__c, miiEventV1__Venue__c, miiEventV1__Video_Domain__c, miiEventV1__Video_Height__c, miiEventV1__Video_Type__c, miiEventV1__Video_Width__c, miiEventV1__Webinar_ID__c, miiEventV1__Webinar_Maximum_Registrations__c, miiEventV1__What_You_Will_Learn__c, Media_Channel_ID__c, Amazon_Bucket__c, Amazon_File_Name__c, Media_Centre_Program_Name__c, YouTube_Video_ID__c, YouTube_Display_in_HD__c, Start_Video_at__c, Record_Type_Custom__c, Viewing_Security__c FROM miiEventV1__Presentation__c where id = :pres.id]; newPRES = pres.clone(false);
//pres.miiEventV1__Status__c = 'Planned'; insert newPRES; // set the id of the new pres created for testing newRecordId = newPRES.id; // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Presentation_Ticket_Type__c> tickettypes = new List<miiEventV1__Presentation_Ticket_Type__c>(); for (miiEventV1__Presentation_Ticket_Type__c ptt : [Select Id, Name, miiEventV1__Presentation__c, miiEventV1__Active__c, miiEventV1__Amount_Per_Ticket__c, miiEventV1__Maximum_Tickets_Available__c, miiEventV1__Ticket_Type_Internal_Name__c, miiEventV1__Ticket_Type_Website_Name__c, miiEventV1__Ticket_Type__c, miiEventV1__Total_Expected_Revenue__c, Product_For_Sale__c, Ticket_Image_URL__c, Display_Groups__c FROM miiEventV1__Presentation_Ticket_Type__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Presentation_Ticket_Type__c newPTT = ptt.clone(false); newPTT.miiEventV1__Presentation__c = newPRES.id; tickettypes.add(newPTT); } // copy over the child record - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE List<miiEventV1__Speaker2Presentation__c> speakers = new List<miiEventV1__Speaker2Presentation__c>(); for (miiEventV1__Speaker2Presentation__c psp : [Select miiEventV1__Presentation__c, miiEventV1__Speaker__c, miiEventV1__Active__c FROM miiEventV1__Speaker2Presentation__c where miiEventV1__Presentation__c = :pres.id]) { miiEventV1__Speaker2Presentation__c newPSP = psp.clone(false); newPSP.miiEventV1__Presentation__c = newPRES.id; speakers.add(newPSP); } insert tickettypes; insert speakers; } catch (Exception e){ // roll everything back in case of error Database.rollback(sp); ApexPages.addMessages(e); return null; } return new PageReference('/'+newPRES.id); } public static testmethod void Test1() { miiEventV1__Presentation__c p=new miiEventV1__Presentation__c(); ApexPages.StandardController sc = new ApexPages.standardController(p); PresentationWithTicketTypeController pres=new PresentationWithTicketTypeController (sc); pres.cloneWithItems(); } }
- miiWorks
- May 30, 2012
- Like
- 0
Trying to get a confirmation box before and after executing a custome clone process
Hello again,
I appreciate everyone's help. I am new to all this stuff, Apex, OOP, Java, and HTML.
I have created a custom clone process that clones the opportunity and related partner records. I would like to have a confirmation box (Are you sure?) and if the user clicks yes then create the clone otherwise stay at the original Opportunity page. If they click Yes, then run my custom class/method that clones and finally pop up an ok box that just lets them know the clone was successful. When they click 'Ok' then they should see the cloned opportunity.
Right now they click my custom button and then the current opp gets cloned and they see the new cloned opportunity.
Here is my the code that my custom button calls
<apex:page standardController="Opportunity" extensions="OppCloneWithPartnerRecsController" action="{!oppCloneWithPartners}"> <apex:pageMessages /> </apex:page>
I see examples using the java script confirmCancel method but it is not clear to me where I would move the action=oppCloneWithPartners piece???
- Eager-2-Learn
- May 13, 2010
- Like
- 0
Outbound message: Can they be triggered
and
2) can they be triggered when record is deleted on an object, whether it is custom or not
I would appreciate any insight to this
Thanks,
Mike
- msimonds
- September 19, 2008
- Like
- 0
how to display a visualforce page in home page whose height should vary dynamically
- sfdc-apex
- August 12, 2008
- Like
- 0