• Narcissu
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 12
    Replies

Hi,

 

I just wrote down the code below but have a hard time writing test coverage code. Can someone please write it or give me some ideas pointing me to the right direction. Thanks very much.

 

Trigger UpdateUpcoming on Task (after insert, after update)
{
    Set<id> AccountsIDs = new Set<id>();
    List<Account>AcctList = new List<Account>();
    For (task t:Trigger.new)
    {
    For (account at:[select id,upcoming_due__c,(select id,activitydate from tasks where isclosed = false and activitydate != null order by activitydate asc limit 1) from account where id =: t.accountid])
{
    If (date.valueof(t.activitydate) < at.upcoming_due__c || at.upcoming_due__c == null)
        at.upcoming_due__c = date.valueof(t.activitydate);
    If (trigger.isDelete)
        at.upcoming_due__c = null;
    AcctList.add(at);
}
}
    update AcctList;
}

Hi,

 

I am thinking about this language "If delete A, the value of A will become null."

 

Does anyone have any ideas?

 

Thanks in advance.

Hi,

 

I just finished the code below. It works fine as my expect but I have a hard time writing the test code. Can anyone please have a look at it and help me write the test code? Thanks in advance.

 

trigger UpdateUpcoming on Task (after insert, after update)
{
    Set<id> AccountIDs = new set<id>();
    list<Account> AcctList = new list<Account>();
    for(task c : Trigger.new)
    {
        for(Account at:[Select id,upcoming_due__c From Account where id =: c.accountid])
        {
            if (date.valueof(c.ActivityDate) == null)
                at.upcoming_due__c = null;
            else
            if (at.upcoming_due__c == null)
                at.upcoming_due__c = date.valueof(c.ActivityDate);
            if (date.valueof(c.ActivityDate) < at.upcoming_due__c)
                at.upcoming_due__c = date.valueof(c.ActivityDate);
            else
                at.upcoming_due__c = at.upcoming_due__c;
            AcctList.add(at);
        }
    }
    update AcctList;
}

Hi,

 

As we know, we can have multiple open tasks with different due dates at the same time.

 

Now I want to create a field in Account object, and this field will pick up the most recent due date of the multiple tasks. For example, there are two open tasks. One's due date is 1/1/2013, the other's is 2/1/2013. Since 1/1/2013 is the first task I create, it will automatically be populated into the field using the trigger below:

 

trigger UpcomingActivity on Task(after update, after insert)
{
Task b = new Task();
Set<id> AccountIDs = new set<id>();
list<Account> AcctList = new list<Account>();
for(Task c : Trigger.new)
{
for(Account at:[Select id,Upcoming_Due__c From Account where id =: c.accountid])
{
at.Upcoming_Due__c = date.valueof(c.ActivityDate);
AcctList.add(at);
}
}
update AcctList;
}

 

However, if I create another task, the new due date will override 1/1/2013. There are two issues.

 

1. If the new task due date is after the due date of the second task - 2/1/2013, the second one will be ignored.

2. If the new task due date is prior to the two existing ones, the code cannot pick the existing ones anymore. E.g. the new one is 5/1/2012, even 1/1/2013 and 2/1/2013 are in the future and never happen, they are out of the date pending flow.

 

Please give me some ideas how to make the field always show the most recent upcoming due date no matter how many open tasks I have. *Task and Opportunity are two different objects.

Hi,

 

I just added a new application from a third party into Salesforce last week. However, I tried to deploy a new trigger today but my code coverage dropped to 43%. So I ran all tests and found most of the codes from this third party failed the test methods.

 

Is there anyone who encountered this problem before? Is it possible that I installed the application incorrectly?

 

Thanks in advance.

Can anyone give me some ideas how and where to write a test method for the following code? Much thanks.

 

trigger Caseupdate on Case(after insert)
{
Case b = new Case();
Set<id> AccountIDs = new set<id>();
list<Account> AcctList = new list<Account>();
for(case c : Trigger.new)
{
for(Account at:[Select id,Last_Update__c From Account where id =: c.accountid])
{
at.Last_Update__c = date.valueof(c.createddate);
AcctList.add(at);
}
}
update AcctList;
}

Hi,

 

I just created a new trigger and am trying to push it to the production site. As I know I cannot do it unless I have 75% test coverage. However, I have tested it in Sandbox and it worked the way I need. I think it will work without code test.

 

So is it possible that I can deploy my trigger from Sandbox to Production site without any tests?

 

Any responds are much appreciated.

Hi,

 

I am a new user to Apex.

 

I am trying to write a trigger which will automatically enter the case open date to a custom date field on my Account object when anyone in my group opens a case for the client.

 

I understand the difficulty is to sync records between two objects. In both objects, I have a field called Account Name. My guess is to figure out a way to match this field in both objects and then write down a code to insert the case open date to the custom field.

 

I also copied and tried to modify the code from other users to fit my own situation, however I may get into a wrong direction. Following is the code I copied, I put it in the case object:

 

trigger Caseupdate on Case(after insert) {
Case b = new Case();
Set<Date> AccountIDs = new set<Date>();
map<Date, Account> AcctMap = new Map<Date, Account>();
for(Account c : Trigger.new){
AccountIDs.add(c.CreatedDate);
}
for(Account at:[Select a.CreatedDate
From Account a where a.CreatedDate = 'Date/Time Opened']){
AcctMap.put(at.CreatedDate, at);
}
for(Account c: Trigger.new){
if(AcctMap.contains(c.CreatedDate)){
c.Last_Update = AcctMap.get(c.CreatedDate);
}
}
}

 

Thanks in advance, any helps are much appreciated.