• megan.burch
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 74
    Replies

Hi, 

 

I"m writing a trigger to populate a lookup field on the account based on a field that comes in via ETL feed. The lookup is a lookup to another account record type. I'm getting this error right now. system.stringexception invalid id external entry point

 

Below is my code

 

trigger masterchainname on Account (before insert, before update) 
{
   //create a map with a list of master chain names
   List <id> accts = new List <id> ();
   Account[] accounts = Trigger.new;
   //for each account add the MCName to the list
   for(Account a: accounts)
   {
       accts.add(a.Hotel_Chain_Name__c);
   }
    
    List <account> acclist = [select id, name, hotel_chain_name__c, chain_code_account__c from account where id in:accts];
	
    for (account a: accounts)      
    {
        	system.debug ('a.name' + a.name);
        	if (a.Hotel_Chain_Name__c != null && (Trigger.isInsert || (Trigger.isUpdate && ((Trigger.oldMap.get(a.Id).hotel_chain_name__c != a.Market__c) || (a.Chain_Code_Account__c == null) ))))
            { 
                a.Chain_Code_Account__c = a.id;
            }    
    }            
}

 

Hi, 

 

I have a trigger that populates a field on a custom object with a field on the account, but the field on that account is sometimes null. 

 

I put a validation rule on the custom object lookup field for when the field is null, throw an error message saying the field must be filled in. 

 

If I fill in field and save I still get the message even though the filed is filled in. 


Any suggestion for fixing this? 

 

Thanks!

Hi, 

 

I've been running this trigger in production for awhile, but it's running into governor limits for too many SOQL queries. Any suggestions on how to fix it?

 

Trigger

Trigger marketassignmenttrigger on Account (before Insert, before Update)
{
    //Iterate through all accounts passed to the trigger
    Account[] accounts = Trigger.new;
    for (Account a : accounts)
    {
        //The market on the account needs to be populated and (the record is new or (the record is updated and (the market field is changed or the geojunction is null)
        if (a.Market__c != null && (Trigger.isInsert || (Trigger.isUpdate && ((Trigger.oldMap.get(a.Id).Market__c != a.Market__c) || (a.geojunction__c == null) ))))
        { 
            //pull the geojunction ids
            List<GeoJunction__c> geojunctions = [select Id, Market_Assignments__r.Market_Manager__r.id, Market_Assignments__r.Market_Manager__r.IsActive  from GeoJunction__c where name = :a.Market__c];
            
            //Iterate the geo_junctions
            for (GeoJunction__c g : geojunctions)
            {
                if (g.id != null)
                {
                    //updates geojunction on account
                    a.geojunction__c = g.Id;
                    
                    if(a.ownerid == '00560000001267d' && g.Market_Assignments__r.Market_Manager__r.id != null && g.Market_Assignments__r.Market_Manager__r.IsActive  == TRUE)
                    {
                        //updates geojunction on account
                        a.ownerid = g.Market_Assignments__r.Market_Manager__r.id;
                        a.Account_Owner_hidden__c = g.Market_Assignments__r.Market_Manager__r.id;
                    }
                }
            }
        }
    }
}

 

Hi, 

 

I have a trigger which takes an array of fields off one object and populates them to another object based on some logic. The trigger works great but I'm having problems getting the last part covered by my class. Any suggestions would be great. 

 

trigger RMRequestsTrigger on RM_Requests__c (before insert, before update)
{
    //Iterate through all RM requests passed to trigger   
    RM_Requests__c[] requests = trigger.new;
    
    for (RM_Requests__c r :requests)
    {
        //trigger if account is not null and record type is SIP Exclusive
        if (r.account__c != null && r.recordtypeid == '01260000000JAaN')
        {
            //create a list of accounts
            List<Account> accounts = [select Owner.id, id, name, GeoJunction__r.Market_Assignments__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c,
            GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c, GeoJunction__r.Market_Assignments__r.Market_Manager__c
            from Account where id = :r.Account__c];
            
            for (Account a : accounts)
            {
                if (trigger.isinsert || (trigger.isupdate && trigger.oldmap.get(r.id).account__c != r.account__c))
                {
                r.Account_Owner_Time_of_Creation__c = a.owner.id;
                }
                
                //Set RM Request Owner to be the same as account owner if MM Override is false, current stage submitted to RM and Account owner Time of Creation is not null
                if(r.Account_Owner_Time_of_Creation__c != null)
                {
                   //If status is not null or in process by GHS Team set RM request owner to be the same as the account owner and blank out shared mms
                   if(r.Current_Stage__C != null && r.current_stage__c !='In Progress by GHS Team' && r.Market_Manager_Overide__c == false)
                    {
                        r.ownerid = r.Account_Owner_Time_of_Creation__c ;
                    }
                }
                
                if (trigger.isinsert || (trigger.isupdate && trigger.oldmap.get(r.id).ownerid != r.ownerid))
                {
                    r.market_manager_shared1__c = null;
                    r.market_manager_shared2__c = null;
                    r.market_manager_shared3__c = null;
                    
                    if (a.geojunction__c !=null)
                    {
                        //Set Shared MMs based off market assignement and request owner
     
                        if (r.ownerid == a.GeoJunction__r.Market_Assignments__r.Market_Manager__c)
                        {
                            r.market_manager_shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared1__c;
                            r.market_manager_shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared2__c;
                            r.market_manager_shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared_3__c;
                        }
                        else if (r.ownerid == a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c)
                        {
                            r.market_manager_shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager__c;
                            r.market_manager_shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared2__c;
                            r.market_manager_shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared_3__c;
                        }
                        else if (r.ownerid == a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c)
                        {
                            r.market_manager_shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager__c;
                            r.market_manager_shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared1__c;
                            r.market_manager_shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared_3__c;
                        }
                        else if (r.ownerid == a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c)
                        {
                            r.market_manager_shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager__c;
                            r.market_manager_shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared1__c;
                            r.market_manager_shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_shared2__c;
                        }
                    }
                }
            }
        }
    }
}

 

@istest public class RMReqeustsTriggerTest{
    static testmethod void RMReqeustsTriggerTest(){
        
Geo_Codes__c geo = new geo_codes__c ();
        geo.name = 'test';
        insert geo;

Market_Assignments__c m1 = new Market_Assignments__c ();
        
         m1.Name = 'Market Assignment';

         insert m1;
        
        m1 = [select id, market_manager__c, market_manager_shared1__c, market_manager_shared2__c, market_manager_shared_3__c from market_assignments__c where id = :m1.id];
         system.debug ('M1 Shared =' + m1.Market_Manager_Shared1__c);
         
GeoJunction__c g1  = new GeoJunction__c();
      g1.shared_market__c = true;
      g1.geo_codes__c = geo.id;
      g1.market_assignments__c = m1.id;
      insert g1;
 
        g1 = [select id, name, geo_codes__c, market_assignments__c, market_assignments__r.market_manager__c, market_assignments__r.market_manager_shared1__c from geojunction__c where id = :g1.id];

Account a1 = new Account();

        a1.Name = 'Test Account';
        a1.geojunction__c = g1.id;
            insert a1;

        a1 = [select Owner.id, id, name, GeoJunction__r.Market_Assignments__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c,
              GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c, GeoJunction__r.Market_Assignments__r.Market_Manager__c
              from Account where Id = :a1.id];

        
          m1.Name = 'Market Assignment';
          m1.market_manager__c = a1.ownerid;

          update m1;
          m1 = [select id, market_manager__c, market_manager_shared1__c, market_manager_shared2__c, market_manager_shared_3__c from market_assignments__c where id =:m1.id];          

        
     RM_Requests__c rmReq = new RM_Requests__c();
       
         rmReq.Account_Owner_Time_of_Creation__c = a1.OwnerId;
         rmReq.name = 'test';
         rmReq.Market_Manager_Overide__c = False;
         rmreq.account__c = a1.id;
         rmreq.current_stage__c = 'Submitted to RM Team';
         rmreq.recordtypeid = '01260000000JAaN';

            insert rmReq;
     system.debug ('shared 1 =' + rmreq.market_manager_shared1__c);
       
     rmreq = [select id, Account_Owner_Time_of_Creation__c, account__c, ownerid, shared_market_account__c, Market_Manager_Shared2__c, Market_Manager_Shared3__c, Market_Manager_Shared1__c from rm_requests__c where id = :rmreq.id];
            
            
    system.assertequals (rmReq.Account_Owner_Time_of_Creation__c, a1.OwnerId);
    system.assertequals (rmReq.ownerid, a1.ownerid);
    if (rmreq.ownerid == a1.GeoJunction__r.Market_Assignments__r.Market_Manager__c)
        {system.assertequals (rmreq.market_manager_shared1__c, m1.market_manager_shared1__c);
        system.assertequals (rmreq.market_manager_shared2__c, m1.market_manager_shared2__c);
        system.assertequals (rmreq.market_manager_shared3__c, m1.market_manager_shared_3__c);}


          rmReq.Market_Manager_Overide__c= True;
          rmReq.Account_Owner_Time_of_Creation__c = a1.OwnerId;
          rmreq.account__c = a1.id;
         
          update rmReq;
      
          system.assertequals(a1.OwnerId,rmReq.Account_Owner_Time_of_Creation__c);
   }
}

 

