Get Object from ID in VisualForce rerendered page - salesforce

I am working with visualforce. Is there a way to get the fieldname from the id in the rerendered section of the visualforce page.
{!$CurrentPage.parameters.cid} gives me the id. Suppose that cid has the id of the contact object. How can i display certain fields of the contact object in the outputpanel. I tried the but it gave whole detail. I only want certain fields.

Hope you are referencing this documentation in your work. $CurrentPage.parameters.parameter_name is a way of getting query string parameters in Visuaforce and there is nothing to do with that for altering the fields you need in the Contact section.
If you are using <apex:detail /> for the Contact section, what you can do is update your Contact object detail page layout as you need.

Related

How to retrieve parent object field values in SOQL to display in VF Page

I am new to SFDC, struggling to retreive parent objects fields through SOQL query on child object.
I have two objects namely Opportunity and Scope where Scope has a lookup to Opportunity.
Here is the query i have written in Controller.
ScopeController.cls:
List<Scope> scopeList=[Select id,Name,ScopeValue__c,Opportunity__c,Opportunity__r.opAmount__c from Scope__c];
System.debug('scopeList : '+scopeList);
Accessing the values of scopeList in below VF Page.
ScopePage:
<apex:repeat value="{!scopeList}" var="s">
<tr>
<td>{!s.Name}</td>
<td>{!s.ScopeValue__c}</td>
<td>{!s.Opportunity__c}</td>
<td>{!s.Opportunity__r.opAmount__c}</td>
</tr>
</apex:repeat>
But in the above VF Page not able to show the value of s.Opportunity__r.opAmount__c, it is empty. I debugged in Controller, the SOQL query itself not retrieving the value of "Opportunity__r.opAmount__c" hence shown empty in VF Page.
One reason could be that your profile does not have access to this field (Opportunity__r.opAmount__c).
Query looks fine to me. Do you see this value on the standard layout. Does your profile have access to this field?
From the management settings for the field’s object, go to the fields area.
Select the field you want to modify.
Click View Field Accessibility.

How to display page for testing component with sObject?

I'm new to Salesforce/Apex and I need to be able to test a component I am working on in a separate page.
Here is the scenario. I have the following test page:
<apex:page sidebar="false" showHeader="false" standardController="Contact">
<div id="wrapper" style="max-width:980px;">
<c:djEmailTemplate_MainComponent sObject="{!Contact}" theContactId="{!Contact.Id}"/>
</div>
</apex:page>
I can display the page by adding /apex/testpage to the url after the project name.
What I don't know how to do is to include data to satisfy the parameters (sObject, theContactId) that are needed to populate values in the component.
Can anyone explain how I can do this?
Thanks in advance.
Your test page uses the Contact object as its standard controller, so in most cases you would want to specify a Contact record for the page/controller to operate on. You can use any existing Contact record in your org, or create a new one (specifically you'll want to grab the ID of the record) and then append the ID to the URL you're using like so: /apex/testpage?id=003xxxxxxxxxxxx. This will provide the page and controller a record to pass to the VF component.

QuickSearch on a details page not keeping id when refreshing

I have a Grid for which I have a column formatted to a link. Once I click on a link that is being generated, this link will take me to a page for which the url looks like ?page=details&id=10. This works fine, so far.
On this details page I have another grid which displays child records, by adding the condition to the model of the grid addCondition("parent_id", "=", $_GET["id"]). This works well as well, my child records are being displayed based on the master record id that is being passed.
Now if I add a quickSearch on the grid from the details page, once I try to search, the id is not being passed in the url, so now my condition will be addCondition("parent_id", "=", null) because $_GET["id"] is null. The url that is being generated for the refresh is ?page=details&submit=agile_details_mvcgrid_quicksearch.
So the grid will display no results.
How can I fix this? I could put the value in the session, but it's really a good solution.
Please add the following at the top of your page:
$this->api->stickyGET('id');
This will preserve value of $_GET['id'] form that point on.

Can we have links of related lists in a VF page

I have a VF page in which i have related lists displayed using
<apex:relatedList list="NOTESANDATTACHMENTS"/>
Is there a way i can have the link of the related list on the top of the page like the ones in standard page? The reason for this is that my VF page is pretty long and the user needs to scroll to get the view the notes and attachment list.
is there any way we can achieve this?
Thanks
Not directly, but you can always use anchor links.
Go to related list
...
<a id="mylist" />
<apex:relatedList list="NOTESANDATTACHMENTS"/>
The relationship name for the Notes and Attachments related list has been changed in winter 14 release.
you can show the attachement in the relatedlist tag.
apex:relatedList list="CombinedAttachments" subject="{!$CurrentPage.parameters.id}"
in the VF page if you are using Standard controller then there is no need to add subject attribute.

Django-taggit: how to search for all tags based on another column or foreign key?

The django-taggit example shows how to get all tags for one specific model, and I know there is a way to get all tags in the system, but how do I get all tags based on a foreign-key?
I have tags for the Event model, and there is a primary-key/foreign-key relationship between the EventOrganizer and Event. Each EventOrganizer will have different set of tags, and when he/she logs in, I only want to show the tags that this organizer is concerned about.
Thanks!
Assuming your Event model looks something like this:
class Event(models.Model):
organizer = models.ForeignKey(EventOrganizer)
tags = TaggableManager(blank=True)
# ...
You can filter tags by event.organizer:
from taggit.models import Tag
tags = Tag.objects.filter(event__organizer=organizer)

Resources