+ Start a Discussion
DhairyaDhairya 

Recoed Owner Change

Hi,

 

  In our application we are populationg one custom object  from the webstore using api. Hence, all inserted records have same record owner but for the reporting purpose i need Account Owner name as the custome object owner name. We have two common fields. 

 

  How to resolve the issue?

 

   Appreciate your help.

 

Thanks,

Dhairya

VPrakashVPrakash

Does Account and custom object have a relation, If so you can write a before insert trigger on the custom object to update the owner field.

Shashikant SharmaShashikant Sharma

As you inserting date from sites so all records will have same owner thats the site guest user. If ayou want to have some different owner name then you have to write a trigger on before insert  of records , where if the ownerid is guest user's id  then replace it with the ownerid you want. Now in this case if you will replace it with any particular owner then it will be only single owner. So I would suggest to assign owner id in trigger based on some input that user provides on site register page.

DhairyaDhairya

Thanks for your replies.

 

(1) I do not have any relation between Account and Custom Obj.

 

(2) I tried to use before insert trigger but it failed.

 

Thanks,

Dhairya

DhairyaDhairya

Shashikant thanks for your reply,

 

      webstore data populated into SFDC via API. So, here all inserted records have single owner. I want Account owner as a recoed owner based on one common field between both Account and custom object. I do not know how to write trigger for that.

 

thanks,

Dhairya

Shashikant SharmaShashikant Sharma

Could you please provide your trigger code and the exception that you got.

DhairyaDhairya

Hi Shashikant,

 

      Sorry, last few months enggaged in other work and missed this piece for a long time.

 

      Here is a trigger (daily usage object populated from the webstore and record owner name remain same for all records bcoz inserted using WSDL)

 

 

trigger dailyUsageOwnerChange on Daily_Usage__c (before insert) {

 Daily_Usage__c[] du = trigger.new;
 
 DailyUsageOwnerChange.ownerRecord(du);
 }

 

Class :

Now, we have to change record owner name as per account owner. (Daily Usage Name is always one of the Account name)

     

 
public class DailyUsageOwnerChange{


    public static void ownerRecord(List<Daily_Usage__c> du)
    {
         for(Integer i=0; i < du.size() ;i++)
         {
            Account a = [select OwnerId from account where Account_External_ID__c like :du[i].Oracle_Account_Number__c limit 1];
            du[i].Owner__c = a.ownerId;
         
         }
    
        insert du;
    }




}

 

I really appreciate your help. 

 

regards,

Dhairya