Hi, 

 

I'm writing a trigger that pulls user names from a custom object and writes them to a field on another custom object. There are up to 4 fields that could be updated. That all works, the problem is I want to do it for every name that is not the owner on the object I'm writing to and if conditions are too complicated since any of the names could be the owner. My trigger is below. Any suggestions? 

 

trigger SharedMMTrigger on RM_Requests__c (before insert, before update) {

    //iterate through all requests passed to the trigger
    RM_requests__c[]requests = Trigger.new;
    for (RM_requests__c RM: requests){ 
        

    {  
        
       List <account> accounts = [select id, name, GeoJunction__r.Market_Assignments__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c, GeoJunction__r.Market_Assignments__r.Market_Manager__c from account where id = :rm.account__c];    
       System.debug(' market assignment = ' + rm.account__c);
         
        for (account a : accounts){
              if (a.geojunction__c !=null)
              if(rm.shared_market_Account__c == 'yes')
              {
                  if (rm.owner.id != a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c){
             rm.Market_Manager_Shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c;
                  }
                      else 
                          rm.Market_Manager_Shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c;
              
                  if (rm.owner.id != a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c){
             rm.Market_Manager_Shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c;
                  }
                  else 
                      rm.Market_Manager_Shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c;
                    
                  if (rm.owner.id != a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c){
             rm.Market_Manager_Shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c;
                  }
                  else rm.Market_Manager_Shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c;
        }
     }                                                                         
    }
  }
}

 

Hi,

 

I'm trying to write a trigger that takes a custom object record and if a certain field is checked, creates a new record with a different owner. Everything is working except for the owner field. When I try to set the owner field equal to a field from the account object I get this error. Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Account> at line 70 column 32. Any help would be much appreciated. Trigger is below.

 

