I have an object called position__c and skill_profile__c. I have a juntion object - position_skill_set__c , which is a junction object between postion__c and skill_profile__c. The junction object appears as a related list on position__c. I am trying to get the name of the juntion object like - position_skill_set__c.Name. here is my trigger:

trigger CopySkillsToProject on Position__c (after update) {

    for (Position__c position: Trigger.new) {

        System.debug('Position is -' + position.Name + ' ' + position.Postion__r.);


I am creating this trigger to perform some operation when the position is updated( which I have not implemented yet) , before that I want to access the junction object name inside the trigger. How can I achieve that?


Unless you query for the related objects, the trigger won't have any values for related objects. So, you'll need to do something like this:

trigger CopySkillsToProject on Position__c (after update) {

   map<ID,Position__c> posIdToPositionMap = new map<ID,Position> (
                           [select id, 
                               (select id, name from Position_skill_sets__r)
                               from Position__c where id IN :Trigger.new]);

   for (Position__c p : Trigger.new)
       for (Position_Skill_Set__c pss : posIdToPositionMap.get(p.id).position_skill_sets__r)
           system.debug(pss.name);  // name of the jth PSR on the ith Position
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.