• Alx Mr
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 21
    Replies
I'm not able to call an apex function that checks if attahcment was added from JavaScript.

This is wat i have:

Js:
window.addEventListener("beforeunload", function(){CheckAttachment();});
// onbeforeunload = CheckAttachment;    
function CheckAttachment(){NoAttch();}
VF
<apex:form id="TheForm">
        <apex:actionFunction name="NoAttch" action="{!NoAttachmentEmail}"/>
Controller:
public controllerInfo(){

isattch = false;
altid = false;

....
Function:
public void NoAttachmentEmail(){
        if (isAttch==false && altId == false){
.....}
}

Do i still miss anything? 

Thank you very much.








 
  • January 05, 2017
  • Like
  • 0
Hello.

reRender attribute does not work at all. Even when blank outputPanel (nothing inside the container) used.
This is the only element which is rerendered on the page. What can be the problem?
The paragraphs are rendered correctly on Load, 'rerender' results in general error on page.
<p> 
<apex:outputPanel>                                                   
   <apex:selectList value="{!lSoftware}" size="1" multiselect="false" >
           <apex:selectOptions value="{!SoftwareMulti}"/>
           <apex:actionSupport event="onchange" reRender="f3"/>
   </apex:selectList>                              
</apex:outputPanel>

</p>  
                                                        
<p>Database<br/>                             
    <apex:outputPanel>
          <apex:selectList value="{!lDataBase}" size="1" id="f3">
              <apex:selectOptions value="{!DataBase2Multi}"/>                                                        
          </apex:selectList>
    </apex:outputPanel>                                                      
   </p>
public List<SelectOption> getDataBase2Multi(){ 
       List<SelectOption> lSO_DataBases = new List<SelectOption>();
       ldatabase = '';
       return lSO_DataBases;
}
Even the most basic scenario causing the issue.
I used same methods on the page when new record created worked fine as well, when existing record loaded to be updated there is always an issue.
Can you advise on possible reasons, please. Why reRender attribute is not binded properly on the page?
 
  • September 09, 2016
  • Like
  • 0
Hello.

I've hit a roadblock: the Google reCaptcha verification does not work in production environment after deployment.
However it works perfectly in test environmen, sandbox.
I added both site domain names to google recaptcha account initially, switched the order. 
What can be wrong?
Thank you very much for your help.
 
  • August 08, 2016
  • Like
  • 0
Hello.

Im having difficulty creating test method for the reCaptcha.

The verify() function is trigerred when Save() is called, please see bellow:
 
public PageReference save(){
       verify();
        If (verified==true){
        ....
        }

The reCapture methods perse are as follows:
 
@TestVisible private String baseUrl = 'https://www.google.com/recaptcha/api/siteverify?';
@TestVisible private String privateKey = 'MyPrivateKey';
@TestVisible public String publicKey {get { return 'MypublicKey'; }}
@TestVisible public String challenge { get {returnApexPages.currentPage().getParameters().get('recaptcha challenge');}}
@TestVisible public String response  { get {returnApexPages.currentPage().getParameters().get('g-recaptcha-response');}}
    public Boolean verified { get; set; }
    
    public void verify() {HttpResponse r = makeRequest(baseUrl, 'secret=' + privateKey +'&response='  + response +'&remoteip='  + remoteHost );
                          System.debug(r.getBody());
                          JSONParser parser = JSON.createParser(r.getBody());
                          while (parser.nextToken() != null) {
                             if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'success')) {
                                  parser.nextToken();
                                  if (parser.getBooleanValue()==true){verified =true;}else{verified = false;} }
                          }
                         }
    public PageReference reset() {return null; }
    @TestVisible private HttpResponse makeRequest(string url, string body)  {
        HttpResponse response = null;
        HttpRequest req = new HttpRequest();  
        req.setEndpoint(url);
        req.setMethod('POST');
        req.setBody (body);
        try {
            Http http = new Http();
            response = http.send(req);
            System.debug('reCAPTCHA response: ' + response);
            System.debug('reCAPTCHA body: ' + response.getBody());
        } catch(System.Exception e) {
            System.debug('ERROR: ' + e);
        }
        return response;
    }  
     
    @TestVisible public String remoteHost {get {
        String ret = '127.0.0.1';
        Map<String, String> hdrs = ApexPages.currentPage().getHeaders();
        if (hdrs.get('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;
    }
   }




As per suggestions on forums, particularly the resource: 
https://developer.salesforce.com/index.php?title=Adding_CAPTCHA_to_Force.com_Sites&oldid=42318
i came up to the following insertion into a test method for the function save():
 
ctr= new controllerLeadConfirmationPage();
...
string href = ctr.baseUrl ;
ctr.response = 'foo';
ctr.challenge = ctr.response;
string publick = ctr.publicKey;
string host = ctr.remoteHost;
...
ctr.save()

But still I cannot get it working:
System.NullPointerException: Attempt to de-reference a null object - line 1191 (which is  ' System.debug(r.getBody());' in the verify() function bellow)
 
public void verify() {HttpResponse r = makeRequest(baseUrl, 'secret=' + privateKey +'&response='  + response +'&remoteip='  + remoteHost );
                          System.debug(r.getBody());
                          JSONParser parser = JSON.createParser(r.getBody());
                          while (parser.nextToken() != null) {
                              if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'success')) {
                                  parser.nextToken();
                                  if (parser.getBooleanValue()==true){verified =true;}else{verified = false;} }
                          }
                         }