trigger SharedAccountTrigger on RM_Requests__c (after insert) { 


List<RM_Requests__c> RM = new List<RM_Requests__c>();

List<Account> a = [SELECT Name, Market_Manager_Assignment__c, Market_Manager_Shared1__c, Market_Manager_Shared2__c, Market_Manager_Shared_3__c FROM Account];

    for (RM_Requests__c newRM: Trigger.New)
         if (newRM.RecordTypeID == '01260000000JAaNAAW')
         if (newRM.Market_Manager_Overide__c == True)
         if (newRM.Shared_Market_Account__c == 'YES'){
                 
                 RM.add (new RM_Requests__c(
                     RecordTypeID = '01260000000JBr4AAG',
                     Name = newRM.name,
                     Submitted_to_Promo_Team__c = newRM.Submitted_to_Promo_Team__c,
                     Unexclusive_Date_send_notification__c = newRM.Unexclusive_Date_send_notification__c,
                     Account__c = newRM.Account__c,
                     Reason_Code__c = newRM.Reason_Code__c,
                     Possible_Points__c = newRM.Possible_Points__c,
                     Location_ID__c = newRM.Location_ID__c,
                     Chosen_Placement__c = newRM.Chosen_Placement__c,
                     Market_Manager_Overide__c = True,
                     Current_Stage__c = newRM.Current_Stage__c,
                     MM_Email__c = newRM.MM_Email__c,
                     SMM_Email__c = newRM.SMM_Email__c,
                     RD_Email__c = newRM.RD_Email__c,
                     Duration_Days__c = newRM.Duration_Days__c,
                     Point_of_Sale__c = newRM.Point_of_Sale__c,
                     Point_of_Sale_Other_Notes__c = newRM.Point_of_Sale_Other_Notes__c,
                     Booking_Path__c = newRM.Booking_Path__c,
                     TO_BE_BUILT__c = newRM.TO_BE_BUILT__c,
                     Deal_Type__c = newRM.Deal_Type__c,
                     Percent_off__c = newRM.Percent_off__c,
                     Free_Nights__c = newRM.Free_Nights__c,
                     Dollar_Off__c = newRM.Dollar_Off__c,
                     Promotion_Description__c = newRM.Promotion_Description__c,
                     Minimum_Length_of_Stay__c = newRM.Minimum_Length_of_Stay__c,
                     AP_Band__c = newRM.AP_Band__c,
                     Booking_Start_Date2__c = newRM.Booking_Start_Date2__c,
                     Booking_End_Date__c = newRM.Booking_End_Date__c,
                     MEXICO_ONLY_apply_promo_to_all_nights__c = newRM.MEXICO_ONLY_apply_promo_to_all_nights__c,
                     Stay_Start_Date__c = newRM.Stay_Start_Date__c,
                     Stay_End_Date__c = newRM.Stay_End_Date__c,
                     Blackout_Dates_Restrictions__c = newRM.Blackout_Dates_Restrictions__c,
                     Booking_Start_Date_Time__c = newRm.Booking_Start_Date_Time__c,
                     Booking_End_Date_Time__c = newRM.Booking_End_Date_Time__c,
                     Cumulative_Free_Nights_FN_Only__c = newRM.Cumulative_Free_Nights_FN_Only__c,
                     Select_Nights_to_Apply__c = newRM.Select_Nights_to_Apply__c,
                     Guest_must_arrive_on__c = newRM.Guest_must_arrive_on__c,
                     Rate_Type__c = newRM.Rate_Type__c,
                     Room_Type__c = newRM.Room_Type__c,
                     POS_Channels__c = newRM.POS_Channels__c,
                     Deal_Details__c = newRM.Deal_Details__c,
                     All_POS_Test__c = newRM.All_POS_Test__c,
                     RM_Actioned_Date__c= newRM.RM_Actioned_Date__c,
                     SLA__c = newRM.SLA__c,
                     Submission_Date__c = newRM.Submission_Date__c,
                     GMT_Offset_created_by__c = newRM.GMT_Offset_created_by__c,
                     Adjusted_Location_ID__c = newRM.Adjusted_Location_ID__c,
                     Adjusted_POS__c = newRM.Adjusted_POS__c,
                     Adjusted_Position__c = newRM.Adjusted_Position__c,
                     Adjusted_Start_Time__c = newRM.Adjusted_Start_Time__c,
                     Adjusted_End_Time__c = newRM.Adjusted_End_Time__c,
                     Adjustment_Reason_Code__c = newRM.Adjustment_Reason_Code__c,
                     Account_Owner_Time_of_Creation__c = newRM.Account_Owner_Time_of_Creation__c,
                     ownerid = a.Market_Manager_Assignment__c
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     ));   
         }
   insert RM;
 }

 

 

