• Jamison Brown
  • NEWBIE
  • 0 Points
  • Member since 2012

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

I am trying to get a field populated with the number of activities within an account. Based on what I have seen, it would need to be separated for tasks and events. We dont really use events, so I just need to set it up for tasks. I found some existing code and edited it, but cant get it to work. What am I doing wrong? I am a novice, so please be kind.

 

/* Provide summary of Number of Tasks on Account record */

trigger TaskSumTrigger on Task (after delete, after insert, after undelete,
after update) {

Task[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of accounts
Set<ID> acctIds = new Set<ID>();
for (Task con : cons) {
acctIds.add(con.AccountId);
}

Map<ID, Task> tasksForAccounts = new Map<ID, Account>([select Id
,AccountId
from Task
where AccountId in :acctIds]);

Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
,Number_of_Activities__c
from Account
where Id in :acctIds]);

for (Account acct : acctsToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Task con : tasksForAccounts.values()) {
if (con.AccountId == acct.Id)
conIds.add(con.Id);
}
if (acct.Number_of_Activities__c != conIds.size())
acct.Number_of_Activities__c = conIds.size();
}

update acctsToUpdate.values();

}

We have a third party APP installed called MassConvertLeads. Attached to this is an Apex trigger called Batch_ConvertLead. This trigger is probably pretty self explanatory, but the code is listed below. Our version of the app expired and we may not renew it, but it is currently scheduled to run as a lead is saved as new. Since the app is expired, it will not allow a new lead to enter our database. I tried to deactivate the trigger so I could uninstall the app, but I am getting testing errors so the deactivation of the trigger will not deploy. Any thoughts?

 

rigger Batch_ConvertLead on Lead (after insert, after update)
    {
        //if(MassLeadConvert.runLeadTrigger)
        //{
                try
                  {
                    //create a string of ids to be converted
                    String records = '';
                    
                    //get all the records with status Lead Source = Web and Lead Status = Qualified
                    for(Lead lead : Trigger.New)
                        {
                            if(lead.IsConverted == false)
                                {
                                    if(records == '')
                                        records = lead.Id;
                                    else
                                        records = records + ',' + lead.Id;
                                }
                        }
                        
                    System.debug('Records in trigger :::::' + records);
                    
                    //call the single click lead convert method to convert the lead 
                    if(records != '')
                        {
                          MassConvert.MassLeadConvert.enableAutoConvert(true);
                          MassConvert.MassLeadConvert.ConvertRecords(records,true,true,'','',false,'');
                        }
                  }
              catch(Exception e)
                {
                  new Lead().addError(e.getMessage());
                }
        //}
    }

 

 

Test Results:

 

API NameTypeLineColumnProblem

Test_Trigger_ConvertLead.myUnitTest()Class231Failure Message: "System.AssertException: Assertion Failed", Failure Stack Trace: "Class.Test_Trigger_ConvertLead.myUnitTest: line 23, column 1"
TestMethodCls3.myTest1()Class571Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Unfuddle_Ticket__c, Unfuddle_Summary__c]: [Unfuddle_Ticket__c, Unfuddle_Summary__c]", Failure Stack Trace: "Class.TestMethodCls3.myTest1: line 57, column 1"
TestMethodCls3.myTest2()Class1461Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Unfuddle_Ticket__c, Unfuddle_Summary__c]: [Unfuddle_Ticket__c, Unfuddle_Summary__c]", Failure Stack Trace: "Class.TestMethodCls3.myTest2: line 146, column 1"
TestMethodCls3.myTest3()Class2061Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Unfuddle_Ticket__c, Unfuddle_Summary__c]: [Unfuddle_Ticket__c, Unfuddle_Summary__c]", Failure Stack Trace: "Class.TestMethodCls3.myTest3: line 206, column 1"
caseOwnerUpdate   Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

 

Hello there.

I found a section of apex coding that will, coupled with a round robin case assignment app, assign leads for me. I followed their instructions, but I am getting the error below. I also posted a link to the coding. What am I missing?

 


Error: Compile Error: unexpected token: trigger at line 135 column 0 

 

 

https://gist.github.com/1562280


I am trying to get a field populated with the number of activities within an account. Based on what I have seen, it would need to be separated for tasks and events. We dont really use events, so I just need to set it up for tasks. I found some existing code and edited it, but cant get it to work. What am I doing wrong? I am a novice, so please be kind.

 

/* Provide summary of Number of Tasks on Account record */

trigger TaskSumTrigger on Task (after delete, after insert, after undelete,
after update) {

Task[] cons;
if (Trigger.isDelete)
cons = Trigger.old;
else
cons = Trigger.new;

// get list of accounts
Set<ID> acctIds = new Set<ID>();
for (Task con : cons) {
acctIds.add(con.AccountId);
}

Map<ID, Task> tasksForAccounts = new Map<ID, Account>([select Id
,AccountId
from Task
where AccountId in :acctIds]);

Map<ID, Account> acctsToUpdate = new Map<ID, Account>([select Id
,Number_of_Activities__c
from Account
where Id in :acctIds]);

for (Account acct : acctsToUpdate.values()) {
Set<ID> conIds = new Set<ID>();
for (Task con : tasksForAccounts.values()) {
if (con.AccountId == acct.Id)
conIds.add(con.Id);
}
if (acct.Number_of_Activities__c != conIds.size())
acct.Number_of_Activities__c = conIds.size();
}

update acctsToUpdate.values();

}