• Jeremy-Kraybill
  • NEWBIE
  • 50 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 25
    Replies

Hi folks,

     Iam just a step away to move my code to prod, my test class fails, here is my trigger and class, iam not sure how to fix it up..

Trigger:

 

trigger Opportunities on Opportunity (after insert) {
 
    Opportunities o = new Opportunities();
    o.SetContactRoleDefaults(Trigger.new);
 
}

Class:

 

public class Opportunities {
 
    // Default Constructor
    public Opportunities()
    {
    }
 
    // Sets default values on the Contact Role record created during Conversion. Called on AFTER INSERT
    public void SetContactRoleDefaults(Opportunity[] opptys)
    {
        /***************
        * Variables
        ***************/
        set<ID> set_opptyIDs = new set<ID>();
 
        /***************
        * Initial Loop
        ***************/
        // Get a set of the Opportunity IDs being affected.
        for(Opportunity o:opptys) {
            set_opptyIDs.add(o.id);
        }
 
        /***************
        * Process Records
        ***************/
        // Update the Contact Role record to be Primary and the Decision Maker
        list<OpportunityContactRole> list_opptyContactRolesToUpdate = new list<OpportunityContactRole>();
        for(OpportunityContactRole ocr:[select Id,IsPrimary,Role from OpportunityContactRole where OpportunityId in :set_opptyIDs]) {
            ocr.IsPrimary = true;
            ocr.Role = 'Primary Contact';
            list_opptyContactRolesToUpdate.add(ocr);

        }
 
        if (list_opptyContactRolesToUpdate.size() > 0) {
            update list_opptyContactRolesToUpdate;
        }
 
    }
}

 

Test Class:

@isTest
private class Opportunities {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Set<Id> optyIds = new Set<Id>();
       
    list<OpportunityContactRole> list_opptyContactRolesToUpdate = new list<OpportunityContactRole>();
        
      Account acc = new Account(Name = 'test', phone = '1234567890');
      insert acc;
      
      Opportunity opp = new Opportunity(SaleType__c = 'new', Name = 'test', AccountId = acc.Id ,Amount = 50,     

                                    CurrencyIsoCode = 'USD', CloseDate = Date.newInstance(2009,02,01), StageName = 'Closed',

                                    ForecastCategoryName = 'omitted', SystemType__c = 'Other', SystemQty__c = 0);
      insert opp;
      
      Account acc1 = new Account(Name = 'test', phone = '1234567890');
      insert acc1;
      
      Contact con = new Contact(LastName = 'Testing', AccountId = 'acc1.Id');
      insert con;
      
      OpportunityContactRole ocr = new OpportunityContactRole(IsPrimary = true, Role = 'Primary Contact', OpportunityId =

                                                              opp.Id, ContactId = 'con.Id');
      insert ocr;
      
        
    }
}

 

when i run the test it fails and i get this msg


System.StringException: Invalid id: acc1.Id

 

The class is 66% covered it is not covered in the highlighted part, so all i want to make sure the test class doesn't fails and it covers the highlighted lines, any help is appreciated guys.

 

TIA1

 


Hi there. Is it possible to set an attachment for a Messaging.MassEmailMessage object?

I hope so!

Thanks

  • February 15, 2009
  • Like
  • 0

There is a new alert on the partnerforce portal that is letting partners know of the upcoming "clickjack protection" for non-setup pages in winter '12. It seems to be stating that if a customer turns this on, ALL framed/iframed pages (visualforce or otherwise) will stop working.

 

Does anybody have any more information on this? If I'm reading it correctly, it's going to be an unusable feature for any customer who either has installed a package that uses frames or has done their own custom implementation using frames or iframes. I've personally seen dozens of customers who do this.

 

If this is the case, I hope SFDC at least has it turned off by default and boldly warns anyone who turns it on that it is likely to break pages if they use frames anywhere.

Hey all,

Does anyone know how to dynamically get listIds from Enhanced Lists?

 

ie: Bad practice:

 

 

<apex:enhancedList height="300" listId="00BM0000000LbS1" />

 

 

Good practice:

<apex:enhancedList height="300" listId="{!myListId}" />
  • April 26, 2011
  • Like
  • 0

Hi All,

We created an apex:component in our managed package which consists of  Fileupload field ,submit button,cancel button . and made access type as global for component and attributes.If we test this in our managed package developer org including it in a VF page its working fine and if we test it by adding it in a VF page of managedpackage installed version its working like this: component is loading (calling constructor) and when i click upload/cancel button throwing error :
The installed managed class Cloudrop.fileuploadcomponent is not visible

 

