• iperez_genius
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 25
    Replies
Can someone please correct me if i am wrong but my understanding of the term "Test coverage"

is how much of the function/tirgger is being tested by the test function.

is that right?


Ilan
I know this question has been as millions of times...

but no definitive answer has been given...

how do i activate my trigger in the production interface.

I have the class and trigger in my production interface and i have run the tests and i have 100% coverage...

i can't figure out how to activate the trigger...



can someone advise step please.
firstly let me say there needs to be a tutorial section to explain how to do all the things necessary to create a trigger and deploy it with all term explained....

secondly i have created my trigger, which is tested and works 100% in my developer license.

I am trying to bring it into my production environment.

I have downloaded eclipse installed the plugin, and saved my trigger to saleforce, production...
the trigger is inactive though. From what i have read inorder to activate the trigger i need to get my test coverage greater than 75%.

apparently to do this i need to create a test class.

Briefly my trigger, on insertion of a task with subject mail_merged a custom field in a lead is set from no to yes.

Below is my attempt at a test class

Code:
public class updateLead {
 static testMethod void testUpdateLead() {
  Task t1 = new Task (subject='Mail merge document(s) generated: mail_Merged');
  Task t2 = new Task (subject='Email');
  Task[] myTasks = new Task[]{t1,t2};
  insert myTasks;
  Task queryTask1 = [select Id,subject from Task where Id = :t1.Id];
  system.assertEquals('Mail merge document(s) generated: mail_Merged',queryTask1.subject);
  Task queryTask2 = [select Id,subject from Task where Id = :t2.Id];
  system.assertEquals('Email',queryTask2.subject);

 }
}

 here is my trigger

Code:
trigger updateLead on Task (after insert) {
Lead[] leadsToUpdate;for (Task t: Trigger.new)
{
String accountid = t.whoId;
leadsToUpdate = [select id, SentPack__c, email from lead where id =: accountid];

String Otype = accountid.substring(0, 3);

 if (Otype=='00Q' && t.Subject=='Mail merge document(s) generated: mail_Merged')
 {
 
  for (Lead ltu : leadsToUpdate)
  {
   if (ltu.SentPack__c == 'no')
{

ltu.SentPack__c = 'yes' ;
update ltu;
}  


  }


 }
}

}

 what must i do next to get test coverage great than 75%

Please help...

thanks in advance

Ilan   


Code:
trigger updateLead on Task (after insert)
{
List<Lead> leadsToUpdate = new List<Lead>();
for (Task t: Trigger.new)
{
System.debug('1');
System.debug(t.Subject+'2');// value is mailMerge
System.debug(t.What.Type+'3'); // value is null

if (t.What.Type=='Lead' && t.Subject=='mailMerge')
{
System.debug('4');
Lead l = new Lead(Id = t.WhatId);
if (l.SentInfoPack__c == 'no')
{
System.debug('5');
l.SentInfoPack__c = 'yes';
leadsToUpdate.add(l);
}
}
}
update leadsToUpdate;
}


So this trigger compiles and executes howerver there is a problem with obtaining values.

the red are the values i need and the subject value comes out fine, however the green value is null.

can someone please advise.

I have no idea how to fix my problem. I also need code not just advice. I am on a steep learning curve here, this is my first look at apex code :)

Any help and advice is greatly appreciated.

Ilan
 

trying to find the apex code to discover what object a task belongs to

so i create a task for a lead i want to know that the task i access in my code is only a task attributed to elads and not contacts or oppotunities...

can anyone help

ilan
Code:
trigger updateLead on Task (after insert)
{
Lead[] leadsToUpdate;
Task[] taskEdit;



for (Task t: Trigger.new)
{
leadsToUpdate = [select id, SentInfoPack__c, email from lead];
taskEdit =[select whoid, subject from task];

for (Lead ltu : leadsToUpdate)
{
Lead[] leadInserts;
for (Task tsk : taskEdit)
 if ((tsk.whoid == ltu.id) && (tsk.subject == 'mailMerge266'))
{
if (ltu.SentInfoPack__c == 'no')
{
ltu.SentInfoPack__c = 'yes' ;
update ltu;
}

}

}

}

}

I wrote this code i was wondering if anyone can advise how to make it more efficient as i am not sure how well it will fair up against thousands of records.

Ilan
 
I know its completely slack on my behalf not to have searched through all the posts to find my solution but i am in a bind with time, and i think this will be quicker. Hopefully someone is kind enough to help me.