I'm having trouble with a trigger I'm trying to write. When new accounts are loaded into my org the owner field is sometimes defaulted to a placeholder user 'x x'. There is another field on the account called market assignment which is a forumula that pulls the market assignment on the market assignment custom object. Also on the market assignement custom object is the manager which should also be the account owner. The trigger is trying to update accounts where owner = 'x x' with the manager from the corresponding market assignement. Any help would be much appreciated. Thanks!!

 

Trigger

 

Trigger marketassignmenttrigger on Account (before Insert, before Update) {
    
    Map<String, Market_Assignments__c> junctionMap = new Map<String, Market_Assignments__c>{};
    
    for (Account a : Trigger.new)
    {
        if (a.owner != null && 
        (Trigger.isInsert || (Trigger.isUpdate && Trigger.oldMap.get(a.id).Market_assignment_copy__c == a.Market_assignment_copy__c)))
        {            
            //Ignore casing in the map
            junctionMap.put(a.Market_assignment_copy__c.toLowerCase(), null);            
        }
    }
    
    if (!junctionMap.isEmpty())
    {    
        
        for (Market_Assignments__c item : [ select Id, market_manager__c, name from Market_Assignments__c where market_manager__c IN :junctionMap.keySet()] )
        {
            junctionMap.put(item.name.toLowerCase(), item);
        }
                        
        for (Account a : Trigger.new)
        {
            if (a.ownerid == '00560000001267d')
            {
               Market_Assignments__c m = junctionMap.get(a.market_assignment_copy__c.toLowerCase());
                
                
                {
                    a.ownerid = m.market_manager__c;                
                }
                
            }
        }
    }    
}

 

I wrote this simple trigger which is working fine, but the test class I wrote isn't covering any code. The trigger fills a custom text field (market) on the account page to match another custom field on the account page (geojunction). The market field also could get written into by an ETL load so thats why it had to be a text field. Any input would be great. Thanks

 

Trigger

	trigger MarketoffGeoJunctionTrigger on Account (before Insert, before Update) {

     if (Trigger.isInsert) {
        for(Account a : Trigger.new){
            List<geojunction__c> GeoJunction = [select name,id from GeoJunction__c where id=: a.geojunction__c];
            for (GeoJunction__c g : GeoJunction) {
              if(a.geojunction__c !=null){
                     a.market__c = g.name;
                }
            }
        } 
    }
     if (Trigger.isUpdate) {
     for(Account a : Trigger.new){
     List<geojunction__c> GeoJunction = [select name,id from GeoJunction__c where id=: a.geojunction__c];
            for (GeoJunction__c g : GeoJunction) {
                 if(a.geojunction__c !=null){
                    a.market__c=g.name;
                }
            }
        }
    }
}

 Class

@istest public class MarketoffGeoJunctionTriggerTest{
  static testMethod void MarketoffGeoJunctionTriggerTest(){
        
        Geojunction__c g1 = new Geojunction__c();

        g1.name = 'test';
        
        insert g1;

        g1 = [Select Id, name from geojunction__c where ID = :g1.ID];
        
          Account a1 = new Account();
       
         a1.Name = 'Test Account';
         a1.geojunction__c = g1.id;
         a1.market__c = g1.name;
                         
      
        insert a1;

    system.assertequals(g1.name,a1.geojunction__c);

         a1.Name = 'Test Account';
         a1.geojunction__c = 'test';
         a1.market__c = g1.name;
      
      
          update a1;
      
          system.assertequals(g1.name,a1.geojunction__c);
   }
}

 

I wrote this trigger but don't have any idea how to start writing a test case for it. The trigger evaluates if a box is checked on a custom object. If the box is unchecked the owner defaults to the account owner at the time of creation. If the box is checked then the owner can be manually updated and the trigger isn't fired. Here is the trigger code any help would be greatly appreciated.

 

trigger MMOverideTrigger on RM_Requests__c (before insert, before update) {

    if (Trigger.isInsert) {
    RM_Requests__c[] requests = Trigger.new;
        for (RM_Requests__c r :requests){
            List<Account> accounts = [select OwnerId  from Account where id = :r.Account__c];
            for (Account a : accounts) {
                r.Account_Owner_Time_of_Creation__c = a.OwnerId;
            }
           if(r.Account_Owner_Id_Time_of_Creation__c != null) {           
               if(r.Market_Manager_Overide__c == false) {
                    r.OwnerID = r.Account_Owner_Time_of_Creation__c;
               }
           }
        }           
  }   
    
    if (Trigger.isUpdate) {
        //Assign the request before and after the change into a Map
        Map<Id,RM_Requests__c> newRequestMap = Trigger.newMap;
        Map<Id,RM_Requests__c> oldRequestMap = Trigger.oldMap;
        
        for(Id requestId:newRequestMap.keySet()){
             RM_Requests__c myNewRequest = newRequestMap.get(requestId);
             RM_Requests__c myOldRequest = oldRequestMap.get(requestId);
             if ((myNewRequest.Account__c <> myOldRequest.Account__c) || (myNewRequest.Account_Owner_Time_of_Creation__c == NULL)) {
                List<Account> accounts = [select OwnerId  from Account where id = :myNewRequest.Account__c];
                for (Account a : accounts) {
                    myNewRequest.Account_Owner_Time_of_Creation__c = a.OwnerId;
                }
             }
             if(myNewRequest.Account_Owner_Id_Time_of_Creation__c != null) {
                 if(myNewRequest.Market_Manager_Overide__c == false) {
                   myNewRequest.OwnerID = myNewRequest.Account_Owner_Time_of_Creation__c;
                 }
             }
        }

Hi, 

 

I've been running this trigger in production for awhile, but it's running into governor limits for too many SOQL queries. Any suggestions on how to fix it?

 

Trigger

Trigger marketassignmenttrigger on Account (before Insert, before Update)
{
    //Iterate through all accounts passed to the trigger
    Account[] accounts = Trigger.new;
    for (Account a : accounts)
    {
        //The market on the account needs to be populated and (the record is new or (the record is updated and (the market field is changed or the geojunction is null)
        if (a.Market__c != null && (Trigger.isInsert || (Trigger.isUpdate && ((Trigger.oldMap.get(a.Id).Market__c != a.Market__c) || (a.geojunction__c == null) ))))
        { 
            //pull the geojunction ids
            List<GeoJunction__c> geojunctions = [select Id, Market_Assignments__r.Market_Manager__r.id, Market_Assignments__r.Market_Manager__r.IsActive  from GeoJunction__c where name = :a.Market__c];
            
            //Iterate the geo_junctions
            for (GeoJunction__c g : geojunctions)
            {
                if (g.id != null)
                {
                    //updates geojunction on account
                    a.geojunction__c = g.Id;
                    
                    if(a.ownerid == '00560000001267d' && g.Market_Assignments__r.Market_Manager__r.id != null && g.Market_Assignments__r.Market_Manager__r.IsActive  == TRUE)
                    {
                        //updates geojunction on account
                        a.ownerid = g.Market_Assignments__r.Market_Manager__r.id;
                        a.Account_Owner_hidden__c = g.Market_Assignments__r.Market_Manager__r.id;
                    }
                }
            }
        }
    }
}

 

Hi, 

 

I'm writing a trigger that pulls user names from a custom object and writes them to a field on another custom object. There are up to 4 fields that could be updated. That all works, the problem is I want to do it for every name that is not the owner on the object I'm writing to and if conditions are too complicated since any of the names could be the owner. My trigger is below. Any suggestions? 

 

trigger SharedMMTrigger on RM_Requests__c (before insert, before update) {

    //iterate through all requests passed to the trigger
    RM_requests__c[]requests = Trigger.new;
    for (RM_requests__c RM: requests){ 
        

    {  
        
       List <account> accounts = [select id, name, GeoJunction__r.Market_Assignments__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c, GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c, GeoJunction__r.Market_Assignments__r.Market_Manager__c from account where id = :rm.account__c];    
       System.debug(' market assignment = ' + rm.account__c);
         
        for (account a : accounts){
              if (a.geojunction__c !=null)
              if(rm.shared_market_Account__c == 'yes')
              {
                  if (rm.owner.id != a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c){
             rm.Market_Manager_Shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c;
                  }
                      else 
                          rm.Market_Manager_Shared1__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c;
              
                  if (rm.owner.id != a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c){
             rm.Market_Manager_Shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared2__c;
                  }
                  else 
                      rm.Market_Manager_Shared2__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c;
                    
                  if (rm.owner.id != a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c){
             rm.Market_Manager_Shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared_3__c;
                  }
                  else rm.Market_Manager_Shared3__c = a.GeoJunction__r.Market_Assignments__r.Market_Manager_Shared1__c;
        }
     }                                                                         
    }
  }
}

 

Hi,

 

I'm trying to write a trigger that takes a custom object record and if a certain field is checked, creates a new record with a different owner. Everything is working except for the owner field. When I try to set the owner field equal to a field from the account object I get this error. Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST<Account> at line 70 column 32. Any help would be much appreciated. Trigger is below.

 

trigger SharedAccountTrigger on RM_Requests__c (after insert) { 


List<RM_Requests__c> RM = new List<RM_Requests__c>();

List<Account> a = [SELECT Name, Market_Manager_Assignment__c, Market_Manager_Shared1__c, Market_Manager_Shared2__c, Market_Manager_Shared_3__c FROM Account];

    for (RM_Requests__c newRM: Trigger.New)
         if (newRM.RecordTypeID == '01260000000JAaNAAW')
         if (newRM.Market_Manager_Overide__c == True)
         if (newRM.Shared_Market_Account__c == 'YES'){
                 
                 RM.add (new RM_Requests__c(
                     RecordTypeID = '01260000000JBr4AAG',
                     Name = newRM.name,
                     Submitted_to_Promo_Team__c = newRM.Submitted_to_Promo_Team__c,
                     Unexclusive_Date_send_notification__c = newRM.Unexclusive_Date_send_notification__c,
                     Account__c = newRM.Account__c,
                     Reason_Code__c = newRM.Reason_Code__c,
                     Possible_Points__c = newRM.Possible_Points__c,
                     Location_ID__c = newRM.Location_ID__c,
                     Chosen_Placement__c = newRM.Chosen_Placement__c,
                     Market_Manager_Overide__c = True,
                     Current_Stage__c = newRM.Current_Stage__c,
                     MM_Email__c = newRM.MM_Email__c,
                     SMM_Email__c = newRM.SMM_Email__c,
                     RD_Email__c = newRM.RD_Email__c,
                     Duration_Days__c = newRM.Duration_Days__c,
                     Point_of_Sale__c = newRM.Point_of_Sale__c,
                     Point_of_Sale_Other_Notes__c = newRM.Point_of_Sale_Other_Notes__c,
                     Booking_Path__c = newRM.Booking_Path__c,
                     TO_BE_BUILT__c = newRM.TO_BE_BUILT__c,
                     Deal_Type__c = newRM.Deal_Type__c,
                     Percent_off__c = newRM.Percent_off__c,
                     Free_Nights__c = newRM.Free_Nights__c,
                     Dollar_Off__c = newRM.Dollar_Off__c,
                     Promotion_Description__c = newRM.Promotion_Description__c,
                     Minimum_Length_of_Stay__c = newRM.Minimum_Length_of_Stay__c,
                     AP_Band__c = newRM.AP_Band__c,
                     Booking_Start_Date2__c = newRM.Booking_Start_Date2__c,
                     Booking_End_Date__c = newRM.Booking_End_Date__c,
                     MEXICO_ONLY_apply_promo_to_all_nights__c = newRM.MEXICO_ONLY_apply_promo_to_all_nights__c,
                     Stay_Start_Date__c = newRM.Stay_Start_Date__c,
                     Stay_End_Date__c = newRM.Stay_End_Date__c,
                     Blackout_Dates_Restrictions__c = newRM.Blackout_Dates_Restrictions__c,
                     Booking_Start_Date_Time__c = newRm.Booking_Start_Date_Time__c,
                     Booking_End_Date_Time__c = newRM.Booking_End_Date_Time__c,
                     Cumulative_Free_Nights_FN_Only__c = newRM.Cumulative_Free_Nights_FN_Only__c,
                     Select_Nights_to_Apply__c = newRM.Select_Nights_to_Apply__c,
                     Guest_must_arrive_on__c = newRM.Guest_must_arrive_on__c,
                     Rate_Type__c = newRM.Rate_Type__c,
                     Room_Type__c = newRM.Room_Type__c,
                     POS_Channels__c = newRM.POS_Channels__c,
                     Deal_Details__c = newRM.Deal_Details__c,
                     All_POS_Test__c = newRM.All_POS_Test__c,
                     RM_Actioned_Date__c= newRM.RM_Actioned_Date__c,
                     SLA__c = newRM.SLA__c,
                     Submission_Date__c = newRM.Submission_Date__c,
                     GMT_Offset_created_by__c = newRM.GMT_Offset_created_by__c,
                     Adjusted_Location_ID__c = newRM.Adjusted_Location_ID__c,
                     Adjusted_POS__c = newRM.Adjusted_POS__c,
                     Adjusted_Position__c = newRM.Adjusted_Position__c,
                     Adjusted_Start_Time__c = newRM.Adjusted_Start_Time__c,
                     Adjusted_End_Time__c = newRM.Adjusted_End_Time__c,
                     Adjustment_Reason_Code__c = newRM.Adjustment_Reason_Code__c,
                     Account_Owner_Time_of_Creation__c = newRM.Account_Owner_Time_of_Creation__c,
                     ownerid = a.Market_Manager_Assignment__c
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     
                     ));   
         }
   insert RM;
 }

 

 

I'm having trouble with a trigger I'm trying to write. When new accounts are loaded into my org the owner field is sometimes defaulted to a placeholder user 'x x'. There is another field on the account called market assignment which is a forumula that pulls the market assignment on the market assignment custom object. Also on the market assignement custom object is the manager which should also be the account owner. The trigger is trying to update accounts where owner = 'x x' with the manager from the corresponding market assignement. Any help would be much appreciated. Thanks!!

 

Trigger

 

Trigger marketassignmenttrigger on Account (before Insert, before Update) {
    
    Map<String, Market_Assignments__c> junctionMap = new Map<String, Market_Assignments__c>{};
    
    for (Account a : Trigger.new)
    {
        if (a.owner != null && 
        (Trigger.isInsert || (Trigger.isUpdate && Trigger.oldMap.get(a.id).Market_assignment_copy__c == a.Market_assignment_copy__c)))
        {            
            //Ignore casing in the map
            junctionMap.put(a.Market_assignment_copy__c.toLowerCase(), null);            
        }
    }
    
    if (!junctionMap.isEmpty())
    {    
        
        for (Market_Assignments__c item : [ select Id, market_manager__c, name from Market_Assignments__c where market_manager__c IN :junctionMap.keySet()] )
        {
            junctionMap.put(item.name.toLowerCase(), item);
        }
                        
        for (Account a : Trigger.new)
        {
            if (a.ownerid == '00560000001267d')
            {
               Market_Assignments__c m = junctionMap.get(a.market_assignment_copy__c.toLowerCase());
                
                
                {
                    a.ownerid = m.market_manager__c;                
                }
                
            }
        }
    }    
}