can any one help me out on this!

  • April 05, 2011
  • Like
  • 0

I have a Apex Scheduler class which will send out emails on nightly basis to designated compliance SMTP mail box.I want to set the "From" address of the email to be the user who created the record .I have the userId and can query the User objct and set the display name but not sure how to set the from address.

 

Is it possible?

 

Thanks for the help

-John

  • April 04, 2011
  • Like
  • 0

I was wondering how i could ference a standard controller and a custom controller at the same time?

 

Please Help. 

 

Thanks. 

Hi folks,

     Iam just a step away to move my code to prod, my test class fails, here is my trigger and class, iam not sure how to fix it up..

Trigger:

 

trigger Opportunities on Opportunity (after insert) {
 
    Opportunities o = new Opportunities();
    o.SetContactRoleDefaults(Trigger.new);
 
}

Class:

 

public class Opportunities {
 
    // Default Constructor
    public Opportunities()
    {
    }
 
    // Sets default values on the Contact Role record created during Conversion. Called on AFTER INSERT
    public void SetContactRoleDefaults(Opportunity[] opptys)
    {
        /***************
        * Variables
        ***************/
        set<ID> set_opptyIDs = new set<ID>();
 
        /***************
        * Initial Loop
        ***************/
        // Get a set of the Opportunity IDs being affected.
        for(Opportunity o:opptys) {
            set_opptyIDs.add(o.id);
        }
 
        /***************
        * Process Records
        ***************/
        // Update the Contact Role record to be Primary and the Decision Maker
        list<OpportunityContactRole> list_opptyContactRolesToUpdate = new list<OpportunityContactRole>();
        for(OpportunityContactRole ocr:[select Id,IsPrimary,Role from OpportunityContactRole where OpportunityId in :set_opptyIDs]) {
            ocr.IsPrimary = true;
            ocr.Role = 'Primary Contact';
            list_opptyContactRolesToUpdate.add(ocr);

        }
 
        if (list_opptyContactRolesToUpdate.size() > 0) {
            update list_opptyContactRolesToUpdate;
        }
 
    }
}

 

Test Class:

@isTest
private class Opportunities {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
        Set<Id> optyIds = new Set<Id>();
       
    list<OpportunityContactRole> list_opptyContactRolesToUpdate = new list<OpportunityContactRole>();
        
      Account acc = new Account(Name = 'test', phone = '1234567890');
      insert acc;
      
      Opportunity opp = new Opportunity(SaleType__c = 'new', Name = 'test', AccountId = acc.Id ,Amount = 50,     

                                    CurrencyIsoCode = 'USD', CloseDate = Date.newInstance(2009,02,01), StageName = 'Closed',

                                    ForecastCategoryName = 'omitted', SystemType__c = 'Other', SystemQty__c = 0);
      insert opp;
      
      Account acc1 = new Account(Name = 'test', phone = '1234567890');
      insert acc1;
      
      Contact con = new Contact(LastName = 'Testing', AccountId = 'acc1.Id');
      insert con;
      
      OpportunityContactRole ocr = new OpportunityContactRole(IsPrimary = true, Role = 'Primary Contact', OpportunityId =

                                                              opp.Id, ContactId = 'con.Id');
      insert ocr;
      
        
    }
}

 

when i run the test it fails and i get this msg


System.StringException: Invalid id: acc1.Id

 

The class is 66% covered it is not covered in the highlighted part, so all i want to make sure the test class doesn't fails and it covers the highlighted lines, any help is appreciated guys.

 

TIA1

 


Hi,

 

I need to come up with a piece of code that will allow me to determine if the case owner is a queue or a user, The first things that come to my mind is to run a query on the owner and try to store the result to a user obect. If it faile therefore the case owner is a queue. I don't think this is a slick solution bo any means, so I am hoping someone can provide with a better suggestion.

 

Thank you.

  • March 30, 2011
  • Like
  • 0

There must be some way to tell because both the Profile detail page and the enhanced list view indicate whether the profile is custom.

I have a trigger on a custom object which depending on some criteria; it is supposed to create a list of emails to send.  I have created the trigger and it works fine.  Code coverage is 100%.  I’m ready to deploy it to production.

 

