• tgk1
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 50
    Replies

Hi everyone.  I have a trigger that currently works fine through the user interface.  However I need to bulk update 85,000 task records and the trigger is causing failures.

 

Intended trigger purpose:  Update the Last_SW_Activity__c field (date time field) on the account object with the last modified date of the record when a task record meets the following criteria:

  1. The Subject Line starts with "sw".
  2. The task is marked as completed.
trigger LastSWDate on Task (after insert, after update) {
 
  //To do - If the subject of a completed task contains "SW", put the date of the completed task in the 
  //the "Last_SW_Activity__c" field on the account object

//Create a set of related account ID's
Set <ID> acctIDs = new Set <ID> ();
//Create a list to hold the Updated Accounts
List<Account> updAccts = new List<Account>();

//For every task, add it's related to account ID to the set
  for (Task t: Trigger.new){
    acctIDs.add(t.accountID);
//Create a map to match the task related to ID's with their corresponding account ID's
    Map<ID, Account> acctMap = new Map<ID, Account> ([Select ID, Last_SW_Activity__c from Account where ID in :acctIDs]);
//Create the account object
      Account acctRec = acctMap.get(t.accountID);

//If the account ID isn't null, the subject line starts with "sw", and the task has been marked as completed    
  If ((t.accountID != null) &&(t.subject.indexOf('sw')==0) && (t.Status == 'Completed'))
//Check to see if the Last_SW_Activity__c field is current compared with the latest completed activity
      If (acctMap.get(t.accountID).Last_SW_Activity__c < t.LastModifiedDate || acctMap.get(t.accountID).Last_SW_Activity__c ==null){
//Update the Last_SW_Activity__c field on the account object with the task's end date  
        acctrec.Last_SW_Activity__c = t.LastModifiedDate;
        updAccts.add(acctrec);
    }
  }
  update updAccts;
}

 Can somebody please help make the trigger code more efficient (bulkifying it) and help with creating a test class?  I'm not a developer and could use some serious help here.  Thanks!!

 

 

Hello - I'm trying to learn Apex but I'm having some difficulty understanding the concepts of Apex collections.  Can someone please explain to me a few examples of when using a list, set, or map would be appropriate?  For example what particular scenario would be good to use a list vs. the other collection classes?  Thanks for the help!

Hi everyone - I'm writing up a VisualForce page and I could use some help.  The page I'm trying to setup has three main values:  Product Line, Type, and Order Type.  These three fields are required, and the values of the Product Line field will be used to determine what pageblocksection to display.

 

<apex:page standardController="Opportunity" tabStyle="opportunity" sidebar="false" showHeader="false">
  <apex:form >
    <apex:pageblock title="{!Opportunity.Account.Name} Product List">
      <apex:pageblockButtons location="bottom">
        <apex:commandButton value="Save" action="{!save}"/>
      </apex:pageblockButtons>
      <apex:pageblocksection columns="1">
        <apex:inputfield value="{!Opportunity.Product_Line__c}" required="true"/>
        <apex:inputfield value="{!Opportunity.Type}" required="true"/>
        <apex:inputField value="{!Opportunity.OrderType__c}" required="true"/>
        
        <!-- Page Block Sections-->
        <apex:pageblocksection title="Value 1 Required Fields" columns="1" collapsible="true" id="value1">
        </apex:pageblocksection>
       
        <apex:pageblocksection title="Value 2 Required Fields" columns="2" collapsible="true" id="value2">
        </apex:pageblocksection>
        
        <apex:pageblocksection title="Value 3 Required Fields" columns="2" collapsible="true" id="value3">
        </apex:pageblocksection>
        
        <apex:pageblockSection title="Value 4 Required Fields" columns="2" collapsible="true" id="value4">
        </apex:pageblockSection>
       
      </apex:pageblocksection>
      <!--End Page Block Sections-->
    </apex:pageblock>
  </apex:form>
</apex:page>

 

I'm new to javascript and visualforce, so I could really use some help here.  I don't want any of the pageblocksections to display until the Product Line field is filled out.  For example, if a person selects "Value 1" in the Product Line field, I want the Value 1 page block section to display.  There are four values total.  Any help would be greatly appreciated! 

ple help the above validation rule in SFDc

Hi everyone-

 

My organization has 8 values within the Stage field.  Analytic snapshots have proven unsuccessful for our particular organization in the past, so I'm looking to get creative.

 

The requirement here is to figure out how many days were spent in a particular stage (without getting overwritten).  I'm thinking about doing something where I create 8 fields (Stage 0 Age, Stage 1 Age, etc.) that can capture an integer value of how many days were spent in that particular stage.  This would allow us to really get down to the fine grain levels of reporting that our executive team is starting to require.  I believe something like this would have to be done with a workflow field update, as well as a formula field, but I'm not quite sure how I would do it.  Does anybody have any ideas?

wat exactly an admin does in a company. I knw the tasks: "customization, security nd access, workflow rules, data validation etc..."   Below r my questions:

                                                                                                                                                                                                            Scenario: A small size company(say a construction company) with 50 users.

#1) how many admins required/ wat wil be the approx. team size ?     # 2) does 1 specific admin need to takecare of  ALL the tasks or will be focused on subset of tasks?       #3) Admin need to give/work 24/7 support?     #4) In general, an Admin reports to a Team leader/Sales director?       #5) Does Admin need to seek permission from anyone if he wants to install an application from Appexchange?

 

