How to Display Wrapper Class Variable in Apex Controller - salesforce

Find the link and provide me the solution for that.
I could paste the code here directly,so fine the link
click here to view the code

for(Restaurantwrapper.cls_nearby_restaurants nearby_restaurant : Restaurantwrapper.nearby_restaurants){
String name = nearby_restaurant.restaurant.name;
}

Related

Where to Place Navigation in Joomla Component Development

I am developing a component 'com_datamanager' with an "Admin Dashboard" using ElaAdmin HTML5 Admin Dashboard Template. I have been able to create a simple component with multiple views without the dashboard template and it works.
But now I am stuck at how to add the 'dashboard theme' and which section whether in the view.html.php or tmpl/default to place all the "sidebar navigation"
The navigation will hold a link to all the various views of the component such as create, edit, delete, messages, product details, product list etc and it must also appear on all the above mentioned views.
I will be glad if someone can help me. thank you
Follow below steps
Create helper file of component if you it is not already there and paste below code in your helper file of component. If file is already there only past function part.
class MyComponentHelper
{
public static function addSubmenu($vName = "")
{
JHtmlSidebar::addEntry(
JText::_('Product List'),
'index.php?option=com_mycomponent&view=products',
$vName == 'products'
);
JHtmlSidebar::addEntry(
JText::_('Product'),
'index.php?option=com_mycomponent&view=product',
$vName == 'product'
);
}
}
Now go to yours views/dashboard's view.html.php file and paste below code before the display method call.
MyComponentHelper::addSubmenu('products');
Same code snippet will go in the product view also just change the view
Let me know if you face difficulties in this. It would be more help full if you post components file structure here.

How to set default mentions using ui-mention angularjs library?