I’m calling a future method to process the records asynchronously.  I was expecting to be able to pass a list of account Ids created from my 2000 records to the future method to process but the trigger gives me 200 records at a time.  By the time the test method is done running, I’m very close to the limit of Number of future calls I can make.  What I really wanted and expected was for the future method to be called once and for all the processing to happen there.

 

Why does the trigger or apex automatically break up the 2000 records into bunches of 200 and process them separately? 

 

10:18:45.395|METHOD_EXIT|[7]|testAWAfterInsert

10:18:45.395|METHOD_ENTRY|[69]|System.debug(ANY)

10:18:45.395|USER_DEBUG|[69]|DEBUG|********** TEST 5 **********

10:18:47.357|METHOD_EXIT|[84]|system.Test.startTest()

10:18:47.358|DML_BEGIN|[85]|Op:Insert|Type:Actuals_Weekly__c|Rows:2000

10:18:48.160|USER_DEBUG|[19]|DEBUG|********** newAWs.size = 200

Number of future calls: 1 out of 10

...

10:18:55.859|USER_DEBUG|[19]|DEBUG|********** newAWs.size = 200

Number of future calls: 10 out of 10 ******* CLOSE TO LIMIT

 

Here is my trigger:

trigger AWTriggers on Actuals_Weekly__c (after delete, after insert, after undelete,after update,

                                         before delete, before insert, before update) {

   

    if(trigger.isAfter){

                      if(trigger.isInsert){

                                              AWAfterInsert myAfterInsert = new AWAfterInsert(Trigger.new);

                        }

                        if(trigger.isUpdate){}

                        if(trigger.isDelete){}

                        if(trigger.isUndelete){}

    }

   

    if(trigger.isBefore){

                        if(trigger.isDelete){}

                        if(trigger.isInsert){}

                        if(trigger.isUpdate){}

    }

}

Here is my class:

public with sharing class AWAfterInsert {

 

                        public AWAfterInsert(Actuals_Weekly__c[] newAWs){

                                                NotOrderedMGA14(newAWs);

                        }

                        public static void NotOrderedMGA14(Actuals_Weekly__c[] newAWs){

                                                System.debug('********** newAWs.size = ' + newAWs.size());

                                               

                                                Set<Id> accountIds = new Set<Id>();

                                                for(Actuals_Weekly__c aw : newAWs){

                                                                        accountIds.add(aw.Account__c);

                                                }

 

                                                AWGlobalUtils.asyncNotOrderedMGA14(accountIds);

                        }

}

Here is my future method:

global class AWGlobalUtils {

 @future public static void asyncNotOrderedMGA14(Set<Id> accountIds){

  System.debug('****************************** accountIds.size = ' + accountIds.size());

  list<Actuals_Weekly__c> awl = Database.query('Select Id, Procedure__c, Read_Date__c, Account__c, Account__r.Name, Account__r.OwnerId From Actuals_Weekly__c Where Procedure__c = \'MOLECULAR GRADING ASSAY\' And Read_Date__c < ' + getTargetDate() + ' And Account__c in : accountIds');

  System.debug('********** awl.size = ' + awl.size());

  Map<Id,Actuals_Weekly__c> am = new Map<Id,Actuals_Weekly__c>();

  if(!awl.isEmpty()) {

   for(Actuals_Weekly__c aw2 : awl){

    am.put(aw2.Account__c,aw2);

   }

  }

  System.debug('********** am.size = ' + am.size());

  // Send an email to each account owner

  list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();

  for(Actuals_Weekly__c aw3 : am.values()){

   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

   mail.setTargetObjectId(aw3.Account__r.OwnerId);

   mail.setSaveAsActivity(false);

   mail.setPlainTextBody('Your account: ' + aw3.Account__r.Name +' has not ordered MGA in the past 14 days.');

   mail.setHtmlBody('Your account:<b> ' + aw3.Account__r.Name +' </b>has not ordered MGA in the past 14 days.<p>'+

   ' To view the account <a href=https://cs1.salesforce.com/' + aw3.Account__r.Id + '>click here</a>');

   el.add(mail);

  }

  System.debug('********** el.size = ' + el.size());

  if(!el.isEmpty()){

   Messaging.sendEmail(el);

  }

 }

}

Here is my test method:

@isTest

private class testAWAfterInsert {