Kindly clarify my doubts nd educate me ..Thanks in advance

Hi everyone-

 

I'm trying to bulk upload 23 new user records by using the Apex Dataloader.  I'm not making these users active yet, but I need to create the records so I can eventually activate them one at a time.  All of my fields values in the .CSV file are perfect, but I keep running into issues with the following fields:

 

Time Zone

Locale

Email Encoding

 

When I go to insert the new records, I get an error that states the field name & "bad value for restricted picklist field".

 

Does anybody know the values that I should be using for the New York time zone, with an English (United States) locale, and standard email encoding?  Thanks!!

Hey guys, I'm having an issue with an apex trigger that I rolled out recently.  The trigger is supposed to store a lead record's 18 digit id inside of a field I created called "lead_id__c" after save/insert.  The trigger works fine but is throwing an exception if a lead owner is changed (i.e. it will throw the exception if I change the lead from sales rep a to sales rep b).  Here's the error:

 

 

Apex script unhandled trigger exception by user/organization: 005000000073fWI/00D00000000hg2v

LeadAfterInsert: execution of AfterUpdate

caused by: System.DmlException: Update failed. First exception on row 0 with id 00Q00000009XfaeEAC; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: []

Trigger.LeadAfterInsert: line 29, column 9

 

Anybody have any idea how I can fix this?  Here's the existing trigger and test class I have, I would really appreciate the help!

 

Trigger -

trigger LeadAfterInsert on Lead (after insert, after update) 
{
    List<Lead> lstLeadstoupdate = new List<Lead>();
    if(trigger.isInsert)
    {
        for(Integer i = 0; i < Trigger.new.size(); i++)
        {
            String str = string.valueof(Trigger.new[i].Id);
            lstLeadstoupdate.add(new Lead(Id = Trigger.new[i].Id, Lead_Id__c = str.substring(0, 18)));
        }
    }
    else
    {
        for(Integer i = 0; i < Trigger.new.size(); i++)
            if(Trigger.old[i].Lead_Id__c != null && Trigger.new[i].Lead_Id__c !=  Trigger.old[i].Lead_Id__c)
            {
                String str = string.valueof(Trigger.new[i].Id);
                lstLeadstoupdate.add(new Lead(Id = Trigger.new[i].Id, Lead_Id__c = str.substring(0, 18)));
            }
            else if(Trigger.old[i].Lead_Id__c == null)
            {
                String str = string.valueof(Trigger.new[i].Id);
                lstLeadstoupdate.add(new Lead(Id = Trigger.new[i].Id, Lead_Id__c = str.substring(0, 18)));
            }
    
    }
    
    if(!lstLeadstoupdate.isEmpty())
        update lstLeadstoupdate;
}


 

Test class -

@isTest
private class Test_LeadAfterInsert_Trigger {

    static testMethod void myUnitTest() 
    {
        // TO DO: implement unit test
        Test.startTest();
            Lead objLead = new Lead();
            objLead.LastName = 'Test Lead 1';
            objLead.Company = 'Test Compant 1';
            Insert objLead;
            objLead.Lead_Id__c = '';
            update objLead;
        Test.stopTest();
    }
}



 



Hi,

 

I have a workflow that is triggered by the creation of an object named p_status__c. this object is connected by a lookup to another object p__c.

I want to create an email alert that will be triggered 30 days after the creation of p_status__c only if another checkbox (fieldname is paid) of the p__c object is FALSE.

The point is that only 30 days after the creation of p_status__c the function shoul evaluate the "paid" field.

 

The regular workflow evaluate both conditions on the creation trigger.

A solution anyone?

 

Thank's

Hi all - I'm having trouble writing a test class for the following apex code:

 

trigger LastSWDate on Task (after insert, after update) {
  
  
  //To do - If the subject of a completed task contains "SW", put the date of the completed task in the 
  //the "Last_SW_Activity__c" field on the account object

//Create a set of related account ID's
Set <ID> acctIDs = new Set <ID> ();


//For every task, add it's related to account ID to the set
  for (Task t: Trigger.new){
    acctIDs.add(t.accountID);
//Create a map to match the task related to ID's with their corresponding account ID's
    Map<ID, Account> acctMap = new Map<ID, Account> ([Select ID, Last_SW_Activity__c from Account where ID in :acctIDs]);
//Create the account object
      Account acctRec = acctMap.get(t.accountID);

//If the account ID isn't null, the subject line starts with "sw", and the task has been marked as completed    
  If ((t.accountID != null) &&(t.subject.indexOf('sw')==0) && (t.Status == 'Completed'))
//Check to see if the Last_SW_Activity__c field is current compared with the latest completed activity
      If (acctMap.get(t.accountID).Last_SW_Activity__c < t.LastModifiedDate || acctMap.get(t.accountID).Last_SW_Activity__c ==null){
//Update the Last_SW_Activity__c field on the account object with the task's end date  
        acctrec.Last_SW_Activity__c = t.LastModifiedDate;
        update acctRec;
    }
  }
}

 Can somebody please help take a stab at a test class for this?  I would really appreciate it!  Thanks!

Hi everyone-

 

I could really use some help with a simple trigger.  When a lead record is saved I need an apex trigger to populate a field called "Lead_Id__c" with the lead record's 18 digit ID.  Can someone please help?  Thanks very much in advance!

 

-Tom