Please advise me how can i solve it.
Hello.

I've got an issue. For some reason actionSupport onChange does not work when record was already inserted and loaded back onto form. 
The same form before initial insert (when record does not exist) works fine.
So onKeyUp event reRenders a div, actually hides/shows the div when text typed/erased in inputText.
This works when lead Id is Null (does not exist).
This does not work when lead data loaded to form back: some inputText fields are empy, and then text is typed there, then 'crash' after first char typed.
I'm totaly puzzled and almost frustrated.

Please check the vf and controller method bellow for better understanding.
 
                                            <p>Photo ID Number<br/>
                                                <apex:outputPanel rendered="{!NOT(edLock2)}">
                                                    <div class="requiredInput">
                                                       <apex:outputPanel Id="r64">
                                                            <apex:outputPanel rendered="{!bPhotoIdNumber}">
                                                                <div class="requiredBlock">
                                                                </div>
                                                            </apex:outputPanel>
                                                        </apex:outputPanel>
                                                        <apex:inputText value="{!lIDNumber}" id="IDNumber"/>
                                                        <apex:actionSupport reRender="r64" event="onkeyup"/>
                                                    </div>
                                                </apex:outputPanel>
                                                <apex:outputText value="{!lIDNumber}"  rendered="{!edLock2}"/>
                                            </p>
The paragraph is located in some div> pageBlockSection> pageblock. There are about 70 paragraphs, 5 pageblocks, 15 pageBlockSections in total.

And controller method verifying the condition:
 
private Lead l;
Public String li{get;set;}
Public String lIDNumber{get;set;}

public controllerLeadCompletionPage(){
   li = (ApexPages.currentPage().getParameters().containsKey('id')?   ApexPages.currentPage().getParameters().get('id'):null);
   if(li != null){
       l = [SELECT Id, Id_Number__c from FROM Lead WHERE Id = :li limit 1];
   }else{
       l = new Lead();
   }
}

public PageReference save(){
     l.ID_Number__c= lIdNumber;
     upsert l;
}

public boolean PhotoIDNumber;
public boolean getbPhotoIdNumber(){
        string subPhotoIDNumber;
      	IF(lIDNumber != null){
        	subPhotoIDNumber =lIDNumber;
        	If(subPhotoIDNumber.length()==0){
                PhotoIDNumber = true;
            }else{
                PhotoIDNumber = false;
            }
        }else{
            PhotoIDNumber = true;
        }
        return PhotoIDNumber;
    }

Please help.... "(
Good day,
Is it possible to run insert/update/upsert queries in the query editor.

Thank you
  • April 13, 2016
  • Like
  • 0
