• Vashnar
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hello... Extremely new to Apex code here. Found this online and modified it to work for what I need, but I am missing a date component. I'd like the Class to only count activities that have occurred within the last 90 days, and if there are none reset the count to zero.

Here's what I have so far:

public with sharing class AccountActivityCount {
    public static Boolean didRun = false;
    public static String acctPrefix =  Account.sObjectType.getDescribe().getKeyPrefix();
    public static void updateAccountCounts(Set<ID> acctIds) {
        if (didRun == false) {
            didRun = true;
            List<Account> accts = [SELECT ID, activity_count__c, (SELECT ID FROM Tasks), (SELECT ID FROM Events) FROM Account WHERE ID IN :acctIds];
            List<Account> updateAccts = new List<Account>();
            for (Account o : accts) {
                Integer count = o.tasks.size() + o.events.size();
                if (o.activity_count__c != count) {
                    o.activity_count__c = count;
                    updateAccts.add(o);
                }
            }
            try {
                update updateAccts;
            } catch (Exception e) {
            }
        }
    }
    /*
    * Test method for this class and TaskUpdateOpportunity and EventUpdateOpportunity
    */
    public static testMethod void testCountTask() {
        Account a = new Account(name='Test');
        insert a;
        Task t = new Task(subject='Test Activity', whatId = a.id);
        insert t;
        a = [SELECT ID, activity_count__c FROM Account WHERE ID = :a.id];
        System.assertEquals(1,a.activity_count__c);
        didRun = false; //Reset
        t.whatId = null;
        update t;
        a = [SELECT ID, activity_count__c FROM Account WHERE ID = :a.id];
        System.assertEquals(0,a.activity_count__c);
        didRun = false; //Reset
        Event e = new Event(subject='Test Event', whatId = a.id, startDateTime = System.Now(), endDateTime = System.now());
        insert e;
        a = [SELECT ID, activity_count__c FROM Account WHERE ID = :a.id];
        System.assertEquals(1,a.activity_count__c);
        didRun = false; //Reset
        t.whatId = a.id;
        update t;
        a = [SELECT ID, activity_count__c FROM Account WHERE ID = :a.id];
        System.assertEquals(2,a.activity_count__c);
        didRun = false; //Reset
        e.whatId = null;
        update e;
        a = [SELECT ID, activity_count__c FROM Account WHERE ID = :a.id];
        System.assertEquals(1,a.activity_count__c);
        didRun = false; //reset
        delete t;
        a = [SELECT ID, activity_count__c FROM Account WHERE ID = :a.id];
        System.assertEquals(0,a.activity_count__c);       
    }
}

Thanks in advance, any help is greatly appreciated!
Brian
  • September 30, 2014
  • Like
  • 0

I've set up Tasks in Chatter, but users who have 'Automaticaly follow records that I create' checked are still having to manually follow tasks that they create?

 

I've done a lot of searching and cannot find a solution.

 

Thanks!

Brian

I'm trying to figure out how I can automatically create multiple tasks related to a case when the case is assigned to a support rep from a queue. The case is related to an opportunity and I need a task created for each product related to the opportunity. I'm very green with Apex, so I'm not sure where to start other than I'm pretty sure it needs to be a workflow.

 

I'm on Enterprise Edition.

 

Any help to get me started is appreciated!

Brian

  • September 18, 2013
  • Like
  • 0

Trying to lock editing on Opptys if they have one of two picklist values selected. Also need to except Admins from the rule.

 

My current attempt:

 

AND( 
ISPICKVAL(Status__c,"Active"), 
ISPICKVAL(Status__c,"Expired"), 
NOT($Profile.Id = "00e80000000zMnI") 
)

 

Thanks in advance!

Brian

I'm trying create a validation rule that will not allow a picklist value to be chosen if the checkbox is checked.

 

This is as far as I've gotten...

 

AND(
PRIORVALUE(D2D_Account__c, "true")
ISPICKVAL(Type, "Archived")

 

Tried searching the board and couldn't find a solution.

 

Thanks in advance!

Brian

Trying to lock editing on Opptys if they have one of two picklist values selected. Also need to except Admins from the rule.

 

My current attempt:

 

AND( 
ISPICKVAL(Status__c,"Active"), 
ISPICKVAL(Status__c,"Expired"), 
NOT($Profile.Id = "00e80000000zMnI") 
)

 

Thanks in advance!

Brian

I'm trying create a validation rule that will not allow a picklist value to be chosen if the checkbox is checked.

 

This is as far as I've gotten...

 

AND(
PRIORVALUE(D2D_Account__c, "true")
ISPICKVAL(Type, "Archived")

 

Tried searching the board and couldn't find a solution.

 

Thanks in advance!

Brian

Happy holidays, all.

 

We have recently started using cases for our organization.

 

We have added a custom lookup field to opportunities from cases.

 

We are now using the related list for cases on our accounts, contacts, and opportunity layouts (detail). On accounts and contacts, we are using the standard new case button, but for opportunities this is a custom lookup and we cannot do this.

I've been attempting to create a custom button to make a new case from the cases related list on the opportunity detail screen, but it is not working. (TBH I don't know what I'm doing, I'm just trying to follow an example, so sorry if this is a silly question.)

I made a custom button on cases called new case.

Here is the formula:
URLFOR($Action.Case.New,null,[saveURL=Opportunity.Link, retURL=Opportunity.Link,CF00NG0000008hHho_lkid=Opportunity.Id,CF00NG0000008hHho=Opportunity.Name],true)

Where 00NG0000008hHho is the ID for the custom lookup field for opportunities from cases.

If I add the custom button to the related list, it just gives me a broken link message. The resulting URL that doesn't work is:

https://na11.salesforce.com/servlet/URLFOR($Action.Case.New,null,[saveURL=Opportunity.Link,retURL=Opportunity.Link,CF00NG0000008hHho_lkid=Opportunity.Id,CF00NG0000008hHho=Opportunity.Name],true)

Can you see what I am doing wrong?

Many thanks.