You need to sign in to do that
Don't have an account?
Kunal Purohit 4
How to update master object field using junction object in trigger
i have two master detail object Author__c and Research_Paper__c and one junction object Author-Research_paper__c. Junction object has lookup field Author and Research-paper.. Now i want that after selecting Author name from Lookup field, author name should be updated automatically in "Name of Author" in Research-paper__c object.
Here is my code:
trigger SampleAuthorPopulate on Author_Research_Paper__c (after insert,after update) {
set<id> setid=new set<id>();
set<id> setauthor=new set<id>();
for(Author_Research_Paper__c ar:trigger.new)
{
setid.add(ar.Research_Paper__c);
setauthor.add(ar.Author__c);
}
map<id,Research_Paper__c> rmap=new map<id,Research_Paper__c>();
for(Research_Paper__c rc:[select id,Name_of_Primary_Author__c from Research_Paper__c where id in:setid])
{
rmap.put(rc.Id, rc);
}
list<Author_c> au=[select id,name from Author__c where name in: setauthor];
list<Research_Paper__c> rlist=new list<Research_Paper__c>();
for(Author_Research_Paper__c ar:trigger.new)
{
if(rmap.containsKey(ar.Research_Paper__c))
{
if(ar.Is_Primary_Author__c==true)
{
rmap.get(ar.Research_Paper__c).Name_of_Primary_Author__c=au.Name;
rlist.add(rmap.get(ar.Research_Paper__c));
}
}
}
update rlist;
}
Here is my code:
trigger SampleAuthorPopulate on Author_Research_Paper__c (after insert,after update) {
set<id> setid=new set<id>();
set<id> setauthor=new set<id>();
for(Author_Research_Paper__c ar:trigger.new)
{
setid.add(ar.Research_Paper__c);
setauthor.add(ar.Author__c);
}
map<id,Research_Paper__c> rmap=new map<id,Research_Paper__c>();
for(Research_Paper__c rc:[select id,Name_of_Primary_Author__c from Research_Paper__c where id in:setid])
{
rmap.put(rc.Id, rc);
}
list<Author_c> au=[select id,name from Author__c where name in: setauthor];
list<Research_Paper__c> rlist=new list<Research_Paper__c>();
for(Author_Research_Paper__c ar:trigger.new)
{
if(rmap.containsKey(ar.Research_Paper__c))
{
if(ar.Is_Primary_Author__c==true)
{
rmap.get(ar.Research_Paper__c).Name_of_Primary_Author__c=au.Name;
rlist.add(rmap.get(ar.Research_Paper__c));
}
}
}
update rlist;
}
Hi,
I am trying to create record on junction object when detailed obj records get created, --
Scenario -
Obj Name: venue, Field Name - PlaceID__c [Text(255)
Object Name: Time, Field Name1 - PlaceID__c[Text(255)]
Field Name2 - UniqueKey [Text(255) (External ID) ]
Name: JunctionObj1__c (Junction Object between Venue and Time) - Both Field(venue-time) M-D rel
--> I am trying to build Logic where new Venue/Time record gets creeated, it should automatically create new record on junction obj, here "PlaceID__c" is common field so I am querying based on it.
--> For Instance - when user insert record on "Venue", I need to find corrosponding record of time object based on "PlaceId" field and create new rec on Junction Obj.
I wrote some Psudo code, but its not working out, Can anyone share some sample code