 static testMethod void AccountHasOrderedBulkTesting2(){

   System.debug('********** TEST 5 **********');

   List<Account> testAL = new List<Account>();

   for(integer i=0; i<200; i++){

    testAL.add(new Account(Name = 'Test Account ' + i, Account_Classification__c = 'Doctor'));

   }

   insert testAL;

   Date d2 = date.newinstance(2011, 1, 17);

   List<Actuals_Weekly__c> testAWL2 = new List<Actuals_Weekly__c>();

   for(Account a : testAL){

    for(integer i=0; i<10; i++){

     testAWL2.add(new Actuals_Weekly__c(Account__c = a.Id, Read_Date__c = d2, Procedure__c = 'MOLECULAR GRADING ASSAY'));

    }

   }

   test.startTest();

   insert testAWL2;

   test.stopTest();

 }

} 

  • March 30, 2011
  • Like
  • 0

Hey all,

 

Hitting a wall in trying to figure this one out.

 

At a high level:

VF Page with a command button whose action returns a pagereference to an external site. This external site checks the referer field in the http headers to determine if it allows access or not.

 

If I use Firefox 3, the referer header is sent and the external site accepts the request. The exact same process in Internet Explorer (7 and 8) fails, as the referer field is not included in the request headers.

 

VF Page (cut out the unrelated code)

<apex:commandButton value="Submit Order" action="{!submit}" rendered="{!DisplayForFinalApprover}"/>

 Controller:

public PageReference submit(){
PageReference pageRef;
pageRef = new PageReference('https://www.externalsite.com/epage.cgi');
pageRef.getParameters().put('MERCHANT_ID','123');
pageRef.getParameters().put('ORDER_ID','123');
etc
pageRef.setRedirect(true);
return pageRef;		
}
	

The above works in FF but not IE. 

 

Now if I put the use outputlink as follows:

<apex:outputLink value="https://www.externalsite.com/epage.cgi?MERCHANT_ID=123&ORDER_ID=123" id="theLink">Submit Order</apex:outputLink>

 

Then the referer field is in the request headers and the external site accepts the request. both in IE and FF.

 

So why does the PageReference work in Firefox, but not in Internet Explorer? Why is the referer field not sent?

Hi All,

Firstly, thanks for taking the time to read my post.

I have a vg page that has an actionFunction that calls an apex method from my custom controller. After running, there are a few components that are supposed to reload. However, what's happening is as follows:

1. The page starts to reload.

2. The apex method is called.

3. The components are NOT rerendered.

Does anyone have any ideas as to why that would happen?

Here is the relevant code:

1. ActionFunction tag:

  <apex:actionFunction name="undoEdit" action="{!undoEdit}" rerender="taskInfoDisplay, descInfo,fundraisingInfo, sysInfo,editButtons">
  <apex:param name="fieldToRollBack" value="{!fieldToRollBack}"/>
  </apex:actionFunction>

 

 

2. VF code that calls it:

 

<apex:commandButton image="xxx" onclick="undoEdit('Priority')" rendered="{!editState['Priority']}"/>

 

 

3. Apex Method:

 

public void undoEdit(){
		fieldToRollBack = ApexPages.currentPage().getParameters().get('fieldToRollBack');
		System.debug('the field is:' +  fieldToRollBack );
		//first check if this was edited
		if(editState.get(fieldToRollBack)){
			System.debug('the field was changed');
			if(origTaskVals.containsKey(fieldToRollBack)){
				System.debug('this is a task field, rolling back. The current val: ' + myTask.get(fieldToRollBack) + '. The orig val: ' + origTaskVals.get(fieldToRollBack));
				myTask.put(fieldToRollBack,origTaskVals.get(fieldToRollBack));
				System.debug('after putting, the val is: ' + myTask.get(fieldToRollBack))	;
			}
			
			editState.put(fieldToRollBack, false);
			
		}
	
	}

 

Thanks in advance for your help!

 

  • March 28, 2011
  • Like
  • 0

Using the latest IDE for Eclipse, 

 

Starting yesterday, about every min' or so I get the message "Save error: Conflict found while preparing to save 'xxx.cls-meta.xml' to server.  Remote instance has been updated since last save or sync."

 

I can work around this by refreshing from the server, pasting in my changed code and re-saving, but having to constantly do this is getting tiresom. Any ideas? 

  • September 16, 2009
  • Like
  • 0

I need to provide subtotals in a VF template e.g.

 

ONE OFF COSTS 

  Setup £500 

ONGOING COSTS 

  Hosting 12 x £10 

  Software Lice 12 x £10

 

