• DavidHabib.ax407
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 5
    Replies

I was using a set of sObjects, assuming that the set would prevent me from putting the same sObject in the set multiple times.  Unfortunately, I found that if I modified one of the fields of the sObject between additions to the set, then the sObject would get put on multiple times.  Is this expected behavior or a bug?

 

Here is a sample test routine which asserts, exposing the problem:

 

    static testmethod void SetSobjectBug() {
        Account acc = new Account(name='Individual');
        insert acc;
        Contact con = new Contact(Lastname='Testy', AccountId=acc.Id);
        insert con;
        Campaign cmp = new Campaign(name='Test Campaign');
        insert cmp;
        CampaignMember cm = new CampaignMember(CampaignId=cmp.Id, ContactId=con.Id, Status='Sent');
        
        Set<CampaignMember> setCM = new Set<CampaignMember>();
        system.assert(setCM.add(cm));
        cm.Status = 'Responded';
        system.assert(setCM.add(cm) == false);  // THIS ASSERTS.  If cm.Status is not changed, it won't assert.
    }

 

I was assuming the set was holding onto a reference to the object, but given this assert, I wonder if the set is make a full copy of the object, and doing a full compare to test membership?

 

Thanks,
Dave

Campaign object's now have a CampaignMemberRecordType field which is the record type to create CampaignMember records with. 

 

Unfortunately, I can't set it in Apex code.  Eclipse complains with "Invalid field CampaignMemberRecordType for SObject Campaign".

 

I also tried using CampaignMemberType, but also got an Eclipse error.

 

What do I need to do to be able to set this programmatically?

 

Thanks,
Dave

I'm trying to write my first trigger (on Contacts), and I'm finding that the Trigger.new collection of Contacts seem to only hold contact.Id, but all other fields of the contacts are null. 
 
Here's the code, and it asserts at c.Name != null.  All the other sample code I've looked at seem to reference fields of the objects in Trigger.new without any problems.  What am I doing wrong?
 
trigger ContactTrigger on Contact (after insert, after update) {

    for (Contact c:Trigger.new) {

        system.assert(c != null);

        system.assert(c.Id != null);

        system.assert(c.Name != null);

    }

}