• LB_DD
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hello,

I have a public Visualforce page with a Form.
This page is part of a Managed Package.

I submit the package to security review and get this reply:

«Brute Force Vulnerability
Guest site don't have logging in or email validation. Use a CAPTCHA in the process to prevent a brute force attack on the system.»

I don't want to use the Captcha, isn't a good solution to the app, need a solution on the server side.

Anyone have the same problem and found a solution to this?
Any ideia to resolve this problem?

Salesforce have the Web-to-Lead form and don't control the brute force submmiting!


Thanks and regards.

LB

  • July 27, 2012
  • Like
  • 0

Hello all,

 

I try to Upload a CSV file from a C# Winform application to a Visualforce page. I try to POST on the VF page, but can't get the file!!!

 

My VF Page:

 

<apex:page sidebar="false" showHeader="false" controller="CSVUploadCallbackCtr" action="{!init}">
      <apex:form enctype="multipart/form-data">
          <apex:sectionHeader title="Upload data from CSV file"/>
          <apex:pagemessages />
          <apex:pageBlock title="Select best option!">
            <center>
              <h2>Conteudo:</h2><br />
              <apex:inputTextarea rows="1" id="gli"/><br /><br /><h2>ou</h2><br />              
              <apex:inputFile value="{!contentFile}"  id="file" /> 
              <apex:commandButton action="{!ReadFile}" value="Upload File" id="theButton" style="width:70px;"/>              
            </center>               
          </apex:pageBlock>
      </apex:form>
</apex:page>

 

The Controller:

public with sharing class FarmaciaCSVUploadCallbackCtr {
   public string nameFile{get;set;}
    public Blob contentFile{get;set;}
    String[] filelines = new String[]{};
 
    /* Try read here, but only work for the Input TextArea, not for the CSV file */
    public Pagereference init()
    {   
        String Gli = ApexPages.currentPage().getParameters().get('gli');   
        String[] lines = Gli.split('\n');
        System.Debug('=======> init() / Gli='+Gli);
        try{
            nameFile=contentFile.toString();
        }catch(Exception ex){}

System.Debug('=======> init() / nameFile='+nameFile+' / Gli='+Gli);                 

       for (Integer i=1;i<lines.size();i++)
       {
        System.Debug('=======> init() / line='+lines[i]); 
       }
       return null;
    }

    /* FROM C# this is not executed, only when submit from Visualforce Page. */    
    public Pagereference ReadFile()
    {   
        try{
            nameFile=contentFile.toString();
            filelines = nameFile.split('\n');
        }catch(Exception ex){}
System.Debug('=======> ReadFile() / nameFile='+nameFile+' / filelines='+filelines);        
        for (Integer i=1;i<filelines.size();i++)
        {
            String[] inputvalues = new String[]{};
            inputvalues = filelines[i].split(',');
System.Debug('=======> ReadFile() / filelines='+filelines[i]); 
        }
        return null;
    }
    

}

 

On the Visualforce page, when POST from my Win App, the field "Gli" (a inputTextArea) receive the text value on the controller, but the CSV file, don't !

 

Anyone have a solution or another idea to POST csv files to a Visualforce Page?

 

Best Regards,

LB

 

  • June 21, 2012
  • Like
  • 0

Hello,

 

Have a VF page associated to a controller and want use another controller to receive @RemoteAction calls, is possible?

 

Example:

 

Visuaforce page

<apex:page standardStylesheets="false" docType="html-5.0" sidebar="false" showHeader="false" contentType="text/html" cache="true" controller="test_ControllerRA">
  <h1>Congratulations</h1>
  This is your new Page
 <hr />
 <p><a href="#" onclick="showMessage();">Press Me</a></p>
 <div id="zoneShowMsg">zone to show message</div>
 
 <script>
 function showMessage()
{
        var str = 'name=TheName&info=Info+Tag';

        document.getElementById('zoneShowMsg').innerHTML = 'Processing... please wait.';
   try{        
        test_ControllerGlobalRA.processRA(str , function(Result, event)
        {
        console.log('Result:',Result);
        console.log('event',event);
            if (event.status)
            {
                console.log('Result=',Result);                
                if(Result!= '')
                {                      
                      document.getElementById('zoneShowMsg').innerHTML = 'Information:'+Result;
                }
                else
                {
                      document.getElementById('zoneShowMsg').innerHTML = 'Problems with information:'+Result;
                }
            } 

        }, {escape:true}); 
    }catch(ex){
        document.getElementById('zoneShowMsg').innerHTML = 'ERROR:'+ex;
    }       
}
 </script>
</apex:page>

 

The VF Page Controller:

public with sharing class test_ControllerRA {

    public String getTheString(String str){
    
        String[] arrStr = str.split('&');
        String theText = 'Name: '+arrStr[0]+' / ';
        theText +='Info: '+arrStr[1]+' /// (finished)';
        
        return theText;
    }
}

 

The @RemoteAction controller:

global class test_ControllerGlobalRA{
    @RemoteAction
    global static String processRA(string Str){
        test_ControllerRA tcra = new test_ControllerRA();
        String theStr = tcra.getTheString(Str);
        return theStr;
    }
}

 

I want to use the VF page inside a iframe.

 

 

If anyone can help me, I thank.

 

Best Regards,

LB

 

  • March 07, 2012
  • Like
  • 0

Hello,

 

I want to know (I can info about this) if I can have a Visualforce page with a controller and on that page a @RemoteAction with another controller, similar to this:

 

   VISUALFORCE PAGE:

<apex:page standardStylesheets="false" docType="html-5.0" sidebar="false" showHeader="false" contentType="text/html" cache="true" controller="MyPageControllerClass">

<apex:composition template="TemplateFB">
  <head>
  </head>
<apex:form id="signUpForm">
  <input type="text" name="Id" id="Id" />
  <a href="#" onclick="javascript&colon;signUp(); return false;">Click Me</a>
  <div id="processing"></div>
</apex:form>

<script>
function signUp()
{
   var str = '';
   try{
      str = document.getElementById('Id').value;
   }catch(e){}
   MyGlobalClass.SaveId(str , function(Result, event)
   {
        console.log('Result',Result);
        console.log('event',event);
        if (event.status)
        {
          document.getElementById('processing').innerHTML = 'Information updated.';
        }else{
          document.getElementById('processing').innerHTML = 'Problem!';
        }
   }, {escape:true});
}
</script></apex:composition></apex:page>

  GLOBAL CLASS to manage @RemoteAction call:

global with sharing class MyGlobalClass {
  
    @RemoteAction
    global static String SaveId(string dataString)
    {
        String res = '';
        MyPageControllerClass myc = new MyPageControllerClass();        
        
        try
        {
           res = myc.SaveRecord(dataString);  
        }
        catch(exception e)
        {
            res = 'error';
        }

        return res;
    }
}

   And my Controller on Visualforce page (and call exist a method called by the RemoteAction):

public with sharing class MyPageControllerClass
{

  public String OneMethod(){
   String t = 'one thing';
   return t;
  }

  public String SaveRecord(){
   String t = 'success';
   return t;
  }

}

 

 

With Chrome console I saw:

 

Uncaught ReferenceError: MyGlobalClass is not defined

 