The situatioin:
A lead comes in, we complete a mail merge and against their name a completed task is created stating a mail merge has been inacted.
I need to create a trigger that updates a custom field (sentPack) in a Lead  from default value "no" to "yes"

i am not sure how to do this.

can anyone help me. Please this is urgent

thanks in advance

regards
Ilan Perez
firstly let me say there needs to be a tutorial section to explain how to do all the things necessary to create a trigger and deploy it with all term explained....

secondly i have created my trigger, which is tested and works 100% in my developer license.

I am trying to bring it into my production environment.

I have downloaded eclipse installed the plugin, and saved my trigger to saleforce, production...
the trigger is inactive though. From what i have read inorder to activate the trigger i need to get my test coverage greater than 75%.

apparently to do this i need to create a test class.

Briefly my trigger, on insertion of a task with subject mail_merged a custom field in a lead is set from no to yes.

Below is my attempt at a test class

Code:
public class updateLead {
 static testMethod void testUpdateLead() {
  Task t1 = new Task (subject='Mail merge document(s) generated: mail_Merged');
  Task t2 = new Task (subject='Email');
  Task[] myTasks = new Task[]{t1,t2};
  insert myTasks;
  Task queryTask1 = [select Id,subject from Task where Id = :t1.Id];
  system.assertEquals('Mail merge document(s) generated: mail_Merged',queryTask1.subject);
  Task queryTask2 = [select Id,subject from Task where Id = :t2.Id];
  system.assertEquals('Email',queryTask2.subject);

 }
}

 here is my trigger

Code:
trigger updateLead on Task (after insert) {
Lead[] leadsToUpdate;for (Task t: Trigger.new)
{
String accountid = t.whoId;
leadsToUpdate = [select id, SentPack__c, email from lead where id =: accountid];

String Otype = accountid.substring(0, 3);

 if (Otype=='00Q' && t.Subject=='Mail merge document(s) generated: mail_Merged')
 {
 
  for (Lead ltu : leadsToUpdate)
  {
   if (ltu.SentPack__c == 'no')
{

ltu.SentPack__c = 'yes' ;
update ltu;
}  


  }


 }
}

}

 what must i do next to get test coverage great than 75%

Please help...

thanks in advance

Ilan   


hi All,

I don't really understand the Test coverages. Could you please help me with this?

When I modify a trigger that already exists in production I change it and modify it in sandbox but after I see that it is working correctly I modify it directly in production through the Force.com project. I could do more test coverage in production to see if it is also working correctly in production but the trigger is already deplyed in production because I changed it manually using Eclipse.

I would like to know if it is damangerous and if there is another way to do it more secure.

Thanks.
trying to find the apex code to discover what object a task belongs to

so i create a task for a lead i want to know that the task i access in my code is only a task attributed to elads and not contacts or oppotunities...

can anyone help

ilan
I know its completely slack on my behalf not to have searched through all the posts to find my solution but i am in a bind with time, and i think this will be quicker. Hopefully someone is kind enough to help me.

The situatioin:
A lead comes in, we complete a mail merge and against their name a completed task is created stating a mail merge has been inacted.
I need to create a trigger that updates a custom field (sentPack) in a Lead  from default value "no" to "yes"

i am not sure how to do this.

can anyone help me. Please this is urgent

thanks in advance

regards
Ilan Perez
I am attempting to create a Before insert trigger which concatenates the Account name on the end of the Subject.  Here's my code:
/* Adds additional text to the entered Subject */
trigger triggerAddSubject on Event (before insert)
{
     Account subjectacct  = [select Id, Name from Account where Id = :Trigger.new.whoid];
     Trigger.new.subject = Trigger.new.subject + ' ' + subjectacct.name;
} // end of trigger
 
If I hard code an account guid into the query it works fine, apparently the whoid isn't set until the record is committed, so the subjectacct is null.
 
Have I just written it incorrectly or do I need to rewrite this as a after insert trigger?
 
Is there an easier way to do it?

Thanks,
 
Pat
 
 
I'm looking to find the object types of the WhatId/WhoId fields of the Task and Event objects, so I can query these objects and get more information about them and perform certain automated tasks based on the type.

I found this tech article, which uses the first 3 digits as a marker, but the article also says that this may change at any time:

http://www.sforce.com/us/resources/tn-1.jsp

Is there a better way of getting the object types of WhatId/WhoId fields or querying them based on Id only (no type)?

Thanks!