• MaddySingh
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies
Here is the code I am facing performance issue with. My code is working for 500 records with 100 in each batch. I am trying to process the same csv file with 1000+ records with a batch size of 500 and getting "Time limit exceeded" error on visualforce page. We have a requirment to scale this up to 100,000 thousand records or at least to 50,000 records. I have provided only standard fields in the below code. We have totally 32 columns in the csv file that we are uploading through visualforce page UI. A quick help is much appreciated!!!

public void importCSVFile(){
            csvAsString = csvFileBody.toString();
            csvFileLines = csvAsString.split('\n');
            Integer recordCount = csvFileLines.size();
            Integer batchSize = 500;
            Double batchCount = Math.ceil(recordCount/batchSize);
            System.debug('Batch Counts : '+ batchCount);
       try{
            for( Integer i=1; i<=batchCount; i++){
                recordbatch = recordbatch = new List<String>();
                acclist.clear();
                for(Integer j=(i-1)*batchSize+1; j<=(i*batchSize); j++){
                 System.debug('Record Count : '+ j);
                    if(csvFileLines[j] != null){
               
                    Account account = new Account();
                    string[] csvRecordData = csvFileLines[j].split(',');
                    account.Salutation = csvRecordData[7];
                    account.FirstName = csvRecordData[8];
                    account.LastName = csvRecordData[9];
                    account.PersonMailingCountry = csvRecordData[12];
                    account.PersonMailingStreet = csvRecordData[13];
                    account.PersonMailingCity = csvRecordData[14];
                    account.PersonMailingState = csvRecordData[15];
                    account.PersonMailingPostalCode = csvRecordData[16];
                       
                   acclist.add(account);  
              
               }else{
                        break;
                    }
                    System.debug('Batch size executed : '+ j);
               }
                insert acclist;
               
            }
            }catch (Exception e)
            {
                ApexPages.Message errorMessage = new ApexPages.Message(ApexPages.severity.ERROR,'Please make sure input csv file is correct'+e);
                ApexPages.addMessage(errorMessage);
                System.debug('Exception: '+ e);
            }
                   
  }
I have a trigger with a test method that has lines of code not covered. I was wondering if anyone could help fill in the blanks. Lines, 16,18,20,21,23,24 are not covered. I am also using the test for another trigger, but wanted to add coverage into the test for my new trigger too.


New Trigger