I have a new test class that covers the apex controller code, all in sandboxe. I have old test class and old apex controllers. when i deploy new test class i get an error: method doesn't exist in the controller (of course it doesn't because it is an old controller. When i deploy apex controller the test coverage does not pass.
Question how to deploy/update the test class in production?
Thank you.
  • April 12, 2016
  • Like
  • 0
Hello.
I have a question: the requirement to have a code coverage of 75% by unitTest, is this limit applicable to each Apex form control individualy, or a total for the deployed solution. I have 2 froms covered 90% and 62 respectively. So in total is 76%.
Thank you in advance.
  • April 12, 2016
  • Like
  • 0
Gooda day. I encountered the following exception error while running unit test:
"Failed to enqueue tests.: Unknown Exception"
My guess it is related to the daily limit of test classes to run..
May you confirm if this is the case, and if 'Yes' how can i override this. I use Sandbox, and don't have many options.
Thank you in advance.
 
  • April 11, 2016
  • Like
  • 0
Good day,

I need help writing tests for my get methods. I'm quite a newbie. May you give a pice of advise or a snipet, please.
the apex controller code:
public SelectOption[] getSubGroupsMulti() {  
        aGroupId = (ApexPages.currentPage().getParameters().containsKey('groupId')?                    ApexPages.currentPage().getParameters().get('groupId'):null);
        SelectOption[] lSO_subGroups   = new SelectOption[]{};  
       strSubGroups = [select Sub_Group__c from Account where Id = :aGroupId].Sub_Group__c;
        arrSubGroups = strSubGroups.split(';');
           for (integer i=0; i<arrSubGroups.size(); i++) {  
            lSO_subGroups.add(new SelectOption(arrSubGroups[i], arrSubGroups[i]));  
        }  
        return lSO_subGroups;  
    }

Visual force code
<apex:selectList value="{!aSubGroups}" size="1" multiselect="false">
          <apex:selectOptions value="{!SubGroupsMulti}"/>
</apex:selectList>
Thank you very much

 
  • April 09, 2016
  • Like
  • 0
Good day.
I have an issue. When i declare controller class as public the when i select a file inputFile component works fine. I contrast when i declare the cotroller class as Public with sharing when selectinhg a file it gives an error.
Need some hrlp on this. thnx

<apex:outputPanel rendered="{!hasId}">
                                        <div id="post-266">
                                            <h2 class="left_title"><span>Attach New Document</span></h2>
                                        </div>
                                        <div class="wpcf7" id="wpcf7-f712-p266-o1" lang="en-US" dir="ltr">
                                            <p>
                                                New Attachment<br/>
                                                <apex:inputFile value="{!fileBody}" filename="{!fileName}" id="file"/>
                                                <apex:commandButton value="Add" action="{!addAttachment}" />
                                            </p>
                                        </div>
 </apex:outputPanel>

 public with sharing class controllerUserInfo {
 public string fileName {get; set;}
    public Blob fileBody {get; set;}
public class cAttachment{
        public Boolean selected {get; set;}
        Public Id idAttachment {get;set;}
        public String nameAttachment {get;set;}
        public String typeAttachment {get;set;}
        public Id parentAttachment {get;set;}
        public Boolean attachmentOwner {get; set;}
        
        public cAttachment(Id idA, String nameA, String typeA, Id parentA, Boolean owner){
            idAttachment = idA;
            nameAttachment = nameA;
            typeAttachment = typeA;
            parentAttachment = parentA;
            attachmentOwner = owner;
            selected = false;
        }
        
        public PageReference verArchivo(){
            return new PageReference('/servlet/servlet.FileDownload?file='+idAttachment);
        }
    }
  public  Boolean getHasId(){
        return (a.Id != null);
    }
}
  • April 03, 2016
  • Like
  • 0
Good day.
I need help with the apex class code. I have two selectLists (Brands, Makes). I need to be able to rerender the select list (Makes), populating it with the options based on the option selected in another selectList (Brands). The brands options is taken from databse multiselect picklist. The logic/code seems working fine for the first time when the page loads. However when the other option (brand) is selected from brandList, it doesnt, error page. Thank you for any advise.

Visual force page components:

<apex:page controller="controllerBrandsMakes" sidebar="false" showHeader="false" cache="false" expires="0" docType="html-5.0">
<apex:form >
<p>    Brands<br/>
    <apex:selectList value="{!aBrand}" size="1" multiselect="false">
        <apex:selectOptions value="{!aBrands}"/>
    <apex:actionSupport event="onchange" reRender="MakesField"/>
</apex:selectList>
</p>  

<p>Makes<br/>
<apex:outputPanel id="MakesField">
    <apex:selectList value="{!aMake}" size="1" multiselect="false">
        <apex:selectOptions value="{!DataMakes}"/>
    </apex:selectList>
</apex:outputPanel>
</p>
</apex:form>

Controller class abbridged:

public class controllerBrandsMakes {
public String aBrand {get; set;}
public String aMake {get; set;}
public List<SelectOption> lSO_Brands {get; set;}
public List<SelectOption> lSO_Makes {get; set;}

public controllerBrandsMakes(){
//...
//...aBrand = ... the one of an individual account initially put into apex Brands value (A) is assigned to individual account record.
//...aMake = ...     the one of an individual account initially put into apex Makes value (e.g a2)
//...selectOption lSO_Brands ...Initially put into apex selectList (A;B). picklist contains default schema values (A,B)
//...selectOptionlSO_Makes...Initially put into apex selectList (a1,a2,a3).  multiselect picklist contains default schema values (a1,a2,a3,b1)

}

public SelectOption[] getDataMakes(){  
           aGroupId = (ApexPages.currentPage().getParameters().containsKey('groupId')?ApexPages.currentPage().getParameters().get('groupId'):null);
        list<SelectOption> lSO_Makes   = new list<SelectOption>();  
        String strMake = [select Makes__c from Account where Id = :aGroupId].Makes__c;  // (a1,a2,a3,b1)the list from multiselect picklist of a group account
        String[] arrMakes = strMake.split(';');
        
        if (aBrand.equalsIgnoreCase('A')){
            for (integer i=0; i<arrMakes.size(); i++) {  
                if(!arrMakes[i].equalsIgnoreCase('b1')){
                    lSO_Makes.add(new SelectOption(arrMakes[i], arrMakes[i]));  //(a1,a2,a3)
                }
                aMakes = arrMake[0]; // set (a1) when brand reselected from list
            }
         }else if (aBrand.equalsIgnoreCase('B')){
                    lSO_DataBase2.add(new SelectOption('b1', 'b1')); // only one option
                 aMake = 'b1';
         }    
        return lSO_Makes;  
}
  • March 27, 2016
  • Like
  • 0
I'm not able to call an apex function that checks if attahcment was added from JavaScript.

This is wat i have:

Js:
window.addEventListener("beforeunload", function(){CheckAttachment();});
// onbeforeunload = CheckAttachment;    
function CheckAttachment(){NoAttch();}
VF
<apex:form id="TheForm">
        <apex:actionFunction name="NoAttch" action="{!NoAttachmentEmail}"/>
Controller:
public controllerInfo(){

isattch = false;
altid = false;

....
Function:
public void NoAttachmentEmail(){
        if (isAttch==false && altId == false){
.....}
}

Do i still miss anything? 

Thank you very much.








 
  • January 05, 2017
  • Like
  • 0
Hello.

reRender attribute does not work at all. Even when blank outputPanel (nothing inside the container) used.
This is the only element which is rerendered on the page. What can be the problem?
The paragraphs are rendered correctly on Load, 'rerender' results in general error on page.
<p> 
<apex:outputPanel>                                                   
   <apex:selectList value="{!lSoftware}" size="1" multiselect="false" >
           <apex:selectOptions value="{!SoftwareMulti}"/>
           <apex:actionSupport event="onchange" reRender="f3"/>
   </apex:selectList>                              
</apex:outputPanel>

</p>  
                                                        
<p>Database<br/>                             
    <apex:outputPanel>
          <apex:selectList value="{!lDataBase}" size="1" id="f3">
              <apex:selectOptions value="{!DataBase2Multi}"/>                                                        
          </apex:selectList>
    </apex:outputPanel>                                                      
   </p>
public List<SelectOption> getDataBase2Multi(){ 
       List<SelectOption> lSO_DataBases = new List<SelectOption>();
       ldatabase = '';
       return lSO_DataBases;
}
Even the most basic scenario causing the issue.
I used same methods on the page when new record created worked fine as well, when existing record loaded to be updated there is always an issue.
Can you advise on possible reasons, please. Why reRender attribute is not binded properly on the page?
 
  • September 09, 2016
  • Like
  • 0
Hello.

Im having difficulty creating test method for the reCaptcha.

The verify() function is trigerred when Save() is called, please see bellow:
 
public PageReference save(){
       verify();
        If (verified==true){
        ....
        }

The reCapture methods perse are as follows:
 
@TestVisible private String baseUrl = 'https://www.google.com/recaptcha/api/siteverify?';
@TestVisible private String privateKey = 'MyPrivateKey';
@TestVisible public String publicKey {get { return 'MypublicKey'; }}
@TestVisible public String challenge { get {returnApexPages.currentPage().getParameters().get('recaptcha challenge');}}
@TestVisible public String response  { get {returnApexPages.currentPage().getParameters().get('g-recaptcha-response');}}
    public Boolean verified { get; set; }
    
    public void verify() {HttpResponse r = makeRequest(baseUrl, 'secret=' + privateKey +'&response='  + response +'&remoteip='  + remoteHost );
                          System.debug(r.getBody());
                          JSONParser parser = JSON.createParser(r.getBody());
                          while (parser.nextToken() != null) {
                             if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'success')) {
                                  parser.nextToken();
                                  if (parser.getBooleanValue()==true){verified =true;}else{verified = false;} }
                          }
                         }
    public PageReference reset() {return null; }
    @TestVisible private HttpResponse makeRequest(string url, string body)  {
        HttpResponse response = null;
        HttpRequest req = new HttpRequest();  
        req.setEndpoint(url);
        req.setMethod('POST');
        req.setBody (body);
        try {
            Http http = new Http();
            response = http.send(req);
            System.debug('reCAPTCHA response: ' + response);
            System.debug('reCAPTCHA body: ' + response.getBody());
        } catch(System.Exception e) {
            System.debug('ERROR: ' + e);
        }
        return response;
    }  
     
    @TestVisible public String remoteHost {get {
        String ret = '127.0.0.1';
        Map<String, String> hdrs = ApexPages.currentPage().getHeaders();
        if (hdrs.get('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;
    }
   }




As per suggestions on forums, particularly the resource: 
https://developer.salesforce.com/index.php?title=Adding_CAPTCHA_to_Force.com_Sites&oldid=42318
i came up to the following insertion into a test method for the function save():
 
ctr= new controllerLeadConfirmationPage();
...
string href = ctr.baseUrl ;
ctr.response = 'foo';
ctr.challenge = ctr.response;
string publick = ctr.publicKey;
string host = ctr.remoteHost;
...
ctr.save()

But still I cannot get it working:
System.NullPointerException: Attempt to de-reference a null object - line 1191 (which is  ' System.debug(r.getBody());' in the verify() function bellow)
 
public void verify() {HttpResponse r = makeRequest(baseUrl, 'secret=' + privateKey +'&response='  + response +'&remoteip='  + remoteHost );
                          System.debug(r.getBody());
                          JSONParser parser = JSON.createParser(r.getBody());
                          while (parser.nextToken() != null) {
                              if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'success')) {
                                  parser.nextToken();
                                  if (parser.getBooleanValue()==true){verified =true;}else{verified = false;} }
                          }
                         }

Please advise me how can i solve it.
Hello.

I've got an issue. For some reason actionSupport onChange does not work when record was already inserted and loaded back onto form. 
The same form before initial insert (when record does not exist) works fine.
So onKeyUp event reRenders a div, actually hides/shows the div when text typed/erased in inputText.
This works when lead Id is Null (does not exist).
This does not work when lead data loaded to form back: some inputText fields are empy, and then text is typed there, then 'crash' after first char typed.
I'm totaly puzzled and almost frustrated.

Please check the vf and controller method bellow for better understanding.
 
