We are not going to renew a Partner portal license. So Every Opportunity ( closed won and others) which is on this license user name has to be transferred to Admin. I tried to do it from developer console (simple coding). Debug shows exactly what I want to happen. I do not know why owner is still the previous one. Yes I have child object on Opportunity and they are also getting executed but still no trigger or class changes the owner. Here is the code I tried

   list<Opportunity> tempOpp = new list<Opportunity>();
   list<Opportunity> tempSamOpp = [SELECT id, ownerId,user__c,stageName,Partner_Portal__c,BDE_Description__c
                                    from Opportunity
                                    where ownerId = '00590000000nv63'
                    limit 10];

  system.debug('--list size--'+ tempSamOpp.size()+'--list contain--'+tempSamOpp);

  id uAdmin = [SELECT id, name from User where Name = 'Balamurugan Nadar'].id;
  system.debug('--User Admin ID-' + uAdmin);
  id uSam = [SELECT id, name from User where Name = 'Sam T'].id;
  system.debug('--User Sam ID-' + uSam);

  for(Opportunity tempAdminOpp : tempSamOpp){
      system.debug('--OwnerId- '+ tempAdminOpp.OwnerId);
      if(tempAdminOpp.ownerID == uSam){
         system.debug('-is it coming here-');
         tempAdminOpp.ownerID = uAdmin;
         tempAdminOpp.User__c = uAdmin;
        tempAdminOpp.Partner_Portal__c = null;
       //tempAdminOpp.BDE_Description__c = 'It was Sam\' Opportunity';
     system.debug('-OwnerId Admin-' + tempAdminOpp.ownerId +'-User Admin-' +  tempAdminOpp.User__c);
  system.debug('--tempOpp size--'+ tempOpp.size()+'--tempOpp contains-'+ tempOpp);  
  update tempOpp;

I tried using system.assert(false); to stop execution after update , still other code gets execute. There are more than 700 records of this user.

  • 1
    Export all the opportunity records using data loader and then see the opportunity owner name in excel. Some times developer console doesn't show correct values. I have experienced this thing. May 9, 2014 at 6:14
  • 1
    Can you enable field history tracking on the Owner field? This way you'll see if the one transaction attempts to change the Owner to one value and then it flips back. If you see this you have some trigger or workflow that sets the owner field. May 9, 2014 at 7:05
  • JLiljegren I will try it and let you know. I tried on Opportunities which are closed won and which are not. Then Opportunity which is Closed won is not having any effect but other Opportunity's owner gets change. So what should I do to change the owner of closed won opportunity, is there some other method to change it.
    – Rohit
    May 9, 2014 at 7:14
  • Everything has been sorted out. Now some 65 records has been left for owner to be changed. Thanks to everyone who took out time to reply.
    – Rohit
    May 9, 2014 at 9:43

1 Answer 1



Opportunity[] opportunities = [SELECT /** required Fields **/ 
                               FROM Opportunty 
                               WHERE Owner.Name = /** owner Name **/
                               LIMIT 1];
for(Opportunity opp : opportunities ){
    opp.OwnerId = /** here wanted Id **/

update opportunities;

This have to work. If it is still remain old owner then the issue is not your action from developer console but probably some triggered logic.

  • Please look at my last comment above and reply if you have any solution.
    – Rohit
    May 9, 2014 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .