• Paul Scott
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I am adding a trigger to default a Contact owner to the Account owner. It works fine and passes the test I wrote for it. HOWEVER, it fails a test from another piece of apex, telling me:

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, reassignCtOwnerToAcOwner: data changed by trigger for field Owner ID: owner cannot be blank: []

Here is the trigger I'm trying to deploy:

trigger reassignCtOwnerToAcOwner on Contact (before insert, before update) {

    List<Id> accountIds = new List<Id>();
    Map<Id, Id> accountOwnerIdMap = new Map<Id, Id>();

    // all the accounts whose owner ids to look up
    for ( Contact c : Trigger.new ) {
        accountIds.add( c.accountId );
    }
   
    // look up each account owner id
    for ( Account acct : [ SELECT id, ownerId FROM account WHERE id IN :accountIds ] ) {
        accountOwnerIdMap.put( acct.id, acct.ownerId );
    }
   
    // change contact owner to its account owner
    for ( Contact c : Trigger.new ) {
        c.ownerId = accountOwnerIdMap.get( c.accountId );
    }
}

Here is the test class for the OTHER trigger that fails when I try to insert a contact:

public static testMethod void validateContactCountsAndActivities() {

        //Create Account
  Account ac = new Account(
   Name='Test Account',
   Initial_Lead_Source__c='Cold Call',
   Initial_Lead_Source_Detail__c='Cold Call',
   Account_Type__c='Prospect',
   Account_Status__c='Not Contacted'   );
  insert ac;

        //Create Contact
        Contact ct = new Contact(
                LastName='Test Contact',
                Email='testcontact@email.com',
                Account= ac);
        insert ct;



I'd like to re-open the discussion of SortOrder on the OpportunityLineItem object. A thread from 3.5 years ago can be located here:
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=3154

Looks like people from SF were going to look into it but obviously nothing has come to fruition. The reason I have put this in the Visualforce board is that we have have a few VF applications that could really take advantage of access to this field. Visualforce has also opened up new possibilities to UI design where the ability to manage SortOrder could be useful.

Also, no offense to salesforce.com, but the tool for sorting OpportunityLineItems is not that useful when there are multiple products with the same name. I have actually built a pretty slick sorting application but this is currently useless.

A lot of the concerns were about error handling. What happens if you have 3 line items but sort order is defined as, 1, 2, 2. Or 1, 2, 4. How about just throwing a sortOrder exception and force the developers to write good code?

Ideas? Thoughts?
http://ideas.salesforce.com/article/show/10092062/OpportunityLineItem_SortOrder_to_be_CreatableUpdatable

-Jason


Message Edited by TehNrd on 09-05-2008 01:22 PM
  • September 03, 2008
  • Like
  • 1