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
NPrasadNPrasad 

Need Sample Web Application

Hi All,

 

I am new to salesforce platform. I know basic concepts of Apex and VisualForce. I practiced Blog application (http://www.forcetree.com/2009/08/building-blog-applicationwebsite-using.html).

 

I am interested to learn session concepts and advanced concepts.

 

Could you please suggest me some sample webapplications from scratch like registration page and login page.

 

Thanks & Regards,

Gangadhar

Best Answer chosen by Admin (Salesforce Developers) 
priyanka.mv26priyanka.mv26

You are getting the error since you cannot query the encrypted field in Salesforce

 

Modify the query as select name,password__c from users__c where name=:userName 

 

and perform the login password check using if condition like

 

if(password__c ==  password )

then redirect

else

throw error

 

 

All Answers

JitendraJitendra

Hi Gangadhar,

 

Please go through this series of tutorial on Salesforce.

http://shivasoft.in/blog/webtech/salesforce/step-by-step-salesforce-tutorial-creating-custom-object-1-of-n/

 

priyanka.mv26priyanka.mv26

Use the link http://wiki.developerforce.com/page/Documentation

 

Here you can find list of workbooks which has exercises provided by Salesforce itself.

Hope it helps..

NPrasadNPrasad

I created a simple login form for learning but not able to complete it. I need your help to complete.

 

My idea is to create a login page and redirect to another page after login and display username in that page. .

 

I have followed below steps for creating a login form...

1. Created a 'Users' (API Name: users__c) object with the following fields 1) User Name (API Name: Name),  2) Password (API Name: password__c) and 3) Email (API Name: email__c)

 

2. Apex -- Login Page

 

public with sharing class SA_User_Login {

    public String userName {get;set;}
    public String password {get;set;}
    public String status{get;set;}
    Cookie cookieUname;
    public users__c objUser {get; set;}   
   
    public SA_User_Login() {
        objUser = new users__c();
    }
    public PageReference doLogin() {
        objUser = [select name from users__c where name=:userName and password__c=:password];
        cookieUname = new Cookie('cookieUname',objUser.name,null,-1,false);
        if(objUser.name !='' )
            return (new pagereference('/apex/SA_User_home').setredirect(true));
        else {
            status = 'Invalid Login Details';
        }
        ApexPages.currentPage().setCookies(new Cookie[]{cookieUname});
        return null;   
    }   
}

 

Apex -- After Login Page

 

public with sharing class SA_User_Home {

    public String getUserName() {
        Cookie uname= ApexPages.currentPage().getCookies().get('cookieUname');
        if(uname == null) {
            return '0';
        }
        return uname.getValue();
    }
}

 

I am getting this error

Error: SA_User_Login Compile Error: field 'password__c' can not be filtered in query call at line 13 column 19

 

Could you please help me how to fix it.

 

1) How to use cookies in sales force? My username is not displaying in second page.. It is displaying zero value instead of username.

2) How to get result count.. I tried (objUser.size or objUser.count) but it is displaying error. So, I am using this condition if(objUser.name !='' ) for redirecting to another page

 

Thanks in advance.

 

priyanka.mv26priyanka.mv26

You are getting the error since you cannot query the encrypted field in Salesforce

 

Modify the query as select name,password__c from users__c where name=:userName 

 

and perform the login password check using if condition like

 

if(password__c ==  password )

then redirect

else

throw error

 

 

This was selected as the best answer
NPrasadNPrasad

Thank you Priyanka.

 

Please help me on..

 

1) How to use cookies in sales force? My username is not displaying in second page.. It is displaying zero value instead of username.

2) How to get result count.. I tried (objUser.size or objUser.count) but it is displaying error. So, I am using this condition if(objUser.name !='' ) for redirecting to another page

priyanka.mv26priyanka.mv26

Use the below class to set the cookie in your browser..

 

public with Sharing class SetCookieClass
{

public CookieClass c{get; set;}

public string browserType{get; set;}

public SetCookieClass(String cookiee)
{
CheckLogin(cookiee);
}
public void CheckLogin(String cookiee)
{
c = new CookieClass(cookiee);
}

public class CookieClass
{
public String Username {get; set;}
public CookieClass(string SessionId)
{
Username = SessionId;
setCookieInfo();
}

public void setCookieInfo()
{

Cookie Username = new Cookie('Username',Username,null,-1,false);

//Set the page cookies using the setCookies() method
ApexPages.currentPage().setCookies(new Cookie[]{Username});
}
}
}

 

Invoke this class as given below which sets the cookie username to your browser

SetCookieClass sc = new SetCookieClass(username);

 

for the point 2..

Modify the code as List<User> objUser = [select name from users__c where name=:userName ];

Now try the function objUser.size(), it will work.. 

It was throwing error previously because you are retrieving the record in single user instance so we cannot use the size function..

 

If you use list<User> then it will support size function..

 

For further questions, pleae don't hesitate to ask.. The questions and solutions provided may help others..

 

NPrasadNPrasad

Thank You Priyanka.

 

I am curious about, why are using wrapper classes for setting cookies?

 

Why can't we use directly...

 

for setting cookie..

Cookie Username = new Cookie('Username',Username,null,-1,false);

ApexPages.currentPage().setCookies(new Cookie[]{Username});

 

for retrieving

 Cookie uname= ApexPages.currentPage().getCookies().get('cookieUname');

 

priyanka.mv26priyanka.mv26

Yeah we can use.. I was using the code for my development purpose.. I just send you the code.. I was doing some logics in cookie class and then setting cookies.. And I have to use the code in many places thats why I did so...

NPrasadNPrasad

Than You Priyanka...

 

I have successfully completed my login page... My first step is completed.. I will keep on developing other pages and ask more questions...:)

 

Below is my logic.. It will helpful to others...

 

Login Page

 

public with sharing class SA_User_Login {

    public String userName {get;set;}
    public String password {get;set;}
    public String status{get;set;}
    Cookie cookieUname;
    public List<users__c> lstUser = new  List<users__c>();   
  
    public PageReference doLogin() {
        lstUser = [select name,password__c from users__c where name=:userName];
       
        if(lstUser.size() > 0 && lstUser[0].password__c == password )
        {
            cookieUname = new Cookie('cookieUname',lstUser[0].name,null,-1,false);
            ApexPages.currentPage().setCookies(new Cookie[]{cookieUname});
            return (new pagereference('/apex/SA_User_home').setredirect(true));
        }
        else
        {
            status = 'Invalid Login Details.... Please try again!';
        }
        return null;   
    }   
}

 

After Login Page

 

public with sharing class SA_User_Home {

    public String getuserName() {
        Cookie uname= ApexPages.currentPage().getCookies().get('cookieUname');
        if(uname == null) {
            return '0';
        }
        return uname.getValue();
    }
}