• Joe BB
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 27
    Replies

Hello,

I have the following trigger that is designed to change an Opportunity owner to a new account owenr after an account DLoader upsert. It compares the owners of Opportunity to new owenrs of accounts and users who share accounts (indicated by UserID inserted in SLS2__c upon account update).

 

The trigger works when I change account owners manually in SFDC, but does not work wehn I use that DataLoader to update ownership. It returns the following ERROR:

updateOppOwner: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.updateOppOwner: line 17, column 1.

 

Please help.

this is the trigger inserted in Account:Triggers

====

 

Line 17 : optyMap.get(acct.id).OwnerID= acct.OwnerID;

======

Full trigger:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

 

trigger updateOppOwner on Account (after insert, after update) {
  if (Trigger.isAfter) {
  Set<Id> acctIds = new Set<Id>();
    for (Account acct : Trigger.new) {
       acctIds.add(acct.Id);
       }     
Map<id,Opportunity> optyMap = new Map<Id,Opportunity>( [SELECT OwnerId  FROM Opportunity WHERE AccountId in :acctIds]);

    if ( !optyMap.isEmpty() ) {

    for (Account acct : Trigger.new) {

        for(Opportunity opty : optyMap.values() ) {      

            if(opty.OwnerId != acct.OwnerId && opty.OwnerId != acct.SLS2__c){

               optyMap.get(acct.id).OwnerID= acct.OwnerID;
                    } else {
          opty.OwnerId = opty.OwnerId ;
                   }
            }

        update optyMap.values();

        }
  }
    }
    }

  • February 15, 2013
  • Like
  • 0

Hello Fellas,

 

I was advised to post here. Maybe you will be able to help.

I cannot get this trigger to work upon Data Loader Account upsert.

It works when I do the changes within the application (UI), but it does not when I change the account owner of using the Data Loader.  When I use the Data Loader to upsert account ownership, it changes ownership of ALL opportunities in ALL accounts no matter whether account owner for a particular opportunity has changed or not.

 

Objective: After A Data Loader account upsert - Check IF an owner of an opportunity is NOT the owner of the account and a sharing person of the account,
THEN change owner of that opportunity to the NEW owner of the account to which that opportunity pertains.


For this purpose there is a custom field in account called SLS2__c,  which is updated each time accounts are upserted. This field contains the 15 character SF UserID of the person who shares the account.

 

trigger updateOppOwner on Account (after insert, after update) {
  if (Trigger.isAfter) {
  Set<Id> acctIds = new Set<Id>();
    for (Account acct : Trigger.new) {
       acctIds.add(acct.Id);
       }    
 
    List<Opportunity> optyList = [SELECT OwnerId  FROM Opportunity WHERE AccountId in :acctIds];
    if ( !optyList.isEmpty() ) {
    for (Account acct : Trigger.new) {
        for(Opportunity opty : optyList ) {      
            if(opty.OwnerId != acct.OwnerId && opty.OwnerId != acct.SLS2__c){
               opty.OwnerId = acct.OwnerID;
                    } else {
                      opty.OwnerId = opty.OwnerId ;
           }
            }
        update optyList;
        }
    }
   }
}

 


Again, the trigger works when account ownership is changed manually, but when I use the Data Loader, it changes ownership of ALL opportunities in ALL accounts no matter whether account owner for a particular opportunity has changed or not.


Do you have any suggestions?

  • February 07, 2013
  • Like
  • 0

 

Fellas,

 

I cannot get this trigger to work upon Data Loader Account upsert.

 

The trigger was designed with the help of two members of the community.

 

It works when I do the changes within the application (UI), but it does not when I change the account owner of using the Data Loader.

 

Objective: After A Data Loader account upsert - Check IF an owner of an opportunity is NOT the owner of the account and a sharing person of the account,

THEN change owner of that opportunity to the NEW owner of the account to which that opportunity pertains.

 

 

For this purpose there is a custom field in account called SLS2__c,  which is updated each time accounts are upserted. This field contains the 15 character SF UserID of the person who shares the account.

 

 

 

trigger updateOppOwner on Account (after insert, after update) {

  if (Trigger.isAfter) {

  Set<Id> acctIds = new Set<Id>();

    for (Account acct : Trigger.new) {

       acctIds.add(acct.Id);

       }    

 

    List<Opportunity> optyList = [SELECT OwnerId  FROM Opportunity WHERE AccountId in :acctIds];

    if ( !optyList.isEmpty() ) {

    for (Account acct : Trigger.new) {

        for(Opportunity opty : optyList ) {      

            if(opty.OwnerId != acct.OwnerId && opty.OwnerId != acct.SLS2__c){

               opty.OwnerId = acct.OwnerID;

                    } else {

                      opty.OwnerId = opty.OwnerId ;

           }

            }

        update optyList;

        }

    }

   }

}

 

 

