Find your content:

Search form

You are here

Data changed by trigger for field owner id owner cannot be blank

 
Share

I'm getting an error "Data changed by trigger for field owner id owner cannot be blank" which is very interesting because I'm not actually doing anything with any OwnerId's, and the research that I have done people were setting their Owner Id's to null. I have to populate a Lookup from my addresses where Zip Key is not null.. So what I do is create a set of Zip Keys that are currently populated in Addresses, Then I take those Zip keys and search for them in my Zip_Key__c and Map them to their Regional Manager(Rep#1). Right now I'm just trying to see my output to see if its working but I'm getting an error. Does anyone see an Error in my Trigger or Test class? I think its in my test class, I think its pointing to..

** I forgot to insert Zip_Key__c data -- one error

s.Rep_2__c = acc2.Id;

Which is a Lookup on Account

Trigger

// trigger body here 

Set < id > addSet = new Set < id > ();
    for (Address__c a: [SELECT Rep_Account_Lookup__c, Zip_Key__c, ZipKey_Alias__c, Customer_Number_from_ZipKey__c,Name FROM Address__c ]) {
        if(a.Zip_Key__c != null){ 
        addSet.add(a.Zip_Key__c);
           system.debug('addSet   ' +addSet);   
        }
    }       
    List < Zip_Key__c > zipKeyList = [SELECT Regional_Manager__c  FROM Zip_Key__c Where ZipKey_Alias__c =: addSet];
   Map < String, Zip_Key__c > zipKeyManager = new Map < String, Zip_Key__c > (); 
    system.debug('addList ' +zipKeyList); 

   for (Zip_Key__c zk: zipKeyList)
  {
     zipKeyManager.put(zk.Regional_Manager__c, zk);
  }   
    system.debug('This is zipKeyManager'  +zipKeyManager ); 
   /* for (Split__c cs: Trigger.new) {
        if (addList.isEmpty()) {
            break; 
            }               
            if (addList.get(cs.Production_Site_Address__c).Zip_Key__c != null || String.isNotEmpty(addList.get(cs.Production_Site_Address__c).Zip_Key__c)) {
                if (cs.Rep_1_Production_Site_Rep_v2__c == null) { 
                   cs.Rep_1_Production_Site_Rep_v2__c = addList.get(cs.Production_Site_Address__c).Rep_Account_Lookup__c; 
                }  
            }
        }   */   
    }

Test Class

Account acc = new Account();
    acc.name = 'Test Account';
    acc.BillingCity = 'test City';
    insert acc;

    Address__c add = new Address__c();
    add.Account__c = acc.id;
    add.Type__c = 'Billing';
    add.name = 'Test Address';
    insert add;

    Contact contact = new Contact(LastName = 'hello', FirstName = 'World', Email = 'standarduser@testorg.com', AccountId = acc.Id);
    insert contact;


    Account acc2 = new Account();
    acc2.name = 'Test Account2';
    acc2.BillingCity = 'test City2';
    insert acc2;

    Contact contact2 = new Contact(LastName = 'hello2', FirstName = 'World2', Email = 'standarduser2@testorg.com', AccountId = acc2.Id);
    insert contact2;

    Product2 prod2 = new Product2();
    prod2.Name = 'TestProduct';
    prod2.IsActive = True;
    prod2.AE_Text__c = 'TestText';
    prod2.Item_number__c = 'TestNumber';
    insert prod2;

    Split__c s = new Split__c();
    s.Product__c = prod2.id;
    s.End_Customer_Account__c = acc.id;
    s.Production_Site_Address__c = add.id;
    s.Rep_2__c = acc2.Id;
    insert s;

Attribution to: EricSSH
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/34705

My Block Status

My Block Content