• Amiya Das
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
The main apex class is :-
 
public without sharing class POCPAGEV2CaseContrl {
public String siteKeyValue{get; set;}
    public boolean caseCreated{Get;set;}
    public POCPAGEV2CaseContrl(ApexPages.StandardController sc){
        caseCreated = false;
        caseVar = new Case();
        siteKeyValue = UTAGoogleRecatcha__c.getValues('GoogleRecaptchaKey').SiteKeyValue__c;
    }
    public case caseVar{Get;set;}
    public pagereference saveRec(){
            if(!isCaptchaValid()){

            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Recaptcha validation failed'));
                    return null;
        }
    caseVar.RecordTypeId='01270000000YTjY';
        insert caseVar;
        caseCreated = true;
        return new pagereference('/apex/POCPage3Case?success=1').setRedirect(true);
    }
    
      // Simranjeet Singh - Commented this Method.
  public Boolean isCaptchaValid(){
    String gRecaptchaResponse = ApexPages.currentPage().getParameters().get('g-recaptcha-response');
        GoogleRecaptcha grecaptcha = new GoogleRecaptcha(UTAGoogleRecatcha__c.getValues('GoogleRecaptchaKey').SecretKeyValue__c);
        return grecaptcha.validCaptcha(gRecaptchaResponse);
    } 
}
The above apex class has instance of this apex class below :-
 
public class GoogleRecaptcha {
	
	private String secretKey;
	
	public GoogleRecaptcha(String secretKey){
		this.secretKey = secretKey;
	}
	
	public Boolean validCaptcha(String validationString){
		
		HttpRequest request = new HttpRequest();
		request.setMethod('POST');
		request.setEndpoint('https://www.google.com/recaptcha/api/siteverify');
		request.setBody('secret='+EncodingUtil.urlEncode(secretKey,'UTF-8')+'&response='+EncodingUtil.urlEncode(validationString, 'UTF-8'));
		
		Http http = new Http();
		HttpResponse httpResponse = http.send(request);
		
		RecaptchaResponse response = (RecaptchaResponse)JSON.deserialize(httpResponse.getBody(), RecaptchaResponse.class);
		
		return response.success;
	}
	
	public class RecaptchaResponse{
		Boolean success {get;set;}
	}

}

please help me in test class with proper code coverage for the top most class :- POCPAGEV2CaseContrl

Any Help would be appreciated. Thanks in advance.
Hi,

I am trying to create a input form for Position object. My requirement is that, on submit button, the position records should be saved to the database and should also be displayed on the custom lightning page. For reference, i have used the same logic as given for the expense example in trailhead section :- https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_forms(input form using components). 

Following is the component code:-

