Please use below code snippet and let me know, If it works :)
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.Thankstrigger 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;
}
}
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. 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 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.
답변 4개