• Rosendo Rodriguez
  • 0 Points
  • Member since 2016

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 3
Guys, i have a onclick javascript button that validates fields, uses different templates based on field values.

var ca = new sforce.SObject("Case");
var p = "{!Case.Cons__c}";
var email = "{!Case.Cons_Email__c}";
var email2 = "{!Case.Cons_2_Email__c}";
var email3 = "{!Case.Cons_3_Email__c}";
var flc = "{!Case.Topic__c}";

if((email =="")&&(email2 =="")&&(email3 ==""))
alert("Please select cons and make sure cons has email address ");
else if(flc == ""){
else if(flc == "PC-AF") {
else if(flc != "PC-AF") {

How to make this button work on lightning, can someone please share the code, thank you.
Hello! Thank you in advance for your assistance! I have been working on this for over 24 total changing the Controller and Component in small ways here and there to test and re-test, and I think I am going in circles at this point.

We have 8 custom Javascript buttons for our Cases - one per department. What these buttons do is allow the user to own the case with one click. It enters their name into a custom user lookup "owner" field for that department, updates their name to the standard Owner field, and updates the Status to Assigned. 

The current, working, custom JS button is:
var caseObj = new sforce.SObject("Case"); 
caseObj.Id = '{!Case.Id}'; 

caseObj.CST_Owner__c = '{!$User.Id}'; 
caseObj.OwnerId = '{!$User.Id}'; 
caseObj.Status = "Assigned"; 

var result = sforce.connection.update([caseObj]); 

My Case Buttons Component is currently - this shows on the page and allows for button clicks and will sometimes throw an error and sometimes not but makes no changes:
<aura:component implements="flexipage:availableForAllPageTypes" access="global">
    <aura:attribute name="CaseObj" type="Case" />
        <lightning:button label="Own CST" onclick="{! c.owncst}"/>

My Controller is currently:
owncst : function(component, event, helper) {
    var btnClicked = event.getSource();
    var CaseObj = component.get('v.CaseObj',true)
    component.set('v.CaseObj.Description', "true");
The below code is not covering both RequestClass & ResponseClass. Any help?

Test Class:

public class OpportunityDataResourceTest {
private static testMethod void doGetTest_Positive(){
           Opportunity o = BacklogGeneratorTestFactory.InsertOpportunity(Date.newInstance(2015,01,01), 2, true, 100);
        o = [SELECT Id,Services_Provided__c,StageName,
                            FROM Opportunity WHERE Id = :o.Id];
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        req.requestURI = '/services/apexrest/fetchOpportunities';  //Request URL
        req.httpMethod = 'POST';//HTTP Request Type
        OpportunityDataResource.RequestClass reqParam = new OpportunityDataResource.RequestClass();
        reqParam.opportunityId = String.valueOf(o.Id);
        String JsonMsg=JSON.serialize(reqParam);
        req.requestBody = Blob.valueof(JsonMsg);
        RestContext.request = req;
           RestContext.response= res;
        OpportunityDataResource.ResponseClass response = OpportunityDataResource.doGet(reqParam);
        system.assertEquals(true, response.isValid);
        system.debug('obj status '+response);

Class :

global with sharing class OpportunityDataResource {
    //request parameters from external system
    global class RequestClass{
        webservice String opportunityId;
    //response class to send it to external system
    global class ResponseClass{
        webservice String serviceCode;
        webservice String description;
        webservice Boolean isValid;
        //webservice List<Opportunity> lstOpptyToBeReturn;
    global static ResponseClass doGet(RequestClass req){
        ResponseClass response = new ResponseClass();
        List<Opportunity> lstOpp = new List<Opportunity>();
            //get the opptyId from request class
              String opptyId = String.escapeSingleQuotes(req.opportunityId);
            if(opptyId!=null && String.isNotBlank(opptyId.trim())){
                lstOpp = [Select Id,Name from Opportunity where Oppty_ID_For_Elite__c =: opptyId];
            //form the response if the list of opportunites are found in the system
            if(!lstOpp.isEmpty() && lstOpp.Size() == 1){
                response.isValid = true;
                response.serviceCode = 'Success-1';
                response.description = lstOpp.size()+' '+'opportunities found with Id - '+opptyId;
                return response;
            //form the response if the list of opportunites are found in the system
            else if(lstOpp.isEmpty()){
                response.isValid = false;
                response.serviceCode = 'Error-1';
                response.description = 'No opportunity found with Id - '+opptyId;
                return response;
            //form the response if the list of opportunites are not found with list error
                response.isValid = false;
                response.serviceCode = 'Error-2';
                response.description = 'No opportunity found.Please Contact salesforce system admin';
                return response;
        //exception handling for SOQL query
        Catch(System.QueryException e){
            response.serviceCode = 'Error-1';
            response.description = 'Query exception : '+e+' found.Please Contact system admin';
            return response;
        //exception handling other than SOQL
        Catch(Exception e){
          response.serviceCode = 'Error-2';
            response.description = 'Exception : '+e+' occured.Please Contact system admin';
            return response;  
  • March 10, 2017
  • Like
  • 0