<aura:component implements="force:appHostable" controller="PositionInputController">
    <aura:attribute name="positions" type="Position__c[]"/>
    <aura:attribute name="newPosition" type="Position__c" default="{'sObjectType' : 'Position__c',
                                                                   'Name' : 'Senior Manager',
                                                                   'Apex__c' : true,
                                                                   'Close_Date__c' : '' ,
                                                                   'Days_Open__c' : 5,
                                                                   'Hire_By__c' : '',
                                                                   'Responsibilities__c' : '',
                                                                   'Max_Pay__c' : '',
                                                                   'Min_Pay__c' : ''}"/>
    
    <aura:attribute name="position" type="Position__c"/>
    
    <!-- Boxed Area -->
    <fieldset class="slds-box slds-theme--default slds-container--small">
        <legend id="NewPositionForm" class="slds-text-heading--small slds-p-vertical--medium">
            My Position Form Entry Items
        </legend>
    
    
    
    <!-- Input form Components -->
    <div class="container">
        <form class="slds-form--stacked">
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputText aura:id="name" label="Name" value="{!v.newPosition.Name}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputCheckbox aura:id="apex" label="Apex" value="{!v.newPosition.Apex__c}" class="slds-checkbox" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputDateTime aura:id="closedate" label="CloseDate" value="{!v.newPosition.Close_Date__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true" displayDatePicker="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputNumber aura:id="daysopen" label="DaysOpen" value="{!v.newPosition.Days_Open__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputDateTime aura:id="hirebydate" label="HireByDate" value="{!v.newPosition.Hire_By__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true" displayDatePicker="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputText aura:id="responsibilities" label="Responsibilities" value="{!v.newPosition.Responsibilities__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputCurrency aura:id="minpay" label="MinPay" value="{!v.newPosition.Min_Pay__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputCurrency aura:id="maxpay" label="MaxPay" value="{!v.newPosition.Max_Pay__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            <br/>
            <p>
                <ui:button label="Submit Position" press="{!c.submitPosition}" class="slds-button slds-button--brand"/>
            </p>
        </form>
    </div>
        </fieldset>
    <br/><br/>
    
    <!-- Displaying position form components -->
    <p>Name:
        <ui:outputText value="{!v.position.Name}" class="slds-output"/>
    </p>
    <p>Responsibilities:
        <ui:outputText value="{!v.position.Responsibilities__c}" class="slds-output"/>
    </p>
    <p>Minimum Pay:
        <ui:outputCurrency value="{!v.position.Min_Pay__c}" class="slds-output"/>
    </p>
    <p>Maximum Pay:
        <ui:outputCurrency value="{!v.position.Max_Pay__c}" class="slds-output"/>
    </p>
    <p>Hire By Date:
        <ui:outputDateTime value="{!v.position.Hire_By__c}" class="slds-output"/>
    </p>
    <p>Apex:
        <ui:outputCheckbox value="{!v.position.Apex__c}" class="slds-checkbox"/>
    </p>
    <p>Days Open:
        <ui:outputNumber value="{!v.position.Days_Open__c}" class="slds-output"/>
    </p>
    
    
    <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small"> Positions </h3>
        </header>
        
        <section class="slds-card__body">
               <div id="list" class="row">
                <aura:iteration items="{!v.positions}" var="pos">
                <p> {!pos.Name}, {!pos.Hire_By__c}, {!pos.Responsibilities__c}, {!pos.Min_Pay__c}, {!pos.Max_Pay__c},
                {!pos.Days_Open__c}, {!pos.Apex__c}, {!pos.Close_Date__c} </p>
            </aura:iteration>
            </div>
        </section>
    </div>
    
    
    
</aura:component>

Following is the helper code:-

({
    createPosition : function(component, postn) {
        var thePosition = component.get("v.positions");
        
        var newPosition = JSON.parse(JSON.stringify(postn));
        
        thePosition.push(newPosition);
        component.set("v.positions", thePosition);
    }
})

Following is the controller code :-

({
    submitPosition : function(component, event, helper) {
        validPosition = true;
        
        //Name should not be blank
        var nameField = component.find("name");
        var posName = component.get("v.nameField");
        if($A.util.isEmpty(posName)){
            validPosition = false;
            nameField.set("v.errors", [{message:"name cant be blank"}]);
        }
        else
            nameField.set("v.errors", null);
        
        //responsibilities should not be blank
        var respField = component.find("responsibilities");
        var posResp = component.get("v.respField");
        if($A.util.isEmpty(posResp)){
            validPosition = false;
            respField.set("v.errors", [{message:"responsibilities cant be null"}]);
        }
        else
            respField.set("v.errors", null);
    
    
    //close Date cant be blank
    var closeDateField = component.find("closedate");
    var poscloseDate = component.get("v.closeDateField");
    if($A.util.isEmpty(poscloseDate)){
        validPosition = false;
    closeDateField.set("v.errors", [{message:"close date cant be blank"}]);
    }
    else
        closeDateField.set("v.errors", null);
        
        //Days Open should not be blank
        var daysOpenField = component.find("daysopen");
        var posdaysOpen = component.get("v.daysOpenField");
        if($A.util.isEmpty(posdaysOpen)){
            validPosition = false;
            daysOpenField.set("v.erros", [{message:"days open cant be blank"}]);
        }
        else
            daysOpenField.set("v.erros", null);
        
        //if error checking passed...excute the below code
        if(validPosition){
            //create new Position
            var newPosition = component.get("v.newPosition");
            console.log("create position : " +JSON.stringify(newPosition));
            helper.createPosition(component, newPosition);
        }
        
}
})

Following the is the apex class :- (for saving the position record)

public with sharing class PositionInputController {

@AuraEnabled
    public static list<Position__c> positionMethod1(){
        return [select Id, Name, Responsibilities__c, Apex__c, Close_Date__c, Days_Open__c, Hire_By__c, Max_Pay__c, Min_Pay__c from Position__c ];
    }

@AuraEnabled
    public static Position__c positionMethod2(Position__c pos){
        upsert pos;
        return pos;
    }
}

Following is the application code:-

<aura:application extends="force:slds">
    <div class="slds">
        <div class="slds-page-header">
            <div class="slds-grid">
                <p class="slds-text-heading--label"> Position Entry Form </p>
                <div class="slds-grid">
                    <p class="slds-text-heading--medium"> Position Items List </p>
                </div>
            </div>
        </div>
    </div>
    <c:PositionInputForm />
    
</aura:application>

the error on submit button is :
This page has an error. You might just need to refresh it. Action failed: c:PositionInputForm$controller$submitPosition [validPosition is not defined] Failing descriptor: {c:PositionInputForm$controller$submitPosition}

Any help will be appreciated. 
Thanks
I am getting 'URL No longer exists for a community page' error while previewing a vf page related to communities. While if i am creating a login page without using community template page(custom vf page), I am able to preview that page. When i am using the template page, this error occurs.
Any Ideas for resolution???. 
Thanks in advance
i want to map the current logged in user id with the Admin_Assistant_Email__c field under Ticket_Request__c object. Following is the code. While executing i am getting 'missing ) in parenthetical' in javascript pop-up alert.

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")} 

var trs = new sforce.SObject("Ticket_Request__c"); 
trs.Id = '{!Ticket_Request__c.Id}'; 
var user = sforce.connection.getUserInfo().userId;

if ('{!Ticket_Request__c.Status__c}' == 'New') { 
if (confirm('Are you Sure ? Once the Ticket Request is canceled, it cannot be resubmitted')) { 

trs.Status__c = 'Cancelled - Unsubmitted'; 
var result = sforce.connection.update([trs]); 
window.location.reload(); 




else if ('{!Ticket_Request__c.Status__c}' == 'Cancelled - Unsubmitted') { 
alert('Ticket request is already cancelled'); 


else if (('{!Ticket_Request__c.Status__c}' == 'Approved - Pending Confirmation') 
 && (user == {!Ticket_Request__c.Admin_Assistant_Email__c})) {
 if (confirm('Are you Sure ? Once the Ticket Request is canceled, it cannot be resubmitted')) { 

trs.Status__c = 'Cancelled - Unsubmitted'; 
var result = sforce.connection.update([trs]);  
window.location.reload(); 





else { 
alert('Only newly created ticket requests can be cancelled'); 

}

Any help would be appreciated. Thanks in advance!!
I have a requirement to create a custom button for cancelling a request. Have already implemented this functionality using javascript custom button for which, on clicking the cancel button, the ticket(Custom object) status changes from new to cancelled. But for other status picklist values other than new, it will throw a pop that only new tickets can be cancelled. This has been done(code is below). Now an additional requirement is that only a partilcular user should be able to cancel the ticket for all status picklist values(including new picklist value). As of now a user is only able to cancel a ticket in new status only.
Any help would be appreciated. Thanks in advance. Any ideas what modifications to be done..

Code is :-

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")}{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}
 
var trs = new sforce.SObject("Ticket_Request__c");
trs.Id = '{!Ticket_Request__c.Id}';
if('{!Ticket_Request__c.Status__c}' == 'New') {
if(confirm('Are you Sure ? Once the Ticket Request is cancelled , it cannot be resubmitted')){
window.location.reload();
trs.Status__c = 'Cancelled - Unsubmitted';
}
else{
}
 
}
else if('{!Ticket_Request__c.Status__c}' == 'Cancelled - Unsubmitted'){
alert('Ticket request is already cancelled');
 
}
else if('{!Ticket_Request__c.Status__c}' == 'Cancelled - Unsubmitted'){
AND(
ISCHANGED(Ticket_Request__c.Status__c ),
ISPICKVAL(PRIORVALUE(Ticket_Request__c.Status__c ), "Cancelled - Unsubmitted"),
NOT(ISPICKVAL( Ticket_Request__c.Status__c , "Cancelled - Unsubmitted"))
)
}
else{
alert('Only newly created ticket requests can be cancelled');
 
}
var result = sforce.connection.update([trs]);
Hi,

I am trying to create a input form for Position object. My requirement is that, on submit button, the position records should be saved to the database and should also be displayed on the custom lightning page. For reference, i have used the same logic as given for the expense example in trailhead section :- https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_forms(input form using components). 

Following is the component code:-

<aura:component implements="force:appHostable" controller="PositionInputController">
    <aura:attribute name="positions" type="Position__c[]"/>
    <aura:attribute name="newPosition" type="Position__c" default="{'sObjectType' : 'Position__c',
                                                                   'Name' : 'Senior Manager',
                                                                   'Apex__c' : true,
                                                                   'Close_Date__c' : '' ,
                                                                   'Days_Open__c' : 5,
                                                                   'Hire_By__c' : '',
                                                                   'Responsibilities__c' : '',
                                                                   'Max_Pay__c' : '',
                                                                   'Min_Pay__c' : ''}"/>
    
    <aura:attribute name="position" type="Position__c"/>
    
    <!-- Boxed Area -->
    <fieldset class="slds-box slds-theme--default slds-container--small">
        <legend id="NewPositionForm" class="slds-text-heading--small slds-p-vertical--medium">
            My Position Form Entry Items
        </legend>
    
    
    
    <!-- Input form Components -->
    <div class="container">
        <form class="slds-form--stacked">
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputText aura:id="name" label="Name" value="{!v.newPosition.Name}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputCheckbox aura:id="apex" label="Apex" value="{!v.newPosition.Apex__c}" class="slds-checkbox" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputDateTime aura:id="closedate" label="CloseDate" value="{!v.newPosition.Close_Date__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true" displayDatePicker="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputNumber aura:id="daysopen" label="DaysOpen" value="{!v.newPosition.Days_Open__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputDateTime aura:id="hirebydate" label="HireByDate" value="{!v.newPosition.Hire_By__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true" displayDatePicker="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputText aura:id="responsibilities" label="Responsibilities" value="{!v.newPosition.Responsibilities__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputCurrency aura:id="minpay" label="MinPay" value="{!v.newPosition.Min_Pay__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            
            <div class="slds-form-element slds-is-required">
                <div class="slds-form-element__control">
                    <ui:inputCurrency aura:id="maxpay" label="MaxPay" value="{!v.newPosition.Max_Pay__c}" class="slds-input" 
                                  labelClass="slds-form-element__label" required="true"/>
                </div>
            </div>
            <br/>
            <p>
                <ui:button label="Submit Position" press="{!c.submitPosition}" class="slds-button slds-button--brand"/>
            </p>
        </form>
    </div>
        </fieldset>
    <br/><br/>
    
    <!-- Displaying position form components -->
    <p>Name:
        <ui:outputText value="{!v.position.Name}" class="slds-output"/>
    </p>
    <p>Responsibilities:
        <ui:outputText value="{!v.position.Responsibilities__c}" class="slds-output"/>
    </p>
    <p>Minimum Pay:
        <ui:outputCurrency value="{!v.position.Min_Pay__c}" class="slds-output"/>
    </p>
    <p>Maximum Pay:
        <ui:outputCurrency value="{!v.position.Max_Pay__c}" class="slds-output"/>
    </p>
    <p>Hire By Date:
        <ui:outputDateTime value="{!v.position.Hire_By__c}" class="slds-output"/>
    </p>
    <p>Apex:
        <ui:outputCheckbox value="{!v.position.Apex__c}" class="slds-checkbox"/>
    </p>
    <p>Days Open:
        <ui:outputNumber value="{!v.position.Days_Open__c}" class="slds-output"/>
    </p>
    
    
    <div class="slds-card slds-p-top--medium">
        <header class="slds-card__header">
            <h3 class="slds-text-heading--small"> Positions </h3>
        </header>
        
        <section class="slds-card__body">
               <div id="list" class="row">
                <aura:iteration items="{!v.positions}" var="pos">
                <p> {!pos.Name}, {!pos.Hire_By__c}, {!pos.Responsibilities__c}, {!pos.Min_Pay__c}, {!pos.Max_Pay__c},
                {!pos.Days_Open__c}, {!pos.Apex__c}, {!pos.Close_Date__c} </p>
            </aura:iteration>
            </div>
        </section>
    </div>
    
    
    
</aura:component>

Following is the helper code:-

({
    createPosition : function(component, postn) {
        var thePosition = component.get("v.positions");
        
        var newPosition = JSON.parse(JSON.stringify(postn));
        
        thePosition.push(newPosition);
        component.set("v.positions", thePosition);
    }
})

Following is the controller code :-

({
    submitPosition : function(component, event, helper) {
        validPosition = true;
        
        //Name should not be blank
        var nameField = component.find("name");
        var posName = component.get("v.nameField");
        if($A.util.isEmpty(posName)){
            validPosition = false;
            nameField.set("v.errors", [{message:"name cant be blank"}]);
        }
        else
            nameField.set("v.errors", null);
        
        //responsibilities should not be blank
        var respField = component.find("responsibilities");
        var posResp = component.get("v.respField");
        if($A.util.isEmpty(posResp)){
            validPosition = false;
            respField.set("v.errors", [{message:"responsibilities cant be null"}]);
        }
        else
            respField.set("v.errors", null);
    
    
    //close Date cant be blank
    var closeDateField = component.find("closedate");
    var poscloseDate = component.get("v.closeDateField");
    if($A.util.isEmpty(poscloseDate)){
        validPosition = false;
    closeDateField.set("v.errors", [{message:"close date cant be blank"}]);
    }
    else
        closeDateField.set("v.errors", null);
        
        //Days Open should not be blank
        var daysOpenField = component.find("daysopen");
        var posdaysOpen = component.get("v.daysOpenField");
        if($A.util.isEmpty(posdaysOpen)){
            validPosition = false;
            daysOpenField.set("v.erros", [{message:"days open cant be blank"}]);
        }
        else
            daysOpenField.set("v.erros", null);
        
        //if error checking passed...excute the below code
        if(validPosition){
            //create new Position
            var newPosition = component.get("v.newPosition");
            console.log("create position : " +JSON.stringify(newPosition));
            helper.createPosition(component, newPosition);
        }
        
}
})

Following the is the apex class :- (for saving the position record)

public with sharing class PositionInputController {

@AuraEnabled
    public static list<Position__c> positionMethod1(){
        return [select Id, Name, Responsibilities__c, Apex__c, Close_Date__c, Days_Open__c, Hire_By__c, Max_Pay__c, Min_Pay__c from Position__c ];
    }

@AuraEnabled
    public static Position__c positionMethod2(Position__c pos){
        upsert pos;
        return pos;
    }
}

Following is the application code:-

<aura:application extends="force:slds">
    <div class="slds">
        <div class="slds-page-header">
            <div class="slds-grid">
                <p class="slds-text-heading--label"> Position Entry Form </p>
                <div class="slds-grid">
                    <p class="slds-text-heading--medium"> Position Items List </p>
                </div>
            </div>
        </div>
    </div>
    <c:PositionInputForm />
    
</aura:application>

the error on submit button is :
This page has an error. You might just need to refresh it. Action failed: c:PositionInputForm$controller$submitPosition [validPosition is not defined] Failing descriptor: {c:PositionInputForm$controller$submitPosition}

Any help will be appreciated. 
Thanks

Hi All,

 

I am having really tough time dealing with Salesforce Test classes.

 

My first problem is when I write a test class, then the class I am testing does not show up in Overall Code Coverage.

 

Then when I click on test the class does show up in Class Code Coverage and show me the coverage % but when I click on it it opens without the colors telling me which line is covered and which is not.

 

 

Please let me know how to resolve this.

 

Thanks.