Skip to main content
Abhishek Khosla (Ross Video) 님이 #Apex에 질문했습니다
Hi All,

I have a custom object User Region which has a field called RSM Number and RSM__c which is the owner of that region. I want this field to be updated in Opportunity split whose Split owner is unigue and matches RSM__c . Opportunity split  is having a look up relationship with User region object. This is the tirgger I have written. But I am stuck after I have got All the USER region which have same Account region ID and RSM__C is = Split Owner ID. Because there is a ask that id Split Owner is hared between two User region then it should not update only Split owner which are not shared their RSM number should get updated through this trigger. 

Can you all please help me how to write this trigger 

Sample Code : 

Trigger RSMnumberUpdate on OpportunitySplit (before insert,before update){

if(Trigger.isbefore && (Trigger.isinsert || Trigger.isupdate)){

List<id> SplitownerID = new List<id> ();

List<String> OppAccountRegionID = new List<String>();

    For(OpportunitySplit Opsp : Trigger.new){

          SplitownerID.add(Opsp.Splitowner);

          OppAccountRegionID.add(Opsp.AccountRegionID);

}

List<ID> AllUserRegionsID = [SELECT id FROM UserRegion__c WHERE RSM__c IN : SplitownerID AND Parent_Region__c IN : OppAccountRegionID];

     

        

}

}

 
답변 3개
  1. 2019년 6월 20일 오전 6:38
    Hi Abhishek,

    Try the following code it may helpful for you:

    Trigger RSMnumberUpdate on OpportunitySplit (before insert,before update){

        if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate)){

        List<ID> SplitownerID = new List<ID> ();

        List<ID> OppAccountRegionID = new List<ID> ();

        For(OpportunitySplit Opsp : Trigger.new){

              SplitownerID.add(Opsp.Splitowner);

              OppAccountRegionID.add(Opsp.AccountRegionID);

        }

        List<ID> AllUserRegionsID=new List<ID>();

        AllUserRegionsID = [SELECT id FROM UserRegion__c WHERE RSM__c IN : SplitownerID AND Parent_Region__c IN : OppAccountRegionID];

    }

    }

        

    I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

    Thanks,

    Ajay Dubedi

     
0/9000