Again, the trigger works when account ownership is changed manually, but when I use the Data Loader, it changes ownership of ALL opportunities in ALL accounts no matter whether account owner for a particular opportunity has changed or not.

 

Do you have any suggestions? 

  • February 07, 2013
  • Like
  • 0

I need to update an owner of an opportunity pertaining to an account when the owner of the account changes, but only if the owner of the opportunity is not one of the persons sharing the account pertaining to that opportunity.

 

So the owner of the opportunity should change only if the owner of the opportunity does not coincide with any of the USERS who share the account pertaining to the opportunity. Ownership of the opportunity will have to change to the person who owns the account.

 

Accounts can be shared by 3 persons - one owner and 2 shared users.

The owner of an Opportunity has a  custom field that represents his unique code. For example SLS=AT1. All 3 users who share an account have custom fields both in Accounts that represent their personal unique identification codes - SLS1, SLS2 and SLS3, where SLS1=account owner's code.

For example SLS1=ABF, SLS2=GHT, SLS3=AT1

 

Basically, the logic has to say the following:

If Opportunity field SLS does not match any of the account fields SLS1, SLS2 and SLS3, update opportunity owner with the current account owner.

Is that possible and how? I gues trigger, but how should it look like?

  • February 04, 2013
  • Like
  • 0

 

Hello,

in our organization, we do not want prior account owners of accounts to see their old accounts that have been transferred to new owners.
Therefore,  we are going to transfer all Opportunities and Contacts to the current Account owners to which these Opps and Contacts pertain.

However, I just noticed that if we transfer all Contacts pertaining to an account to their current Account owners, the Activities that have a contact assigned as a "Primary Coontact" will be transferred as well to the new contact owner.
We do not want activities to be transferred, because we have Sales reps that share the same accounts with the owners of those accounts and we want the activities created by different Sales reps taht share accounts to remain under their ownership.
Is there a way to disable “Primary Contact” for Activities? Or is there a workaround?
 
Thank you!!!
  • January 07, 2013
  • Like
  • 0

 

Hello,
I would like to be able to create a formula that can bring up (auto populate) a custom Activity field from a field that originates in the the object where the activity is related to.


For example, Account object has custom field that says Account#. The Related Activity (New Task) has the same custom field Account#. I would like to create a link between both fields, such that when Account# in Account record is populated it automatically transfers that field value to the related field in New Task, New Event and Log a Call Activities once an user clicks on these activities.

Could you  please tell me how I can create such trigger?

 

Please help!
Thank you so much!

  • October 18, 2012
  • Like
  • 0

Hello,

I have the following trigger that is designed to change an Opportunity owner to a new account owenr after an account DLoader upsert. It compares the owners of Opportunity to new owenrs of accounts and users who share accounts (indicated by UserID inserted in SLS2__c upon account update).

 

The trigger works when I change account owners manually in SFDC, but does not work wehn I use that DataLoader to update ownership. It returns the following ERROR:

updateOppOwner: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.updateOppOwner: line 17, column 1.

 

Please help.

this is the trigger inserted in Account:Triggers

====

 

Line 17 : optyMap.get(acct.id).OwnerID= acct.OwnerID;

======

Full trigger:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

 

trigger updateOppOwner on Account (after insert, after update) {
  if (Trigger.isAfter) {
  Set<Id> acctIds = new Set<Id>();
    for (Account acct : Trigger.new) {
       acctIds.add(acct.Id);
       }     
Map<id,Opportunity> optyMap = new Map<Id,Opportunity>( [SELECT OwnerId  FROM Opportunity WHERE AccountId in :acctIds]);

    if ( !optyMap.isEmpty() ) {

    for (Account acct : Trigger.new) {

        for(Opportunity opty : optyMap.values() ) {      

            if(opty.OwnerId != acct.OwnerId && opty.OwnerId != acct.SLS2__c){

               optyMap.get(acct.id).OwnerID= acct.OwnerID;
                    } else {
          opty.OwnerId = opty.OwnerId ;
                   }
            }

        update optyMap.values();

        }
  }
    }
    }

  • February 15, 2013
  • Like
  • 0

Hello Fellas,

 