trigger Trigger_PreferredSP on Case (before update) {

List<String> accountList = new List<String>();
    for (Case c : Trigger.new)
        accountList.add(c.AccountId);
  
    // Query Accounts
    Map<Id, Account> accountMap = new Map<id, Account>([SELECT OwnerId,Preferred_SP__c,Shipping_Country__c FROM Account WHERE id =: accountList]);
  
    // Set Service Provider
    for (Case c : Trigger.new){
        Account a = accountMap.get(c.AccountId);
       
        if(a != null){ //Checks to see if the case has an account.
       
        if(a.Shipping_Country__c != 'USA')
       
        if(a.Shipping_Country__c != 'CAN')
       
            if ( c.Service_Provider__c == null)
                c.Service_Provider__c = a.Preferred_SP__c ;
              
           else if(c.AccountId == null & a.Preferred_SP__c == null )
             c.Service_Provider__c = null ;
        }


TEST METHOD

@isTest
private class Test_AssignWebCaseQueue {

    static testMethod void myUnitTest() {
        // TO DO: implement unit test
       
        test.startTest();
       
        Account acc = new Account( Name ='Key West Services', Market_Segment__c='Finance Company',Shipping_Country__c= 'USA', Customer_Type__c='Finance Company', Preferred_SP__c ='0017000000WitqP', Registered_for_Seminar__c=true );
      insert acc;
     
      acc.Name='Key West Services';
      acc.Market_Segment__c ='Finance Company';
      acc.Customer_Type__c='Finance Company';
      acc.Preferred_SP__c ='0017000000WitqP';
      acc.Shipping_Country__c= 'USA';
      acc.Shipping_Country__c= 'CAN';
     
      update acc;
     
     

      Case cse = new Case( Status='Open', Origin='Parts Support - Web', Subject='Parts', Web_Case_Type__c='Part Support',Service_Provider__c='0017000000WitqP');
      insert cse;

      cse.Status = 'Open';
      cse.Origin = 'Parts Support - Web';
      cse.OwnerId='00G70000001JGIA';
      cse.Web_Case_Type__c='Part Support';
      cse.Service_Provider__c = '0017000000WitqP';
      update cse;
     
      cse.Status = 'Open';
      cse.Origin = 'Tech Support- Web';
      cse.OwnerId='00G70000001hJGH';
      cse.Web_Case_Type__c='Tech Support';
      update cse;

     

    test.stopTest();
    }
}
  • June 25, 2014
  • Like
  • 0
We have an internal system we use to manage the services we provide to our clients.

What would be the easiest way for me to have an iframe on the Account page that would show that client's record within our internal system?

thanks!

Hey Guys,

I am try to put together my first vf page and I have a question.

The page I am creating is a page where the user can select some contacts from the contact page then pust a button called 'Create Event' that will take then to a page where that can fill out the event info and the selected contacts will be assigned then saved.

So right now I have a button then when clicked will take them to the new page with the selected Id's in the URL.

ex:  &type=whoid&Ids=003e000000IidjU%2C003e000000Iidji%2C003e000000HkFlA

I would like to display a list of the selected contacts in the new page but I am not sure how to get a list a contact objects form the Id's in the URL.

Here is my event page: (note: this is just a start)

<apex:page standardController="Event" extensions="CreateEvent_Controller" >
  <h1>Create Event With Selected Contacts</h1>
  <apex:sectionHeader title="Event" subtitle="New Event" help="/help/doc/user_ed.jsp?loc=help&target=creating_tasks.htm&section=Activities"/>
 <apex:form >
     <apex:pageMessages ></apex:pageMessages>
     <apex:pageBlock title="Event Edit"  mode="edit">
         <apex:pageBlockSection columns="1" title="Event Information"  >
        
                <apex:inputField value="{!Event.Subject}" />
                <apex:inputField value="{!Event.Location}" />
                <apex:inputField value="{!Event.StartDateTime}" />
                <apex:inputField value="{!Event.EndDateTime}" />
               
         </apex:pageBlockSection>
        
         <apex:pageBlockSection columns="1" title="Description Information" >
                 <apex:inputTextarea value="{!Event.Description}" cols="75" rows="5" richText="false"/>
         </apex:pageBlockSection>
        
         <apex:pageBlockSection columns="1" title="Description Information" >
            <apex:dataList value="{!contacts}" var="contact">
                <apex:outputText value="{!contact.Name}"/>
            </apex:dataList>
         </apex:pageBlockSection>  
           
         <apex:pageBlockButtons >
             <apex:commandButton value="Save" action="{!save}" immediate="true" />
             <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
         </apex:pageBlockButtons>
     </apex:pageBlock>
    
 </apex:form>
</apex:page>

And here in my controller:

public with sharing class CreateEvent_Controller
{

   
    public ApexPages.StandardController myUserController {get; set;}
    public List<Contact> contacts {get; set;}


    public ApexPages.StandardController standardContactController;
   
    public CreateEvent_Controller(ApexPages.StandardController cntrl)
    {
   
        standardContactController = cntrl;
       
        /*contacts = (Contact)cntrl.getRecord();*/
   
    }
   
}

Any help on how to get the contact object list would be great, and any overall suggestions after that would be helpfull






I don't have much credit finding this weird thing but I wanted to know if it's a bug or if it's really intended, which I cannot imagine. 

copy paste from this blog: http://blog.tquila.com/2012/06/25/grokking-force-dot-com-apex/

 

"Unit Tests increment your Objects unique Id

This is not covered in the documentation, or atleast I haven’t found it in the Apex docs. When you run unit tests that insert/create records for a particular object(standard or otherwise), it increments the value of the Name field(of type Auto Number) outside of the test context.

Let’s say you have a custom object “Invoice Statement” (Invoice_Statement__c) that has a Name field called “Invoice Number”, and is of type “Auto Number”. The format of the field is: INV-{0000}, and let’s assume that the latest record number is INV-2058.

If you insert 10 records in the test class as follows:

 

1// Let's assume that this runs inside of a test method
2List<Invoice_Statement__c> invStatementList = new List<Invoice_Statement__c>();
3for(Integer i = 0; i < 10; i++) {
4  invStatementList.add(new Invoice_Statement__c(company='acme ltd');
5}
6insert invStatementList;

 

Now, when you insert a new Invoice Statement record outside of the test method via a trigger, or batch, or the User Interface, the next inserted record will have the id INV-2069. So don’t rely on the unique name field if you have strict rules around the auto-increment feature in your application. Instead add a custom field which is auto-incremented in a workflow or trigger to have more granular control over how the value is incremented."

 

I verified that by myself, and this indeed happen. I remember having used these numbers for customer who want to have exactly one unique number per record (especially for bills), so this could be a huge issue.

 

Anyone aware of that? I didn't find it in the Salesforce known bug ....