                                            <p>Photo ID Number<br/>
                                                <apex:outputPanel rendered="{!NOT(edLock2)}">
                                                    <div class="requiredInput">
                                                       <apex:outputPanel Id="r64">
                                                            <apex:outputPanel rendered="{!bPhotoIdNumber}">
                                                                <div class="requiredBlock">
                                                                </div>
                                                            </apex:outputPanel>
                                                        </apex:outputPanel>
                                                        <apex:inputText value="{!lIDNumber}" id="IDNumber"/>
                                                        <apex:actionSupport reRender="r64" event="onkeyup"/>
                                                    </div>
                                                </apex:outputPanel>
                                                <apex:outputText value="{!lIDNumber}"  rendered="{!edLock2}"/>
                                            </p>
The paragraph is located in some div> pageBlockSection> pageblock. There are about 70 paragraphs, 5 pageblocks, 15 pageBlockSections in total.

And controller method verifying the condition:
 
private Lead l;
Public String li{get;set;}
Public String lIDNumber{get;set;}

public controllerLeadCompletionPage(){
   li = (ApexPages.currentPage().getParameters().containsKey('id')?   ApexPages.currentPage().getParameters().get('id'):null);
   if(li != null){
       l = [SELECT Id, Id_Number__c from FROM Lead WHERE Id = :li limit 1];
   }else{
       l = new Lead();
   }
}

public PageReference save(){
     l.ID_Number__c= lIdNumber;
     upsert l;
}

public boolean PhotoIDNumber;
public boolean getbPhotoIdNumber(){
        string subPhotoIDNumber;
      	IF(lIDNumber != null){
        	subPhotoIDNumber =lIDNumber;
        	If(subPhotoIDNumber.length()==0){
                PhotoIDNumber = true;
            }else{
                PhotoIDNumber = false;
            }
        }else{
            PhotoIDNumber = true;
        }
        return PhotoIDNumber;
    }

Please help.... "(
Good day,
Is it possible to run insert/update/upsert queries in the query editor.

Thank you
  • April 13, 2016
  • Like
  • 0
I have a new test class that covers the apex controller code, all in sandboxe. I have old test class and old apex controllers. when i deploy new test class i get an error: method doesn't exist in the controller (of course it doesn't because it is an old controller. When i deploy apex controller the test coverage does not pass.
Question how to deploy/update the test class in production?
Thank you.
  • April 12, 2016
  • Like
  • 0
Hello.
I have a question: the requirement to have a code coverage of 75% by unitTest, is this limit applicable to each Apex form control individualy, or a total for the deployed solution. I have 2 froms covered 90% and 62 respectively. So in total is 76%.
Thank you in advance.
  • April 12, 2016
  • Like
  • 0
Good day,

I need help writing tests for my get methods. I'm quite a newbie. May you give a pice of advise or a snipet, please.
the apex controller code:
public SelectOption[] getSubGroupsMulti() {  
        aGroupId = (ApexPages.currentPage().getParameters().containsKey('groupId')?                    ApexPages.currentPage().getParameters().get('groupId'):null);
        SelectOption[] lSO_subGroups   = new SelectOption[]{};  
       strSubGroups = [select Sub_Group__c from Account where Id = :aGroupId].Sub_Group__c;
        arrSubGroups = strSubGroups.split(';');
           for (integer i=0; i<arrSubGroups.size(); i++) {  
            lSO_subGroups.add(new SelectOption(arrSubGroups[i], arrSubGroups[i]));  
        }  
        return lSO_subGroups;  
    }

Visual force code
<apex:selectList value="{!aSubGroups}" size="1" multiselect="false">
          <apex:selectOptions value="{!SubGroupsMulti}"/>
</apex:selectList>
Thank you very much

 
  • April 09, 2016
  • Like
  • 0