Skip to main content Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.
buggs sfdc (BLSOFT) 님이 #Apex에 질문했습니다
HI All,

i have a custom table(Social_media__C) which doesn’t have any relationship with opportunity,And i have another custom table partner__c which is related to opportunity,now when first record(on partner__c table) is created related to a opportunity,that first partner__c one of the field value we need to update into Social_media__c’s one of the field.how can we do this?

            first.Created.partner__c.value = Social_media__c.value(no lookup to opportunity)
답변 4개
  1. 2017년 2월 20일 오전 11:45
    Please use below code snippet and let me know, If it works :)

     

    trigger SocialMediaTrigger on Social_media__c(before insert,before update)

      {

        

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

     Map<Id,Partner__c> mp_Partner;

        

    for(Social_media__c socialMediaRecd : Trigger.new)

      {

         st_oppId.add(socialMediaRecd.Opportunity__c);

      }

      

      for(Partner__c partnerRecd : [Select Id,Opportunity__c,PopulateValuetoSocialMedia from Partner__c where Opportunity IN  : st_oppId])

        {

      if(mp_Partner==null)

          mp_Partner = new Map<Id,Partner__c>();

      

      mp_Partner.put(partnerRecd.Opportunity__c,partnerRecd);

    }

      

    for(Social_media__c socialMediaRecd : Trigger.new)

       {

       

         if(mp_partner!=null && mp_partner.containsKey(socialMediaRecd.Opportunity))

             socialMediaRecd.Field = mp_partner.get(socialMediaRecd.Opportunity__c).PopulateValuetoSocialMedia;

       

       }

    }

    Here Field represent the field of social media, which u will populate from partner field.

    PopulateValuetoSocialMedia represent the field of partner, which you want to update.

    Thanks

     
  2. 2017년 2월 19일 오후 5:57
    Hello,

    Thank you for the response,as i said there is no relationship between Social_media__c and partner__c,so if i create lookup on Social_media__c to opportunity,then if i write a trigger on it,that may solve my problem?

    if that is the case,then i will a create lookup to opportunity,but i have a dought will that lookup is really helpful to search the previous opportunitys related partner__c's records even,And also i need to find the first created record on the partner__c , that value i have to update on Social_media__c's field,also please provide any sample code snippet for the trigger.
  3. 2017년 2월 19일 오전 11:21
    Hello Sonam,

    Is there any relationship between Social_media__c and partner__c Object If yes, Then you can simply write a trigger as Suraj said. If no then how can you ditermine that which Partner object need to update.

    Let me know if this helps :)

    Thanks!

    Amit Singh
  4. 2017년 2월 19일 오전 10:15
    You can create a trigger on  the  partner__c object, that trigger will fire when you create the record on the partner___c then accordingly you can update the Social_media__c object with your required values.
0/9000