• Rosendo Rodriguez
  • NEWBIE
  • 0 Points
  • Member since 2016

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

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
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 == ""){
location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&p24={!Case.Cons_Email__c};{!Case.Cons_2_Email__c};{!Case.Cons_3_Email__c}&template_id=00X60000004dTuo&p26=cons@gmail.com');
}
else if(flc == "PC-AF") {
location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&p24={!Case.Cons_Email__c};{!Case.Cons_2_Email__c};{!Case.Cons_3_Email__c}&template_id=00Xt0000000LxEP&p26=cons@gmail.com');
}
else if(flc != "PC-AF") {
location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Case.Id}&p2_lkid={!Case.ContactId}&p24={!Case.Cons_Email__c};{!Case.Cons_2_Email__c};{!Case.Cons_3_Email__c}&template_id=00Xt0000000LxEt&p26=cons@gmail.com');
}

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:
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")} 
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]); 
window.location.href=window.location.href;

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}"/>
</aura:component>

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:

@isTest
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,
                          Signed_SOW__c,Job_Setup__c,
                          Expected_SOW_Signed_Date__c,
                          Billing_Type__c,
                          Business_Developer__c,
                          Ultimate_Client__c,
                          Engagement_Name1__c,AccountId
                            FROM Opportunity WHERE Id = :o.Id];
        
        Test.startTest();
        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);
        Test.stopTest();
        system.assertEquals(true, response.isValid);
        system.debug('obj status '+response);
    }
}



Class :

@RestResource(urlMapping='/fetchOpportunities/')
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;
    }
    
      @HttpPost
    global static ResponseClass doGet(RequestClass req){
        
        ResponseClass response = new ResponseClass();
        List<Opportunity> lstOpp = new List<Opportunity>();
        try{
            //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
            else{
                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