• jfitz1959
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Apex Documentation shows this when selecting for 'person account' objects:

SELECT Name, SobjectType, IsPersonType FROM RecordType WHERE SobjectType='Account' AND IsPersonType=True

 

A) I don't know where to go from there (adding 'and email=joe@blow.com' throws an error)

B) if I used this method it would seem to be a two step process...there must be a more efficient 'select' statement to accomplish this in one step?

doing a unit test case on a case trigger and getting results that indicate the new case gets created, but not the new contacts. None of the created contact info gets propagated through but the case info does....not sure whats going on any help?

 

Here is my unit test case

@istest public class TriggerTest

 {

     public static testMethod void myTest()

     {

         List<string> ids = new List<string>(); //more for debugging

         for(integer i=0; i<20; i++)

         {

             //create some contacts first-tried creating contacts with in case creation loop below but that didn't work either...

             string em='joe'+string.valueof(i)+'@gmail.com';

             string last = 'joe'+string.valueof(i);

             System.Debug('triggerTest:email:'+em);

             Contact cont = new contact(email=em,lastname=last);

             insert cont;

             ids.add(cont.id);

         }

         System.Debug('triggerTest:contacts:'+string.Valueo​f(ids.size()));//debugging

         List<case> cases=new List<case>();

         for(integer i=0; i<20; i++)

         {

             cases.add( new case(contactID=ids[i],status='new',origin='web') );

         }

         insert cases;

    }

 }

 

and here is my trigger:

 

trigger trig on Case (after insert)

 {

 List<TriggerTest__c> tt = new List<TriggerTest__c>();

 for(case c:trigger.new)

 {

     System.Debug('trig:origin:'+c.origin);

     System.Debug('trig:status:'+c.status);

     System.Debug('trig:contactId:'+c.contactid);

     System.Debug('trig:name:'+c.contact.lastname);

     System.Debug('trig:email:'+c.contact.email);

     System.Debug('trig:email:'+String.valueof(c.contac​t.email));

     tt.Add( new TriggerTest__c(EntryTime__c = datetime.now(), Email__c= 'j@email.com'));

 }

 if(!tt.isempty())

 {

    insert tt;

 }

}

 

partial trace...no email ????

15:09:43.610 (610320000)|USER_DEBUG|[5]|DEBUG|trig:origin:Web

15:09:43.610 (610364000)|USER_DEBUG|[6]|DEBUG|trig:status:New

15:09:43.610 (610405000)|USER_DEBUG|[7]|DEBUG|trig:contactId:00​3U0000009g3VTIAY

15:09:43.610 (610430000)|USER_DEBUG|[8]|DEBUG|trig:name:null

15:09:43.610 (610450000)|USER_DEBUG|[9]|DEBUG|trig:email:null

15:09:43.610 (610476000)|USER_DEBUG|[10]|DEBUG|trig:email:null

We're creating a unit test for a cases trigger and as part of the process we need to create new cases.

We're using something like this to start but we're stuck...

   ....

   List<case> cases=new List<case>();

   for(integer I=0; I<20; I++)

   {

             string em='joe@gmail.com/'+String.valueof(i);

             cases.add( new case(contact.email=em) ); //<= this throws an Error: Compile Error: Invalid field initializer: contact.email at line 10 column 33

   }

   insert cases;    

   ...

I'm not sure how to fill in the email portion or even if I'll need more info.

I'm getting an Error: Compile Error: Invalid field contactemail for SObject Case at line 4 column 10

which is strange to me since Contact Email {contactemail} is a listed field in 'cases'. In fact almost none of the case fields are considered valid...

I tried writing a sample trigger for 'accounts' and had no problems since all the fields were available. Oddly enough the only field that seems 'readable' is Web Email {suppliedemail}

 

trigger trigCase on Case (after insert)

{

    for(case c:trigger.new)

    {

       string e=c.contactemail;

    }

}

 

Any help/clues would be appreciated.

Apex Documentation shows this when selecting for 'person account' objects:

SELECT Name, SobjectType, IsPersonType FROM RecordType WHERE SobjectType='Account' AND IsPersonType=True

 

A) I don't know where to go from there (adding 'and email=joe@blow.com' throws an error)

B) if I used this method it would seem to be a two step process...there must be a more efficient 'select' statement to accomplish this in one step?

We're creating a unit test for a cases trigger and as part of the process we need to create new cases.

We're using something like this to start but we're stuck...

   ....

   List<case> cases=new List<case>();

   for(integer I=0; I<20; I++)

   {

             string em='joe@gmail.com/'+String.valueof(i);

             cases.add( new case(contact.email=em) ); //<= this throws an Error: Compile Error: Invalid field initializer: contact.email at line 10 column 33

   }

   insert cases;    

   ...

I'm not sure how to fill in the email portion or even if I'll need more info.