function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MohaMoha 

Retreive a Junction Object record on a visualforce page

Hello, i need some help, i have a Junction OBject  called RelatedEvent it's related to Contact object and Event__c Object, i need to create an apex class and visual force Page to retreive record detail in my customer portal view, my problem is when i pass a static id of a precised record it retreives details, but i don't know to select the right Id dynamically to show me the details, if anyone have an idea i will send him my Class to help me

thanks,

Best Answer chosen by Admin (Salesforce Developers) 
MohaMoha

Hello, This is My Code : 

 

public MyParticipation() {


contact = new Contact();


user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, Company__c, contact.email
FROM User
WHERE id = :UserInfo.getUserId()];



contact.id = user.contactId; ==>this retrieve the ID of the current User for my cusomer portal ID that exist in the URL

System.debug('the contact is : *********************' + contact.id);


relate = new Related_Events_and_reports__c();
relate.Related_Contact__c = contact.id; ==>Here to associate the current contact to my JunctionOBject then i can select the right Record of the junction object

System.debug('le contact de participation est : ****************' +relate.Related_Contact__c);
System.debug('la participation est : ****************' +relate.name);

 

// my problem is here when pass an id statisuqe like name ='111' it's the record id in the JunctionOBject Table it works fine and retreives the details, but if i use "where Related_Contact__c =: relate.Related_Contact__c" as exemple it tells me that there is no rows for the assignement Object :
related = [Select id, Event__c, Related_Contact__c, Yes__c, No__c FROM Related_Events_and_reports__c
where name = '111'];

System.debug('the participation is *********************' +related);

 

Any Help please :)

 

 

 

 

 

 

 

 

 

 

 

All Answers

sushant sussushant sus
just post ur code so every one can help you
MohaMoha

Hello, This is My Code : 

 

public MyParticipation() {


contact = new Contact();


user = [SELECT id, email, username, usertype, communitynickname, timezonesidkey, languagelocalekey, firstname, lastname, phone, title,
street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax, Company__c, contact.email
FROM User
WHERE id = :UserInfo.getUserId()];



contact.id = user.contactId; ==>this retrieve the ID of the current User for my cusomer portal ID that exist in the URL

System.debug('the contact is : *********************' + contact.id);


relate = new Related_Events_and_reports__c();
relate.Related_Contact__c = contact.id; ==>Here to associate the current contact to my JunctionOBject then i can select the right Record of the junction object

System.debug('le contact de participation est : ****************' +relate.Related_Contact__c);
System.debug('la participation est : ****************' +relate.name);

 

// my problem is here when pass an id statisuqe like name ='111' it's the record id in the JunctionOBject Table it works fine and retreives the details, but if i use "where Related_Contact__c =: relate.Related_Contact__c" as exemple it tells me that there is no rows for the assignement Object :
related = [Select id, Event__c, Related_Contact__c, Yes__c, No__c FROM Related_Events_and_reports__c
where name = '111'];

System.debug('the participation is *********************' +related);

 

Any Help please :)

 

 

 

 

 

 

 

 

 

 

 

This was selected as the best answer
AmitdAmitd

Hi Jamal,

 

I have tried the same scenario  and it works fine for me

 

Case cs = new Case();
cs = [Select c.Id, c.ContactId From Case c where c.ContactId='0039000000JUAsx' limit 1];
Contact contact = new Contact();
System.debug('**cs.contactId**='+cs.contactId);
System.debug('**contact.id**='+contact.id);
contact.id = cs.contactId;
System.debug('**contact.id**='+contact.id);
Note nots = new Note();
System.debug('**nots.ParentId**='+nots.ParentId);
nots.ParentId = contact.id;
System.debug('**nots.ParentId**='+nots.ParentId);
system.debug('**result**='+[Select n.Title, n.ParentId, n.Id From Note n where n.ParentId=: nots.ParentId]);