• snievas
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

Hello,

 

We can assign an error to a field, but is it possible to show the error on the top of the page using Apex code ?

 

Please Help

Thank You

  • April 12, 2010
  • Like
  • 0

Has anyone here had any luck enabling shortcuts to add comment code when using eclipse?

What is the best way to keep an object from actually being inserted using triggers? I have a custom helper object that I do not need/want any records created for it.

Hi Guys,

I am trying to write the test method for below mention controller but not able to write. This class is calling ReCaptcha service. I am new to this , please help me out.

 

public  class SA_CFX_Password_Reset_Controller {

    private static string secret = '6LdecwwAAAAAALtIuEKANEv7lgzQNGzMAluFXSHk ';
    public string publicKey { get { return '6LdecwwAAAAAAIqUiXkcEJ_-V1U99uwCm-S4OXuY ' ; }} 

    private static string baseUrl = 'http://api-verify.recaptcha.net/verify'; 
     
    public string challenge {get; set;} { challenge = null; } 
    public string response {get; set; }  { response = null; } 
    public string message {get; set;} { message = null; } 

    public Boolean correctResponse { get; private set; } { correctResponse = false; } 
    
    public Account acc;
       
    public void SA_CFX_Password_Reset_Controller()
    {
        //Constructor
    }
    
    public Account getacc()
    { 
        if (acc == null) 
            acc = new Account();
        return acc;
    }
 
    public PageReference verify() {
      
    try { 
          if ( challenge == null || response == null ) { 
            
            return null; 
          }
                    
          HttpResponse r = makeRequest(  baseUrl ,
               'privatekey='+ secret + 
               '&remoteip=' + remoteHost + 
               '&challenge=' + challenge +
               '&response=' + response +
               '&error=incorrect-captcha-sol'
          );
        
          if ( r != null ) {  // is null when test methods run
            correctResponse = ( r.getBody().contains('true') );
          }
          
          if(correctResponse == true) {              
                Account Acct = [select Id, SA_CFX_Primary_Contact_eMail__c, SA_CFX_Reset_OTP__c, (Select Id,Password__c, User_Id__c, Flag__c  From CFX_Trading_Accounts__r) from Account where SA_CFX_Primary_Contact_eMail__c = :acc.SA_CFX_Primary_Contact_eMail__c ];
                CFX_Trading_Account__c[] tdacc = Acct.CFX_Trading_Accounts__r;
                
                list <CFX_Trading_Account__c> tacc = new list<CFX_Trading_Account__c>();
                for(Integer i=0; i<tdacc.size(); i++)
                {   
                    if(i == 0){
                      tdacc[i].Flag__c = true;
                    }
                    SA_CFXPasswordGenerator PassGen = new SA_CFXPasswordGenerator();
                    String pd = PassGen.randomPassword();
                    tdacc[i].Password__c = pd;
                    tacc.add(tdacc[i]);         
                    
                }
                                
                if(tacc.size()>0){                  
                    Database.SaveResult[] lsr = Database.update(tacc,true);
                    
                    for(Database.SaveResult sr : lsr){
                        if(sr.isSuccess()){
                          
              return Page.SA_CFX_Password_Reset_Successful;
              
                        }
                        else{
                            return Page.SA_CFX_Password_Reset_Failure;
                        }
                    }
                }
                else {
                    
                    return Page.SA_CFX_Password_Reset_Failure;
                }
                
          }  
        response = null;
        challenge = null;  
        message = 'Yes';
        return null;
   }
   
   catch (Exception e)  {
     ApexPages.addMessages(e);
     return null;
     
   }
        
 }    
       
   

    public PageReference reset() {
        challenge = null;
        response = null; 
        return null; 
    }   

    public static HttpResponse makeRequest(string url, string body)  {
          HttpRequest req = new HttpRequest();   
          HttpResponse response = null;
          req.setEndpoint( url );
          req.setMethod('POST');
          req.setBody ( body);
          try {
            Http http = new Http();
            response = http.send(req);
            System.debug('response: '+ response);
            System.debug('body: '+ response.getBody());
           
          } catch( System.Exception e) {
             System.debug('ERROR: '+ e);
          }
          return response;
        }   
    
    public PageReference close()
    {
        return null;
    }
  
    public PageReference close1()
    {   
        PageReference pg = page.ResetOTP ;
        pg.setRedirect(true);
        return pg; 
        return null;
    }
    
    
    public string remoteHost { get { string ret = '127.0.0.1';
        // also could use x-original-remote-host 
        map<string , string> hdrs = ApexPages.currentPage().getHeaders();
        if ( hdrs.get('x-original-remote-addr') != null)
            ret =  hdrs.get('x-original-remote-addr');
        else if ( hdrs.get('X-Salesforce-SIP') != null)
            ret =  hdrs.get('X-Salesforce-SIP');
        return ret;
    } }
    

 

Many Thanks,

pchadha20

"The new Force.com IDE for Spring '10 will be released on April 19th"

 

Okay, it's April 19th now.  Give me, give me!

 

Force.com IDE 3.5.x

I am trying to learn the APEX code and plan on taking the DEV531 course.


If you took DEV531 what are your thoughts on this course?

Is DEV531 the right course to take for someone that is new to programming?

What other advice do you have for learning APEX and Visualforce?


-Thank You

 

LinkedIn Discussion

Hello,

 

We can assign an error to a field, but is it possible to show the error on the top of the page using Apex code ?

 

Please Help

Thank You

  • April 12, 2010
  • Like
  • 0

I'm using the textmate plugin for salesforce. Any chance the associated apexloader.app will be updated, or perhaps the source released?

 

The eclipse ide is just too fragile, so I'm developing using TextMate as editor with ant migration tool for uploading, but Salesforce_com.tmbundle is great for recompiling just one class or trigger at a time.

Message Edited by Shikibu on 03-19-2009 08:25 AM