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
abinayaabinaya 

App Name in Apex Controller

Hi,

 

I need the App name in my Controller class. I got the App name in my visualforce page by using the below javascript:

 

var myappname = document.getElementById("tsidLabel").innerText;

 

But i want the app name in my controller class to check for the currently selected app.

 

Can any one help me out?

SimonJaiSimonJai

You can use param to pass values back to the controller.

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_param.htm

kiranmutturukiranmutturu
do u required the value in the page load or do u have an specific action call associated with this?
abinayaabinaya

I need it on the page load.. I am not going to do any action so i cannot use my action function..

kiranmutturukiranmutturu

u can make use of actionfunction even in page load also, but its a big work around.. apart from that make use of visualforce remoting

some think like this


<script>
var myappname = document.getElementById("tsidLabel").innerText;

Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.Appname.getAppname}',
myappname,
function(result, event){
if (event.status) {


} else if (event.type === 'exception') {
document.getElementById("responseErrors").innerHTML =
event.message + "<br/>\n<pre>" + event.where + "</pre>";
} else {
document.getElementById("responseErrors").innerHTML = event.message;
}
},
{escape: true}
);

&lt;/script&gt;


class:

global with sharing class Appname {


@RemoteAction
global static string getAppname(String appName) {
system.debug('app name'+appname);
return null;
}
}

check the debug whether u are able to get the value in to class or not...

abinayaabinaya

This is my Visual Force Page:

 

<apex:page controller="LoginRedirect"  action="{!Redirect}">
</apex:page>

 

This is my Controller Class :

 

public class LoginRedirect

{

      public PageReference redirect() {
        try
        {
            Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
            Map<String,String> prefixKeyMap = new Map<String,String>{};
            for(String sObj : gd.keySet())
            {
                Schema.DescribeSObjectResult r =  gd.get(sObj).getDescribe();
                prefixKeyMap.put(r.getName(), r.getKeyPrefix());
            }             

            Id roleid= UserInfo.getUserRoleId();            
            system.debug('Roleid:' +roleid);

            UserRole lstRoles = [Select Name from UserRole where id = :roleid];
   

        if(lstRoles != null)
            {               
                    system.debug('Role:' +lstRoles );            
                    if(lstRoles.Name == 'Management Representative')
                    {   
                        String ReqPrefix = prefixKeyMap.get('Requirement__c');
                        PageReference redirectPage = new PageReference('/' +ReqPrefix + '/o');
                        redirectPage.setRedirect(true);
                        return redirectPage;              
                    }
                    else if((lstRoles.Name == 'Lead Recruiter') || (lstRoles.Name == 'Recruiter'))
                    {  
                        String AsgnReqPrefix = prefixKeyMap.get('RequirementAssignment__c');   
                        PageReference redirectPage = new PageReference('/' + AsgnReqPrefix + '/o');
                        redirectPage.setRedirect(true);
                        return redirectPage;                                       
                    }
                    else
                    {
                         PageReference redirectPage = new PageReference('/home/home.jsp');
                        redirectPage.setRedirect(true);
                        return redirectPage;             
                    }
            }
            else
            {
               return null;
            }
        }
       catch(Exception e)
        {
           System.debug('An exception occurred: ' + e.getMessage());
        }
    return null;      
    }

}

 

 

In my Controller class i need to check for the app name before before checking the role name... This is my task... Am breaking my heads for past 3 days... Help me out..