I was advised to post here. Maybe you will be able to help.

I cannot get this trigger to work upon Data Loader Account upsert.

It works when I do the changes within the application (UI), but it does not when I change the account owner of using the Data Loader.  When I use the Data Loader to upsert account ownership, it changes ownership of ALL opportunities in ALL accounts no matter whether account owner for a particular opportunity has changed or not.

 

Objective: After A Data Loader account upsert - Check IF an owner of an opportunity is NOT the owner of the account and a sharing person of the account,
THEN change owner of that opportunity to the NEW owner of the account to which that opportunity pertains.


For this purpose there is a custom field in account called SLS2__c,  which is updated each time accounts are upserted. This field contains the 15 character SF UserID of the person who shares the account.

 

trigger updateOppOwner on Account (after insert, after update) {
  if (Trigger.isAfter) {
  Set<Id> acctIds = new Set<Id>();
    for (Account acct : Trigger.new) {
       acctIds.add(acct.Id);
       }    
 
    List<Opportunity> optyList = [SELECT OwnerId  FROM Opportunity WHERE AccountId in :acctIds];
    if ( !optyList.isEmpty() ) {
    for (Account acct : Trigger.new) {
        for(Opportunity opty : optyList ) {      
            if(opty.OwnerId != acct.OwnerId && opty.OwnerId != acct.SLS2__c){
               opty.OwnerId = acct.OwnerID;
                    } else {
                      opty.OwnerId = opty.OwnerId ;
           }
            }
        update optyList;
        }
    }
   }
}

 


Again, the trigger works when account ownership is changed manually, but when I use the Data Loader, it changes ownership of ALL opportunities in ALL accounts no matter whether account owner for a particular opportunity has changed or not.


Do you have any suggestions?

  • February 07, 2013
  • Like
  • 0

 

Fellas,

 

I cannot get this trigger to work upon Data Loader Account upsert.

 

The trigger was designed with the help of two members of the community.

 

It works when I do the changes within the application (UI), but it does not when I change the account owner of using the Data Loader.

 

Objective: After A Data Loader account upsert - Check IF an owner of an opportunity is NOT the owner of the account and a sharing person of the account,

THEN change owner of that opportunity to the NEW owner of the account to which that opportunity pertains.

 

 

For this purpose there is a custom field in account called SLS2__c,  which is updated each time accounts are upserted. This field contains the 15 character SF UserID of the person who shares the account.

 

 

 

trigger updateOppOwner on Account (after insert, after update) {

  if (Trigger.isAfter) {

  Set<Id> acctIds = new Set<Id>();

    for (Account acct : Trigger.new) {

       acctIds.add(acct.Id);

       }    

 

    List<Opportunity> optyList = [SELECT OwnerId  FROM Opportunity WHERE AccountId in :acctIds];

    if ( !optyList.isEmpty() ) {

    for (Account acct : Trigger.new) {

        for(Opportunity opty : optyList ) {      

            if(opty.OwnerId != acct.OwnerId && opty.OwnerId != acct.SLS2__c){

               opty.OwnerId = acct.OwnerID;

                    } else {

                      opty.OwnerId = opty.OwnerId ;

           }

            }

        update optyList;

        }

    }

   }

}

 

 

Again, the trigger works when account ownership is changed manually, but when I use the Data Loader, it changes ownership of ALL opportunities in ALL accounts no matter whether account owner for a particular opportunity has changed or not.

 

Do you have any suggestions? 

  • February 07, 2013
  • Like
  • 0

I need to update an owner of an opportunity pertaining to an account when the owner of the account changes, but only if the owner of the opportunity is not one of the persons sharing the account pertaining to that opportunity.

 

So the owner of the opportunity should change only if the owner of the opportunity does not coincide with any of the USERS who share the account pertaining to the opportunity. Ownership of the opportunity will have to change to the person who owns the account.

 

Accounts can be shared by 3 persons - one owner and 2 shared users.

The owner of an Opportunity has a  custom field that represents his unique code. For example SLS=AT1. All 3 users who share an account have custom fields both in Accounts that represent their personal unique identification codes - SLS1, SLS2 and SLS3, where SLS1=account owner's code.

For example SLS1=ABF, SLS2=GHT, SLS3=AT1

 

Basically, the logic has to say the following:

If Opportunity field SLS does not match any of the account fields SLS1, SLS2 and SLS3, update opportunity owner with the current account owner.

Is that possible and how? I gues trigger, but how should it look like?

  • February 04, 2013
  • Like
  • 0