:(

 

I need to use the code inside a iFrame.

I put on the "Sites" permission, all controllers available.

 

Anyone have idea if I can use a controller for the vf page and inside use @RemoteAction with another class?

 

 

Best Regards,

LB

 

 

 

  • February 27, 2012
  • Like
  • 0

Hello,

 

I use VS2010, .NET 3.5 to create a website that connect with Salesforce. When I access the website, exist a Query to show some information, the time to show this information is a lot! about 15s to 25s, but if I call se same page the performance is better (5s).

 

In general the performance is slow (I think), can anyone have same problem and resolve?

 

I put my code here to help understand whats happen!

 

ForceConnection.cs

using System;
using System.Collections.Generic;
using System.Web;
using SalesforceCore.SFAPIenterprise;

namespace DD.Salesforce
{
    public class ForceConnection
    {
        public string SessionID { get; set; }
        public string ServerUrl { get; set; }

        public ForceConnection(string connectionString)
        {
            ForceConnectionStringBuilder connectionBuilder = 
                new ForceConnectionStringBuilder(connectionString);

            Login(connectionBuilder.Username, connectionBuilder.Password, connectionBuilder.Token);
        }

        public ForceConnection(string username, string password, string securityToken)
        {
            Login(username, password, securityToken);
        }

        private bool Login(string username, string password, string securityToken)
        {
            try
            {
                using (SforceService service = new SforceService())
                {
                    LoginResult loginResult = 
                        service.login(username, String.Concat(password, securityToken));

                    this.SessionID = loginResult.sessionId;
                    this.ServerUrl = loginResult.serverUrl;
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}

 

 

ForceConnectionStringBuilder.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using SalesforceCore.SFAPIenterprise;

namespace DD.Salesforce
{
    public class ForceConnectionStringBuilder
    {
        public string Username { get; set; }
        public string Password { get; set; }
        public string Token { get; set; }

        public string ConnectionString
        {
            get 
            { 
                return String.Format("Username={0}; Password={1}; Token={2};"); 
            }
            set 
            {
                string[] pairs = value.Split(';');

                foreach (string pair in pairs)
                {
                    if (String.IsNullOrEmpty(pair))
                        continue;

                    string[] parts = pair.Split('=');

                    if (parts.Length != 2)
                    {
                        throw new ApplicationException("Malformed connection string parameter.  The connection string should be formated list this: username=value1; password=value2; token=value3;");
                    }

                    string key = parts[0].Trim();
                    string setting = parts[1].Trim();

                    if (String.IsNullOrEmpty(key) || String.IsNullOrEmpty(setting))
                        continue;

                    switch(key.ToLower())
                    {
                        case "username":
                            Username = setting;
                            break;
                        case "password":
                            Password = setting;
                            break;
                        case "token":
                            Token = setting;
                            break;
                        default :
                            throw new ApplicationException(String.Format("Invalid parameter {0}", parts[0]));
                    }
                }
            }
        }
        
        public ForceConnectionStringBuilder()
        {

        }

        public ForceConnectionStringBuilder(string connectionString)
        {
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[connectionString];
            if (settings != null)
            {
                ConnectionString = settings.ConnectionString;
            }
            else
            {
                ConnectionString = connectionString;
            }
        }
    }
}

 

 

ApiService.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web;
using SalesforceCore.SFAPIenterprise;

namespace DD.Salesforce
{
    public class ApiService : IDisposable
    {
        public static Dictionary<Guid, List<sObject>> asyncResults;

        private SforceService salesforceService;
        const int defaultTimeout = 60000;

        public ApiService()
        {
            salesforceService = new SforceService();
            salesforceService.Timeout = defaultTimeout;
            asyncResults = new Dictionary<Guid, List<sObject>>();
        }

        public ApiService(int timeout) : this()
        {
            salesforceService.Timeout = timeout;
        }

        public List<T> Query<T>(string soql) where T : sObject, new()
        {
            List<T> returnList = new List<T>();

            SetupService();
            QueryResult results = new QueryResult();
            try
            {
                results = salesforceService.query(soql);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }

            for (int i = 0; i < results.size; i++)
            {
                T item = results.records[i] as T;

                if (item != null)
                    returnList.Add(item);
            }
            
            return returnList;
        }

        public T QuerySingle<T>(string soql) where T : sObject, new()
        {
            T returnValue = new T();

            SetupService();            

                QueryResult results = salesforceService.query(soql);

                if (results.size == 1)
                    returnValue = results.records[0] as T;
            
            return returnValue;
        }

        public Guid QueryAsync(string soql)
        {
            SetupService();
            salesforceService.queryCompleted += salesforceService_queryCompleted;
            
            Guid id = Guid.NewGuid();
            
            salesforceService.queryAsync(soql, id);

            return id;
        }

        void salesforceService_queryCompleted(object sender, queryCompletedEventArgs e)
        {
            Guid id = (Guid)e.UserState;
            List<sObject> results = e.Result.records.ToList();

            if (asyncResults.ContainsKey(id))
                asyncResults[id].AddRange(results);
            else
                asyncResults.Add((Guid)e.UserState, results);
        }

        public SaveResult[] Update(sObject[] items)
        {
            SetupService();

            return salesforceService.update(items);
        }

        public UpsertResult[] Upsert(string externalID, sObject[] items)
        {
            SetupService();

            return salesforceService.upsert(externalID, items);
        }

        public SaveResult[] Insert(sObject[] items)
        {
            SetupService();

            return salesforceService.create(items);
        }

        public DeleteResult[] Delete(string[] ids)
        {
            SetupService();

            return salesforceService.delete(ids);
        }

        public UndeleteResult[] Undelete(string[] ids)
        {
            SetupService();

            return salesforceService.undelete(ids);
        }

        private void SetupService()
        {
            ForceConnection connection = new ForceConnection("SalesforceLogin");
            salesforceService.SessionHeaderValue =
                new SessionHeader() { sessionId = connection.SessionID };
            try
            {
                salesforceService.Url = connection.ServerUrl;                
            }
            catch (Exception ex)
            {
                throw new Exception("Salesforce Authentication Fail! Please verify: Username, Password and Token.");             
            }            
        }

        public void  Dispose()
        {
            salesforceService.Dispose();
        }

        public static string ToIsoFormat(DateTime dateTime)
        {
            return dateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
        }
        public static string ToIsoDateFormat(DateTime dateTime)
        {
            return dateTime.ToString("yyyy-MM-dd");
        }
    }
}

 

myControllerTests.cs

using System;
using System.Collections.Generic;
using System.Web;
using SalesforceCore.SFAPIenterprise;
using System.Data;
using DD.Salesforce
namespace DD.Controllers
{
    /// <summary>
    /// Controller to access object on Salesforce.com
    /// </summary>
    public class ControllerTestes
    {
        public List<Teste__c> List()
        {
            string soql =
               @"Select s.Id, s.Name, s.Field1__c, s.Field2__c, s.Field3__c from Teste__c s";

            using (ApiService api = new ApiService())
            {
                List<Teste__c> Testes = api.Query<Teste__c>(soql);
                return Testes;
            }
        }

        public Teste__c Select(string id)
        {
            string soql =
               String.Format(@"Select s.Id, s.Name, s.Field1__c, s.Field2__c, s.Field3__c from Teste__c s WHERE s.Id = '{0}'", id);

            using (ApiService api = new ApiService())
            {
                Teste__c Testes = api.QuerySingle<Teste__c>(soql);

                return Testes;
            }
        }

        public SaveResult[] Add(string[] DadosTeste)
        {
            SaveResult[] result;
            Teste__c aTeste = 
                new Teste__c() { 
                    Field1__c = DadosTeste[0],
                    Field2__c = DadosTeste[1],
                    Field3__c = Convert.ToDouble(DadosTeste[2]),
                    Field3__cSpecified = true
                };
            using (ApiService api = new ApiService())
            {
                sObject[] adds = new sObject[] { aTeste };
                result = api.Insert(adds);
            }
            return result;
        }

        public DeleteResult[] Delete(string[] TesteID)
        {
            DeleteResult[] result;
            using (ApiService api = new ApiService())
            {
                result = api.Delete(TesteID);
            }
            return result;
        }
        //-- Don't know how create Async calls!!!!
        public void ListAsync()
        {
        }
    }
}

 

Default.aspx:

using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SalesforceCore.SFAPIenterprise;
using DD.Controllers;


namespace myProjectTest
{
    public partial class getData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
               string myID = "";
                try{
                   myID = Request.Params["id"].ToString();
                }catch{}
                
                myLabel.Text = getTheData(myID));

        }

        protected string getTheData(string recordid)
        {            
            string res = "";
            if (recordid.Length>0){
             ControllerTestes test = new ControllerTestes();
             Teste__c dsTest = new Teste__c();             
             dsTest = test.Select(recordid);
             if (dsTest != null)
             {
                try
                {
                    res = dsTest.Field1__c.ToString()+" / "+dsTest.Field2__c.ToString()+" / "+dsTest.Field2__c.ToString();
                }
                catch { }
            }
            }else{
              res = "No ID supplied!";
            }
            return res;
        }
       
    }
}

 

 

This is a simple request (Query), but with 100 or more records (using a List)  the performance is poor.

 

I don't know how make Async request (query's) to Salesforce or if exist a better code to make call to Salesforce API!

 

Anyone can help me to speed up the call to Salesforce?

 

Thanks in advance.

 

Best Regards,

LB

 


 

 

  • October 31, 2011
  • Like
  • 0
Hello,

I have a public Visualforce page with a Form.
This page is part of a Managed Package.

I submit the package to security review and get this reply:

«Brute Force Vulnerability
Guest site don't have logging in or email validation. Use a CAPTCHA in the process to prevent a brute force attack on the system.»

I don't want to use the Captcha, isn't a good solution to the app, need a solution on the server side.

Anyone have the same problem and found a solution to this?
Any ideia to resolve this problem?

Salesforce have the Web-to-Lead form and don't control the brute force submmiting!


Thanks and regards.

LB

  • July 27, 2012
  • Like
  • 0

Hello,

 

Have a VF page associated to a controller and want use another controller to receive @RemoteAction calls, is possible?

 

Example:

 

Visuaforce page

<apex:page standardStylesheets="false" docType="html-5.0" sidebar="false" showHeader="false" contentType="text/html" cache="true" controller="test_ControllerRA">
  <h1>Congratulations</h1>
  This is your new Page
 <hr />
 <p><a href="#" onclick="showMessage();">Press Me</a></p>
 <div id="zoneShowMsg">zone to show message</div>
 
 <script>
 function showMessage()
{
        var str = 'name=TheName&info=Info+Tag';

        document.getElementById('zoneShowMsg').innerHTML = 'Processing... please wait.';
   try{        
        test_ControllerGlobalRA.processRA(str , function(Result, event)
        {
        console.log('Result:',Result);
        console.log('event',event);
            if (event.status)
            {
                console.log('Result=',Result);                
                if(Result!= '')
                {                      
                      document.getElementById('zoneShowMsg').innerHTML = 'Information:'+Result;
                }
                else
                {
                      document.getElementById('zoneShowMsg').innerHTML = 'Problems with information:'+Result;
                }
            } 

        }, {escape:true}); 
    }catch(ex){
        document.getElementById('zoneShowMsg').innerHTML = 'ERROR:'+ex;
    }       
}
 </script>
</apex:page>

 

The VF Page Controller:

public with sharing class test_ControllerRA {

    public String getTheString(String str){
    
        String[] arrStr = str.split('&');
        String theText = 'Name: '+arrStr[0]+' / ';
        theText +='Info: '+arrStr[1]+' /// (finished)';
        
        return theText;
    }
}

 

The @RemoteAction controller:

global class test_ControllerGlobalRA{
    @RemoteAction
    global static String processRA(string Str){
        test_ControllerRA tcra = new test_ControllerRA();
        String theStr = tcra.getTheString(Str);
        return theStr;
    }
}

 

I want to use the VF page inside a iframe.

 

 

If anyone can help me, I thank.

 

Best Regards,

LB

 

  • March 07, 2012
  • Like
  • 0

Hello,

 

I want to know (I can info about this) if I can have a Visualforce page with a controller and on that page a @RemoteAction with another controller, similar to this:

 

   VISUALFORCE PAGE:

<apex:page standardStylesheets="false" docType="html-5.0" sidebar="false" showHeader="false" contentType="text/html" cache="true" controller="MyPageControllerClass">

<apex:composition template="TemplateFB">
  <head>
  </head>
<apex:form id="signUpForm">
  <input type="text" name="Id" id="Id" />
  <a href="#" onclick="javascript&colon;signUp(); return false;">Click Me</a>
  <div id="processing"></div>
</apex:form>

<script>
function signUp()
{
   var str = '';
   try{
      str = document.getElementById('Id').value;
   }catch(e){}
   MyGlobalClass.SaveId(str , function(Result, event)
   {
        console.log('Result',Result);
        console.log('event',event);
        if (event.status)
        {
          document.getElementById('processing').innerHTML = 'Information updated.';
        }else{
          document.getElementById('processing').innerHTML = 'Problem!';
        }
   }, {escape:true});
}
</script></apex:composition></apex:page>

  GLOBAL CLASS to manage @RemoteAction call:

global with sharing class MyGlobalClass {
  
    @RemoteAction
    global static String SaveId(string dataString)
    {
        String res = '';
        MyPageControllerClass myc = new MyPageControllerClass();        
        
        try
        {
           res = myc.SaveRecord(dataString);  
        }
        catch(exception e)
        {
            res = 'error';
        }

        return res;
    }
}

   And my Controller on Visualforce page (and call exist a method called by the RemoteAction):

public with sharing class MyPageControllerClass
{

  public String OneMethod(){
   String t = 'one thing';
   return t;
  }

  public String SaveRecord(){
   String t = 'success';
   return t;
  }

}

 

 

With Chrome console I saw:

 

Uncaught ReferenceError: MyGlobalClass is not defined

 

:(

 

I need to use the code inside a iFrame.

I put on the "Sites" permission, all controllers available.

 

Anyone have idea if I can use a controller for the vf page and inside use @RemoteAction with another class?

 

 

Best Regards,

LB

 

 

 

  • February 27, 2012
  • Like
  • 0