Total One off costs: £500

Total Ongoing Costs: £20 per month 

 

I have managed to break down the line items on the opp by using a custom field on the product to designate its an annual license field

 

however, my totals are for the total annual amount e.g. £740 in the above example

 

<tr> <td class="section" colspan="4">INITIAL COSTS</td> </tr> <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}"> <apex:outputText rendered="{!opp.PriceBookEntry.Product2.Annual_Cost__c == false}"> <tr> <td>{!opp.PriceBookEntry.Name}<br>{!opp.PriceBookEntry.Product2.Description}<br>{!opp.Description}</td> <td>{!ROUND(opp.Quantity,1)}</td> <td align="right">£{!ROUND(opp.UnitPrice*1.00,2)}</td> <td align="right">£{!ROUND(opp.TotalPrice*1.00,2)}</td> </tr> </apex:outputText> </apex:repeat> <tr> <td class="section" colspan="4">ONGOING COSTS</td> </tr> <apex:repeat var="opp2" value="{!relatedTo.OpportunityLineItems}"> <apex:outputText rendered="{!opp2.PriceBookEntry.Product2.Annual_Cost__c == true}"> <tr> <td>{!opp2.PriceBookEntry.Name}<br />{!opp2.PriceBookEntry.Product2.Description}<br />{!opp2.Description}</td> <td>{!ROUND(opp2.Quantity,1)}</td> <td align="right">£{!ROUND(opp2.UnitPrice*1.00,2)}</td> <td align="right">£{!ROUND(opp2.TotalPrice*1.00,2)}</td> </tr> </apex:outputText> </apex:repeat> <tr> <td class="section" align="right" colspan="3">TOTAL NET</td> <td align="right">£{!ROUND(relatedTo.Amount * 1.00, 2)}</td> </tr> <tr> <td class="section" align="right" colspan="3">TOTAL TAX</td> <td align="right">£{!ROUND(((relatedTo.Amount * 1.15) - relatedTo.Amount), 2)}</td> </tr> <tr> <td class="section" align="right" colspan="3">GROSS AMOUNT</td> <td align="right">£{!ROUND(relatedTo.Amount * 1.15, 2)}</td> 

</tr> 

Hello.

 

How to send value from visualforce page to apex class ?

 

I tried to use this code, but it does not work.

 

 

global class Bibizanka { public String getBibizankaValue(String Bibiz){ return Bibiz; } }

 

 

<apex:page cache="true" showHeader="false" sidebar="false" controller="Bibizanka"> Bibizanka value = {!BibizankaValue('test')} </apex:page>

 

Thanks.

 

Hi,

 

I want to know How to add the "regExp" for Apex code. I have list of data as a .txt file. I want to split that data put a array.

 

Help me.

 

  • February 18, 2009
  • Like
  • 0

Does anyone know if there is a limit on the number of parameters that you can pass to a controller using a commandLink?  I have a commandLink with 15 param names.  When the link is clicked I get random errors because some of my values are null and they should not be. 

 

I removed the some of the param names in the visualforce page and got the values with a query in the controller but now I'm failing my test because I have over 20 queries.

 

Anyone had similar issues?  I know it's the number of parameters because I deleted them individually and I never get errors with a total of 9.

 

Thanks,

 

George Sowards

 

Hi there, I have a few questions about deploying the Apex classes and I'm hoping you'll be able to enlighten me.

 

 

I noticed that I can't test the code deployment when migrating from Development to Sandbox. The deployment tool in IDE does not check the code coverage when deploying from Dev to Sandbox. Is there a way to test deployment with code coverage test before the actual deployment to production? I know we can run the test classes independently but I would like to see how deployment with code coverage test would go before doing it in production.

 

 

In some of my test classes I had to reference an existing data created from a custom object. Dynamically adding the data via the test class will exceed the limit of 100 SOQL since the the application consists of different approvals and processes.

 

If my said test class has the hardcoded ID of an existing data on the sandbox environment, would I be able to deploy it to production or would the deployment tool look for that data in production?

 

 

Thanks in advance for the help.

 

 

  • February 17, 2009
  • Like
  • 0

Hi all

 

I would like to display a piece of custom UI in a section between two Related Lists on a Page Layout.

 

Does anyone know whether this is possible please?

 

I would like to avoid overriding the whole page if possible as Sysadmin will lose ability to configure Page Layout.

 

Thanks in advance