Any ideas on how to set default mentions using ui-mention angularjs library (https://github.com/angular-ui/ui-mention)? For example, in the text area always have two default mentions (bob baker and Kenny Logins) as in the attached picture
Thanks for your helps, folks.
By adding some users mentions you will see at the bottom the model related:
ng-model (post.message): "hi there #[bob barker:11123]"
so for your example, initializing it is like:
$rootScope.post = {
message: "hi there #[bob barker:11123] #[kenny logins:123ab-123]"
};
But you will notice that it doesn't work.
After taking a look in the code it will work if you are able to add theses users in $mention.mentions and because $mention is the controllerAs in the uiMention directive, you are able to set it in the custom directive (mentionExample in the example) by uiMention.mentions.
So by adding:
uiMentions.mentions = uiMention.mentions.push(choices[0]); //bob barker
uiMentions.mentions = uiMention.mentions.push(choices[1]); //kenny logins
in the function link in the mentionExample, this would work.
But I think you should make it dynamically (in this link function) by searching in $scope.post.message all #mentions and then adding the relating user item in uiMentions.mentions.
Take a look on this plunker I created for you: http://embed.plnkr.co/o3mByKttPthpiqe4O5x6/

Salesforce - passing a string from one class to another! - APEX

Hello,
I have a issue at the moment and I am not able to solve it.
Problem: I have 2 classes at the moment for example class A and Class B. Inside class A I have a for loop running on Accounts.
Class A{
for(Account t: listAccounts){
String abc = t.Name;
String URL = 'http://testURL.com/test?q1='+t.id+'&q2='+t.Name.......till q50';
}
}
So everytime this for loop runs on an account, it generates a new URL. I want a way to pass this URL from the for loop to another class which displays it on a VF page. So, the class B is the controller of the VF page.
The URL is going to be more than 500 characters long so its not possible to pass it as a custom setting and retrive it on the other controller.
Class B{
public String getURL(){
//Somehow fetch that URL everytime the loop runs
return URL;
}
}
Now, the VF page will call this controller class B to retrieve the URL and display it as a output link.
What I have tried: I have tried to use getters and setters but it did not work. Why? because the VF page strictly calls a getURL() method with no parameters.
I also tried to save it in a custom setting but since the length is so long it would not be possible!
Please help. Any kinds of helps will be much appreciated!
Did you try global static variable?
You could create a static method on Class A to return the URL for a given Account object.
Then Class B can look up the Id of the current account on the Visualforce page:
Id id = ApexPages.currentPage().getParameters().get('id');
And pass that Id to the static method of Class A to get the URL for that Account.
This works for a Visualforce page that shows the detail for an Account, but wouldn't work for a list of Accounts.
Thanks guys for the help but the only way out I could find is saving it on a custom object which has a look up on Account and then doing a SOQL to get it in the Class B.
Thanks for the help guys!

Custom Button or Link to a Visualforce page with a custom controller

I have a Visualforce page using a custom controller that is used to edit multiple records under an opportunity.
I'd like to create a custom button or link from Opportunities to this Visualforce page.
Currently the link looks like:
/apex/ExamplePage?oppId={!Opportunity.Id}
This works fine in the development sandbox, but when it is deployed as part of a managed package the link breaks as the page reference doesn't have the namespace prefix.
I found the post Managed Package Redirecting Problem on the Force.com Discussion Boards which implied it should be possible to use $Page to reference the Visualforce page in the URL. E.g.
{!URLFOR($Page.MyExamplePage,'',[objectId = campaign.id])}
But doing so only gives me the syntax error:
Error: Field $Page.MyExamplePage does not exist. Check spelling.
There is another part to the post that suggests using an Apex class and Execute Javascript to work around it. But it appears to me that this has just moved the namespace issue into the Javascript.
How can I safely reference the Visualforce page to work both inside and outside a managed package?
Best to do this from an Apex PageReference return value. Something like this will work:
public PageReference returnPage()
{
return Page.MyExamplePage;
}
Then call this from Visualforce:
<apex:commandButton value="Go To New Page" action="{!returnPage}"/>
The Apex Page call will handle the translation for you.
[EDIT]
Create a bare bones Visualforce page like this:
<apex:page standardController="Opportunity" extensions="TheController" action="{!returnPage}"/>
Add the above returnPage() method to a new TheController (or whatever) class. It doesn't even need a constructor. The class can look like this:
public TheController
{
public PageReference returnPage()
{
return Page.MyExamplePage;
}
}
Then from the Opportunity settings page go to Buttons and Links and create a new custom Visualforce button selecting the new page you just created.
That should do it.
It occurred to me that one less than ideal option would be to create two custom buttons in each case. One with the managed package namespace and one without.
When building the package the correct custom button could be selected.
One issue with this approach is the need to maintain two custom buttons.
It seems the answer is simply /apex/package__Page as provided here by #zachelrath. I can confirm this works in managed packages in production orgs as well as in development.
The post on the developer boards that you've linked to shows the following javascript being used for the button:
{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}
var pageUrl = sforce.apex.execute("mynamespace.PageUrl", "getPageUrl", {objectId:"{!Campaign.Id}"});
window.location.href = pageUrl;
i.e. they're using javascript to call a webservice method in the class they've defined in order to get the page reference. Doing this would allow you to get the URL of the page in apex, where the managed package won't play an impacting part.
That said, the first parameter is the fully-qualified class name, so you could probably check the return value for an error (I don't know the error return value, so I'm assuming it's null here):
// try the namespace first
var pageUrl = sforce.apex.execute("mynamespace.myClass", "getPageUrl", {objectId:"{!Campaign.Id}"});
if (pageUrl == null)
{
pageUrl = sforce.apex.execute("myClass", "getPageUrl", {objectId:"{!Campaign.Id}"});
}
window.location.href = pageUrl;
Obviously you need to check what happens when sforce.apex.execute() fails, and you'll likely want some more error handling.

Salesforce: Launch S-Control in a new window from VisualForce

I'm writing a VisualForce page to replace an old legacy S-Control.
Originally the Custom S-Control was launched from a Custom Button, and it opened in a new browser window (The S-Control is type HTML, and the Custom Button has Behavior: Display in new window)
For certain old records, I want to do a similar thing from VisualForce.
So: Do HTML S-Controls have a URL that I can launch using a link? In which case, how do I figure out the URL?
Or:
Is there a way of embedding 'Custom Buttons' (that is, the buttons defined in "Setup->Customise->Account->Buttons and Links") into VisualForce pages? If so, I can embed the existing button that knows how to open the S-Control
Or:
Can you suggest some other way of doing this? Key features: Open an S-Control in a new window from VisualForce.
Thanks
Got an answer from this forum post courtesy of aballard:
Basically, the !Urlfor() function can be used to get the URL of an S-Control. So, you can use an outputLink like this:
<apex:outputLink value="{!UrlFor($SControl.my_scontrol_name)}"
target="_blank">Show SControl</apex:outputLink>
If you need to pass an object ID to the S-Control, you can add a second parameter that calls a propery on the custom controller, e.g:
<apex:outputLink value="{!UrlFor($SControl.my_scontrol_name, AccountID)}"
target="_blank">Show SControl</apex:outputLink>
... where AccountID is defined on the custom controller as public string getAccountID()
See also this blog post at SalesforceSource for more info on the UrlFor function.

Resources