• Eric Blaxton 11
  • NEWBIE
  • 60 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 9
    Replies
Hi and thanks in advance for any help on this...

The bold part works fine.  If a user selects one of those values for 
Credit_Card_Communication__c  and either /or of these fields is null (Comm_Options__c, Comm_Payment_Plan__c). The error message pops up.
The issue is when I choose another value for Credit Card Communication 'TBD' and either (Comm_Options__c, Comm_Payment_Plan__c) is null

I want to say if Credit Card Communication = TBD and those 2 fields are null, then no error is thrown.  



if( $User.ProfileId != '1' && $User.ProfileId != '2'&& $User.ProfileId != '3' ,
ISPICKVAL( Division__c , 'Distributor')
&&
ISPICKVAL( Type__c, 'Retail Outlet')
&&
if(IsConverted__c,false,true)
&&
not(ischanged(IsConverted__c))
&&
(
(ISPICKVAL(Credit_Card_Communication__c, '1') &&
ISPICKVAL(Comm_Options__c, '') ||
ISPICKVAL(Comm_Payment_Plan__c , '') ) ||
(ISPICKVAL(Credit_Card_Communication__c, '2') &&
ISPICKVAL(Comm_Options__c, '') ||
ISPICKVAL(Comm_Payment_Plan__c , '') ) ||
(ISPICKVAL(Credit_Card_Communication__c, '3') &&
ISPICKVAL(Comm_Options__c, '') ||
ISPICKVAL(Comm_Payment_Plan__c , '') ) ||
(ISPICKVAL(Credit_Card_Communication__c, '4') &&
ISPICKVAL(Comm_Options__c, '') ||
ISPICKVAL(Comm_Payment_Plan__c , '') ) ||
(ISPICKVAL(Credit_Card_Communication__c, '5') &&
ISPICKVAL(Comm_Options__c, '') ||
ISPICKVAL(Comm_Payment_Plan__c , '') )
||
ISPICKVAL(Type_of_Operation__c, '') ||
ISPICKVAL(Distributor_Account_Type__c, '') ||
isblank(Current_Supplier__c) ||
ISPICKVAL(Current_Brand__c, '') ||
ISPICKVAL(Terminal_State__c, '') ||
ISPICKVAL(Primary_Terminal__c, '') ||
ISPICKVAL(Dispenser_Type__c, '') ||
isblank(Diesel_Dispensers__c) ||
isblank(Gas_Dispensers__c) ||
isblank(Combo_Dispensers__c) ||
ISPICKVAL(CC_Velocity__c, '') ||
ISPICKVAL(Zip_Code_Verification__c, '') ||
isblank(of_Registers_POS__c) ||
isblank(Control_System__c) ||
ISPICKVAL(Loyalty_Status__c, '') ||
isblank(Hours_of_Operation__c)
|| ISPICKVAL(Public_Restrooms__c ,'')
),false)

Eric
Hi and thanks in advance for any pointers here.

Issue:  I created an Action button on the CASE object that calls a Lightning component.  When I click on the Add button, then click the Cancel button, the Add button is no longer there.  I have to click on another tab and then go back to the Case and then the Add button is there.

My component:
<aura:component controller="newCheckRequest" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes" >
    <!--This controls the display of the New Check Request action screen, before the New CR screen.  It supresses it.   -->
    <aura:html tag="style">
        .slds-backdrop {
        background: rgba(43, 40, 38, 0) !important;  
        }
      <!--  .slds-fade-in-open {
        display:none !important;-->
        
    </aura:html>  
    <aura:attribute name="cre" type="Check_Request__c"/>     
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

My Controller:
({
    doInit : function(component, event, helper)
    {
       var action = component.get("c.getCase");
       action.setParams({"caseId": component.get("v.recordId")});
       action.setCallback(this, function(response)
       {
        var state = response.getState();
    
       if(component.isValid() && state === "SUCCESS") 
        {
        var  cre = response.getReturnValue();        
                 
            // create method in helper class
            // Putting RT first changes header of the pop up
            var createCrEvent = $A.get("e.force:createRecord");
            var crid=component.get("v.recordId");
            console.log('cre-'+cre);
            createCrEvent.setParams
             ({
                "entityApiName": "Check_Request__c",
                "defaultFieldValues":
                {
                    'Check_RequestRelTo__c' : cre.Id
                  
                }
              });
            createCrEvent.fire(); 
        }
                         
});          
       
     $A.enqueueAction(action);
      // $A.get("e.force:closeQuickAction").fire();
    }        
})

My Helper class: Not really needed, but maybe in the future
({
 toastMessage : function(msg) 
    {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams
        ({
            title : 'Warning',
            message: msg,
            duration:' 5000',
            key: 'info_alt',
            type: 'error',
            mode: 'dismissible'
        });
        toastEvent.fire();
 }
})

My Apex class: to get the record id

public with sharing class newCheckRequest
{
 @AuraEnabled
    public static Case getCase(Id caseId) 
    {
        //Query fields from Parent record to prepopulate New CheckRequest
        return [SELECT Id,CaseNumber FROM Case where id = :caseId];     
    }
}

Thanks,
Eric
Hi and thanks in advance.

We are converting a url button to Lightning component.  I can get the url button to work in Lightning, but I don't have the control over pre populating fields etc.  I want to clear out a few fields.  This is a Clone account button which fires an Apex Class.  

The error I get when clicking the Action button is "Error while creating component for lightning component quick action [Unable to find action 'getAccount' on the controller of c:Clone]"

Please advise on where i went wrong.


I wrote a component

<aura:component controller="CloneAcctBtn" implements="force:lightningQuickActionWithoutHeader,lightning:isUrlAddressable,force:hasRecordId,lightning:hasPageReference,force:appHostable,flexipage:availableForAllPageTypes" >
    <!--This controls the display of the New RTO Quick action screen, before the New Account screen.  It supresses it.   
    <aura:html tag="style">
        .slds-backdrop {
        background: rgba(43, 40, 38, 0) !important;  
        }
        .slds-fade-in-open {
        display:none !important;
        }
    </aura:html>-->
    <aura:attribute name="acc" type="Account"/>     
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />    
         
</aura:component>

Controller:

({
    doInit : function(component, event, helper) 
    {
      var userId = $A.get("$SObjectType.CurrentUser.Id");   
      var action = component.get("c.getAccount");
      action.setParams({"accountId": component.get("v.recordId")});
      action.setCallback(this, function(response){
      var state = response.getState();   
     
      if(component.isValid() && state === "SUCCESS")
       {
        var  acc = response.getReturnValue(); 
        var createAcountEvent = $A.get("e.force:createRecord");
        var accid=component.get("v.recordId");
            
        console.log('accid-'+accid);
          //example set
          createAcountEvent.setParams({
              "entityApiName": "Account",
              "defaultFieldValues":{
          'Name': acc.sObjectInfo.Name,  
          'DataSrc__cSave' : acc.sObjectInfo.DataSrc__c, 
          'CMF_Bill_To_DUNS_Number__cSave' : acc.sObjectInfo.CMF_Bill_To_DUNS_Number__c,
          'Federal_Tax_ID_Number__cSave' : acc.sObjectInfo.Federal_Tax_ID_Number__c,
          'AccountNumberSave' : acc.sObjectInfo.AccountNumber
              }    
       });

        createAcountEvent.fire(); 
                    
        } 
        else
        {
        //write toast message replace the console.log
        helper.toastMessage('Problem getting account, response state');
        //console.log('Problem getting account, response state: ' + state);
        }
        });
        $A.enqueueAction(action);
    }
                    
 })

Class
    public with sharing class CloneAcctBtn {
@AuraEnabled
    public Account a;
    Map<String, Schema.SObjectField> m1 = Schema.SObjectType.Account.fields.getMap();
    string oldRecType;
    
    public CloneAcctBtn(ApexPages.StandardController stdController) {
        this.a = (Account)stdController.getRecord();
        oldRecType = a.RecordTypeId;
    
    }

    
    public Pagereference acctCloned(){//Account acct
        //find all record types
        List<Schema.RecordTypeInfo> infos = Schema.SObjectType.Account.RecordTypeInfos;
        Id defaultRecordTypeId;
        integer i = 0;
        
        String theId = ApexPages.currentPage().getParameters().get('id');
        system.debug(a + ' '+ theID);
        //a = [select id, name, BillingStreet from Account where id =:theId];
        
        /* query lead and then clone it */
        String soql = GrabUpdateableFieldsUtil.getCreatableFieldsSOQL('Account','id=\''+theId+'\'');
        if(Test.isRunningTest())
            System.debug('SOQL for clone: ' + soql);
        a = (Account)Database.query(soql);
        
        // Do all the dirty work we need the code
        Account clonedAcc = a.clone(false,true,false,false);
        
        //check each one
        for (Schema.RecordTypeInfo info : infos) {
            i++;
            if (info.DefaultRecordTypeMapping && info.isAvailable()) {
                defaultRecordTypeId = info.RecordTypeId;
            }
            
        }
        
        for(String fieldName : m1.keySet()) {
            if(m1.get(fieldName).getDescribe().isUpdateable()) {
                system.debug(m1.get(fieldName) + ' ' +m1.get(fieldName).getDescribe().getType() + ' '+m1.get(fieldName).getDescribe() );
                
                //get data types for each fields
                Schema.DisplayType fielddataType = m1.get(fieldName).getDescribe().getType();

                if(fielddataType  == Schema.DisplayType.Integer)
                {
                    clonedAcc.put(fieldName , 0);
                }
                else if(fielddataType != Schema.DisplayType.DateTime){
                    continue;
                }
                else if(fielddataType != Schema.DisplayType.Date){
                    clonedAcc.put(fieldName , date.valueof(system.today()));
                }
                else if(fielddataType != Schema.DisplayType.Double){
                    clonedAcc.put(fieldName , 0.0);
                }
                else if(fielddataType != Schema.DisplayType.Boolean){
                    clonedAcc.put(fieldName , true);
                }
                //else if(fielddataType != Schema.DisplayType.String){
                   // clonedAcc.put(fieldName , '');
               // }
                else
                   clonedAcc.put(fieldName , 'Some Value');
            }
        }
        //here is the default RecordType Id for the current user
        System.debug(defaultRecordTypeId);
        if(oldRecType != defaultRecordTypeId)
        {
            clonedAcc.Type__c = '';
        }
        clonedAcc.OwnerID = userinfo.getUserID();
        clonedAcc.Account_Status__c = 'Prospect';
        clonedAcc.RecordTypeId = defaultRecordTypeId;
        clonedAcc.ExternalSysID__c = ''; 
        clonedAcc.Bill_To_DUNs_Number__c = '';
        clonedAcc.accountnumber = '';
        clonedAcc.CMF_Bill_To_DUNS_Number__c = '';
        clonedAcc.CMF_Ship_To_DUNS_Number__c = '';
        
        insert clonedAcc;
        //System.assertEquals(a, clonedAcc); to do
        

        //Redirect the user back to the original page
        PageReference pageRef = new PageReference('/' + clonedAcc.id); 
        pageRef.setRedirect(true);
        return pageRef;   
        
        
    }

}
Hi and thanks in advance for your help.  I wrote this test and can't figure out why I can't get any coverage.  Seems so simple.

public with sharing class AccountStatus
{

 @AuraEnabled

    public static Account getAccount(Id accountId)

    {

        //Query fields from Parent record to prepopulate New RTO

        return [SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :accountId];    

    }

}


Test class

@isTest
private class AccountStatusTest

{

   

    static testMethod void getAccount()

    {

        Account a = new Account();

        a.name='Test';

        a.phone='12345';        

        a.Account_Status__c = 'Active Account';

        a.Bill_To_DUNs_Number__c = '1234567890';

        a.BillingCountry = 'United States';

        a.BillingStreet = 'Main Street';

        a.BillingCity = 'Dallas';

        a.BillingState = 'Texas';

        a.BillingPostalCode = '76543';

        a.Billing_County__c = 'Blackland';

        a.BillingStateCode = 'TX';

        a.Legal_Entity_Name__c = 'TestParent';

        a.Type__c = 'Retail Outlet';

       // a.Account_Record_ID__c = '0120W000001USkRQAW';

        a.Current_Brand__c = 'Sunoco';

        insert a;

       

        Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :a.id];

        System.assert(a2!=null);        

    }    

}

Thank You,
Eric

 
Hi and thank in advance.
We are migrating to lightning and i have a few javascript buttons to convert.  
Js button "if("{!Account.Account_Status__c}"!="Active Account")
window.alert("You can create an RTO for an active Distributor only.");
else{
window.open

//prepopulate fields.

}"


I created an Aura Component to display a Modal popup.  What I want to do is have an if / else statement

User clicks on Action: New Child record.  If the Account status != Active, display Modal "you can only create child record on Active account.  

If the Account status = Active then proceed with creating a new record.  Then prepopulate some values on the new record.

Component
<aura:component implements="force:lightningQuickAction" >
    <!--Boolean attribute to indicate if modal is open or not 
       default value is false as modal is closed when page is loaded 
    -->
    <aura:attribute name="isModalOpen" type="boolean" default="false"/>
    
    <!--Display modal based on Account status.  If not active, display. Else prepopulate fields 
    -->
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name = "Account_Status__c" type="String"/>
    <aura:attribute name="passThroughValue" type="String"/>
    
    <lightning:card title="{!v.passThroughValue}">
  
    </lightning:card>
                    
    <div class="slds-m-around_xx-large">
             <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>
                            You can create an RTO for an active Distributor only.
                            </b>
                        </p>
                    </div>

        <!--Use aura:if tag to display/hide popup based on isModalOpen value-->  
        <aura:if isTrue="{!v.Account_Status__c}">
        <aura:if isTrue="{!v.isModalOpen}">
             
            <!-- Modal/Popup Box starts here-->
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <!-- Modal/Popup Box Header Starts here-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
                                              onclick="{! c.closeModel }"
                                              alternativeText="close"
                                              variant="bare-inverse"
                                              class="slds-modal__close"/>
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Modal/PopUp Box</h2>
                    </header>
                    
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </aura:if>
            </aura:if>
    </div>
</aura:component>

Controller:
({    
   openModel: function(component, event, helper) {
      // Set isModalOpen attribute to true
      component.set("v.isModalOpen", true);
   },
  
   closeModel: function(component, event, helper) {
      // Set isModalOpen attribute to false  
      component.set("v.isModalOpen", false);
   },
  
   submitDetails: function(component, event, helper) {
      // Set isModalOpen attribute to false
      //Add your code to call apex method or do some processing
      component.set("v.isModalOpen", false);
   }, 
    }   )

Is this possible?

 
I need guidance in creating an app, installing an app or something that allows for a scrolling news feed relating to the account.
Hi and thanks in advance for any guidance on this.  
I want to take in-person classroom training to learn APEX and VF in the Dallas, Texas area. 
So far I have found:
  • virtual training with live teacher
  • online training study at my own pace
  • Travel to take classes offered by Salesforce. which is expensive.
Hi and thanks in Advance.  I was able to write a test code for my class, but need help.  This provides 5% coverage.

Class:
global with sharing class TMWSendOrderService 
{
    public class OrderResponse 
    {
        string OrderNumber;
        List<string> Comments = new List<string>();
        List<string> Errors = new List<string>();
        string CaseNumber;
    }
  
  public class FuelOrdered 
    {
    string Type;
    integer Amount;
  }
    
    public class TmwOrder 
    {
        string CaseNumber;
        Date DeliveryDate;
        string DeliveryTimeframe;
        string CompanyCode;
        string Origin;
    List<FuelOrdered> FuelList = new List<FuelOrdered>();
    List<string> ErrorsFound = new List<string>();
    }
  
    webservice static String SendToTmw(string cid) 
    {
    system.debug('cid: ' + cid);
        return SendOrderToTmw(cid);
    }
  
    private static string SendOrderToTmw(string cid)
    {

        if(String.isBlank(cid))
            return 'INVALID_PARAMETERS';
        
        // get list of cases that have not yet been sent to TMW and have a valid quantity
    List<Case> sfCases = [ SELECT Id, AccountId, CaseNumber, Origin, 
        RQ_Delivery_Date__c, RQ_Delivery_Timeframe__c, 
        Fuel1_Requested_Type__c, Fuel1_Requested_Amount__c, 
        Fuel2_Requested_Type__c, Fuel2_Requested_Amount__c, 
        Fuel3_Requested_Type__c, Fuel3_Requested_Amount__c, 
        Fuel4_Requested_Type__c, Fuel4_Requested_Amount__c
      FROM Case WHERE id = :cid 
      AND TMW_Order_Num__c = '' //AND SendtoTMW__c = false 
      AND ( 
        Fuel1_Requested_Amount__c > 0 OR Fuel2_Requested_Amount__c > 0 
                OR Fuel3_Requested_Amount__c > 0 OR Fuel4_Requested_Amount__c > 0 
            ) ]; 
        // Instantiate a new http object.  Create a list of cases and send to REST service
        if(sfCases.size() == 0)
            return 'This case requires: valid quantity, requested delivery time and timeframe, and cannot be a resubmission.';
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        Case sfCase = sfCases[0];
    // get company  code from translation table
    string companyCode = 
        [  
          SELECT Surrogate_ID__c FROM Translation_Table__c 
          WHERE IntegratedSite__c = :sfCase.AccountId LIMIT 1
        ].Surrogate_ID__c.replace('TMW-','');
        // populate case
        TmwOrder tmwOrder = new TmwOrder();
        tmwOrder.CaseNumber = sfCase.casenumber;
        tmwOrder.DeliveryDate = sfCase.RQ_Delivery_Date__c;
        tmwOrder.DeliveryTimeframe = sfCase.RQ_Delivery_Timeframe__c;
        tmwOrder.CompanyCode = companyCode;
        tmwOrder.Origin = sfCase.Origin;
        FuelOrdered item = new FuelOrdered();
        // create FuelOrdered list from requested types/amounts
        item.Type = sfCase.Fuel1_Requested_Type__c;
        item.Amount = Integer.valueOf(sfCase.Fuel1_Requested_Amount__c);
        if (item.Amount > 0) tmwOrder.FuelList.Add(item);
        item = new FuelOrdered();
        item.Type = sfCase.Fuel2_Requested_Type__c;
        item.Amount = Integer.valueOf(sfCase.Fuel2_Requested_Amount__c);
        if (item.Amount > 0) tmwOrder.FuelList.Add(item);
        item = new FuelOrdered();
        item.Type = sfCase.Fuel3_Requested_Type__c;
        item.Amount = Integer.valueOf(sfCase.Fuel3_Requested_Amount__c);
        if (item.Amount > 0) tmwOrder.FuelList.Add(item);
        item = new FuelOrdered();
        item.Type = sfCase.Fuel4_Requested_Type__c;
        item.Amount = Integer.valueOf(sfCase.Fuel4_Requested_Amount__c);
        if (item.Amount > 0) tmwOrder.FuelList.Add(item);
        string postString = JSON.serialize(tmwOrder);
        req.setBody(postString);
        req.setEndpoint('http://dev-tmw.sunocolp.com/api/CreateTMWOrder');
        req.setHeader('content-type','application/json');
        req.setTimeout(60000);
        req.setMethod('POST');
        //req.setCompressed(true);
        // Send the request, and return a response
        HttpResponse res = h.send(req);
        string bod = res.getBody();
        system.debug(bod);
        OrderResponse rsp = (OrderResponse)JSON.deserialize(bod, OrderResponse.class);
        system.debug('order response: ' + rsp);
        Case newCase;
        if (rsp.OrderNumber != null && rsp.OrderNumber !='')
        {
            // If Order was created, add order # to the case
            newCase = 
      [  
        Select Id, TMW_Order_Num__c, SFtoTMWSent__c, SendtoTMW__c  
                FROM Case 
                WHERE CaseNumber = :rsp.CaseNumber
            ];
            newCase.TMW_Order_Num__c = rsp.OrderNumber;
            newCase.SendtoTMW__c = true;
            newCase.SFtoTMWSent__c = date.today();
            update newCase;
        }
        else
        {
            // No order # was returned.  Mark case as sent to TMW.
            newCase = 
            [  
                 SELECT Id, SFtoTMWSent__c, SendtoTMW__c  
                 FROM Case 
                 WHERE CaseNumber = :rsp.CaseNumber
            ];
            newCase.SendtoTMW__c = true;
            newCase.SFtoTMWSent__c = date.today();
            update newCase;
        }
        // add case comments (if any)
        for (Integer i = 0; i < rsp.Comments.size(); i++)
        {
            CaseComment com = new CaseComment();
            com.ParentId = newCase.id;
            com.CommentBody = rsp.Comments[i];
            insert com;
        }        
        return 'Order submitted successfully!';
    }
}
---------------------------
Test Class:
@isTest
 
private class TMWSendOrderService_Test{
 
  @testSetup
 
  static void setupTestData(){
 
    test.startTest();
 
    Translation_Table__c translation_table_Obj = new Translation_Table__c(Integration_Status__c = false);
 
    Insert translation_table_Obj; 
 
    test.stopTest();
 
  }
 
   static testMethod void test_TmwOrder(){
 
    List<Translation_Table__c> translation_table_Obj  =  [SELECT Integration_Status__c, Name from Translation_Table__c];
 
    System.assertEquals(true,translation_table_Obj.size()>0);
 
    TMWSendOrderService obj01 = new TMWSendOrderService();
 
    TMWSendOrderService.OrderResponse obj11 = new TMWSendOrderService.OrderResponse();
 
    TMWSendOrderService.FuelOrdered obj21 = new TMWSendOrderService.FuelOrdered();
 
    TMWSendOrderService.TmwOrder obj31 = new TMWSendOrderService.TmwOrder();
 
  }
 
}

 
Hi and thanks for any help or direction.

1. Please tell me if this is good Apex class.  By good I mean, up to SF best practices, bulkification etc.
2. I need help in writing a test class.  

@RestResource(urlMapping='/TmwCaseUpdates/v1/*')

global class TmwCaseUpdates 
{

    global class OrderResponse 
    {
        string OrderNumber;
        List<string> Comments = new List<string>();
        List<string> Errors = new List<string>();
        string CaseNumber;
    }
    
  global class FuelOrderItem
    {
        string FuelOrderNumber;
        string FuelType;
        string CaseNumber;
        long FuelOrderedAmount;
        long FuelDeliveredAmount;
    }
    
  global class SalesforceUpdateCase
    {
        string Status;
        string FuelOrderStatus;
        string TMWOrderNumber;
        DateTime DeliveredTime;
        DateTime CarrierConfirmDateTime;
        string[] CaseComments;
        List<FuelOrderItem> FuelOrderItems;
        string NotifiedDate;
        string CreditAlertType;
        Date RequestDeliveryDate;
        string RequestDeliveryTimeframe;
        string Description;
        string Subject;
        string CompanyCode;
        string Origin;
    long QuantityDelivered;
    long QuantityRequested;
    }
    
    global static string GetAccountID(string companyId)
    {
        string cmpID = 'TMW-' + companyId;
        string accountID = [SELECT IntegratedSite__c FROM Translation_Table__c where Surrogate_ID__c='TMW-JMJHOR01' LIMIT 1].Id;
        return accountID;
    }
    
    @HttpPost
    global static List<OrderResponse> UpdateOrders()
    {
        string requestBody = RestContext.request.requestBody.tostring();
        System.debug('input data is ' + requestBody);
        List<SalesforceUpdateCase> updOrders = (List<SalesforceUpdateCase>)JSON.deserialize(requestBody, List<SalesforceUpdateCase>.class);
        System.debug(updOrders);
        // create OrderResponse list to be returned to the caller
        List<OrderResponse> orderList = new List<OrderResponse>();
        // loop through SalesforceUpdateCase objects.  Create new cases for valid orders.  Return any case comments
        for (SalesforceUpdateCase theOrder : updOrders)        
        {
            OrderResponse theResponse = new OrderResponse();
            List<Case> theCases = new List<Case>();
            theCases =   [ select id, status, AccountId, TMW_Order_Num__c, CaseNumber, Fuel_Order_Status__c 
                         FROM case WHERE TMW_Order_Num__c = :theOrder.TMWOrderNumber ];
            System.debug('order # is ' + theOrder.TMWOrderNumber);
            if (theCases.size() > 1)
            {
                theResponse.Errors.Add('Case ' + theCases[0].CaseNumber + 'for TMW Order ' + theOrder.TMWOrderNumber + ' already exists');
                System.debug('Case ' + theCases[0].CaseNumber + 'for TMW Order ' + theOrder.TMWOrderNumber + ' already exists');
                theResponse.OrderNumber = theOrder.TMWOrderNumber;
                theResponse.CaseNumber = theCases[0].CaseNumber;
                orderList.Add(theResponse);
            } else if (theCases.size() == 0)
            {
                // Create new SF case
                Case newCase = new Case();
        newCase.Status = theOrder.Status;
        newCase.Fuel_Order_Status__c = theOrder.FuelOrderStatus;
        newCase.TMW_Order_Num__c = theOrder.TMWOrderNumber;
        newCase.TMWSentDt__c = Date.today();
        newCase.Credit_Alert_Type__c = theOrder.CreditAlerttype;
                newCase.Delivered_Time__c = theOrder.DeliveredTime;
                // Get the company code from the translation table. Company codes are stored as TMW-xxxxx
                string translatedCompanyCode = 'TMW-' + theOrder.CompanyCode;
                System.debug(translatedCompanyCode);
                newCase.AccountId = [SELECT IntegratedSite__c 
                                     FROM Translation_Table__c 
                                     WHERE Surrogate_ID__c = :translatedCompanyCode].IntegratedSite__c;
                newCase.RQ_Delivery_Timeframe__c = theOrder.RequestDeliveryTimeframe;
                newCase.RQ_Delivery_Date__c = theOrder.RequestDeliveryDate;
                newCase.Origin = theOrder.Origin;
                integer i = 0;
                for (FuelOrderItem item : theOrder.FuelOrderItems)
                {
                    i++;
                    switch on i
                    {
                        when 1 
                        {
                            newCase.Fuel1_Requested_Type__c = item.FuelType;
                            if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel1_Delivered_Type__c = item.FuelType;
                                newCase.Fuel1_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }
                        }
                        when 2 
                        {
                            newCase.Fuel2_Requested_Type__c = item.FuelType;
                            if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel2_Delivered_Type__c = item.FuelType;
                                newCase.Fuel2_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }                            
                        }
                        when 3 
                        {
                            newCase.Fuel3_Requested_Type__c = item.FuelType;
                            if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel3_Delivered_Type__c = item.FuelType;
                                newCase.Fuel3_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }                                            
                        }
                        when 4 
                        {
                            newCase.Fuel4_Requested_Type__c = item.FuelType;
              if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel4_Delivered_Type__c = item.FuelType;
                                newCase.Fuel4_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }                
                        }
                    }
                }
                System.debug('about to insert case');
        Insert newCase;
        theResponse.OrderNumber = theOrder.TMWOrderNumber;
        theResponse.CaseNumber = newCase.CaseNumber;
        orderList.Add(theResponse);
            }
      else
            {
                // Update existing case
                Case updCase = theCases[0];
                if (updCase.Fuel_Order_Status__c != theOrder.FuelOrderStatus)
                {
                    updCase.Status = theOrder.Status;
                    updCase.Fuel_Order_Status__c = theOrder.FuelOrderStatus;
                    updCase.TMW_Order_Num__c = theOrder.TMWOrderNumber;
                    updCase.TMWSentDt__c = Date.today();
                    updCase.Credit_Alert_Type__c = theOrder.CreditAlerttype;
                    // update Delivered fields for completed orders
                    if (theOrder.FuelOrderStatus == 'Delivered')
                    {
                        for (FuelOrderItem item : theOrder.FuelOrderItems)
            {
                            if (updCase.Fuel1_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel1_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
                            else if (updCase.Fuel2_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel2_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
                            else if (updCase.Fuel3_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel3_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
                            else if (updCase.Fuel4_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel4_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
            }
                        updCase.Delivered_Time__c = theOrder.DeliveredTime;
                        updCase.Carrier_Confirm_Date_Time__c = theOrder.CarrierConfirmDateTime;
                    }
                    System.debug('about to update case');
            Update updCase;
                    theResponse.OrderNumber = theOrder.TMWOrderNumber;
                    theResponse.CaseNumber = updCase.CaseNumber;
                    orderList.Add(theResponse);
                }
            }            
        }
        return orderList;
    }
}
 
Hi and thanks in advance for any pointers here.

Issue:  I created an Action button on the CASE object that calls a Lightning component.  When I click on the Add button, then click the Cancel button, the Add button is no longer there.  I have to click on another tab and then go back to the Case and then the Add button is there.

My component:
<aura:component controller="newCheckRequest" implements="force:lightningQuickActionWithoutHeader,force:hasRecordId,force:appHostable,flexipage:availableForAllPageTypes" >
    <!--This controls the display of the New Check Request action screen, before the New CR screen.  It supresses it.   -->
    <aura:html tag="style">
        .slds-backdrop {
        background: rgba(43, 40, 38, 0) !important;  
        }
      <!--  .slds-fade-in-open {
        display:none !important;-->
        
    </aura:html>  
    <aura:attribute name="cre" type="Check_Request__c"/>     
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

My Controller:
({
    doInit : function(component, event, helper)
    {
       var action = component.get("c.getCase");
       action.setParams({"caseId": component.get("v.recordId")});
       action.setCallback(this, function(response)
       {
        var state = response.getState();
    
       if(component.isValid() && state === "SUCCESS") 
        {
        var  cre = response.getReturnValue();        
                 
            // create method in helper class
            // Putting RT first changes header of the pop up
            var createCrEvent = $A.get("e.force:createRecord");
            var crid=component.get("v.recordId");
            console.log('cre-'+cre);
            createCrEvent.setParams
             ({
                "entityApiName": "Check_Request__c",
                "defaultFieldValues":
                {
                    'Check_RequestRelTo__c' : cre.Id
                  
                }
              });
            createCrEvent.fire(); 
        }
                         
});          
       
     $A.enqueueAction(action);
      // $A.get("e.force:closeQuickAction").fire();
    }        
})

My Helper class: Not really needed, but maybe in the future
({
 toastMessage : function(msg) 
    {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams
        ({
            title : 'Warning',
            message: msg,
            duration:' 5000',
            key: 'info_alt',
            type: 'error',
            mode: 'dismissible'
        });
        toastEvent.fire();
 }
})

My Apex class: to get the record id

public with sharing class newCheckRequest
{
 @AuraEnabled
    public static Case getCase(Id caseId) 
    {
        //Query fields from Parent record to prepopulate New CheckRequest
        return [SELECT Id,CaseNumber FROM Case where id = :caseId];     
    }
}

Thanks,
Eric
Hi and thanks in advance for your help.  I wrote this test and can't figure out why I can't get any coverage.  Seems so simple.

public with sharing class AccountStatus
{

 @AuraEnabled

    public static Account getAccount(Id accountId)

    {

        //Query fields from Parent record to prepopulate New RTO

        return [SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :accountId];    

    }

}


Test class

@isTest
private class AccountStatusTest

{

   

    static testMethod void getAccount()

    {

        Account a = new Account();

        a.name='Test';

        a.phone='12345';        

        a.Account_Status__c = 'Active Account';

        a.Bill_To_DUNs_Number__c = '1234567890';

        a.BillingCountry = 'United States';

        a.BillingStreet = 'Main Street';

        a.BillingCity = 'Dallas';

        a.BillingState = 'Texas';

        a.BillingPostalCode = '76543';

        a.Billing_County__c = 'Blackland';

        a.BillingStateCode = 'TX';

        a.Legal_Entity_Name__c = 'TestParent';

        a.Type__c = 'Retail Outlet';

       // a.Account_Record_ID__c = '0120W000001USkRQAW';

        a.Current_Brand__c = 'Sunoco';

        insert a;

       

        Account a2=[SELECT Id, Name, Account_Status__c, Bill_To_DUNs_Number__c,  

                BillingCountry,BillingStreet,BillingCity,BillingState,BillingPostalCode,

                Billing_County__c,BillingStateCode,Legal_Entity_Name__c,Type__c,Account_Record_ID__c,

                Current_Brand__c

                FROM Account where id = :a.id];

        System.assert(a2!=null);        

    }    

}

Thank You,
Eric

 
Hi and thank in advance.
We are migrating to lightning and i have a few javascript buttons to convert.  
Js button "if("{!Account.Account_Status__c}"!="Active Account")
window.alert("You can create an RTO for an active Distributor only.");
else{
window.open

//prepopulate fields.

}"


I created an Aura Component to display a Modal popup.  What I want to do is have an if / else statement

User clicks on Action: New Child record.  If the Account status != Active, display Modal "you can only create child record on Active account.  

If the Account status = Active then proceed with creating a new record.  Then prepopulate some values on the new record.

Component
<aura:component implements="force:lightningQuickAction" >
    <!--Boolean attribute to indicate if modal is open or not 
       default value is false as modal is closed when page is loaded 
    -->
    <aura:attribute name="isModalOpen" type="boolean" default="false"/>
    
    <!--Display modal based on Account status.  If not active, display. Else prepopulate fields 
    -->
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name = "Account_Status__c" type="String"/>
    <aura:attribute name="passThroughValue" type="String"/>
    
    <lightning:card title="{!v.passThroughValue}">
  
    </lightning:card>
                    
    <div class="slds-m-around_xx-large">
             <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
                        <p><b>
                            You can create an RTO for an active Distributor only.
                            </b>
                        </p>
                    </div>

        <!--Use aura:if tag to display/hide popup based on isModalOpen value-->  
        <aura:if isTrue="{!v.Account_Status__c}">
        <aura:if isTrue="{!v.isModalOpen}">
             
            <!-- Modal/Popup Box starts here-->
            <section role="dialog" tabindex="-1" aria-labelledby="modal-heading-01" aria-modal="true" aria-describedby="modal-content-id-1" class="slds-modal slds-fade-in-open">
                <div class="slds-modal__container">
                    <!-- Modal/Popup Box Header Starts here-->
                    <header class="slds-modal__header">
                        <lightning:buttonIcon iconName="utility:close"
                                              onclick="{! c.closeModel }"
                                              alternativeText="close"
                                              variant="bare-inverse"
                                              class="slds-modal__close"/>
                        <h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Modal/PopUp Box</h2>
                    </header>
                    
                </div>
            </section>
            <div class="slds-backdrop slds-backdrop_open"></div>
        </aura:if>
            </aura:if>
    </div>
</aura:component>

Controller:
({    
   openModel: function(component, event, helper) {
      // Set isModalOpen attribute to true
      component.set("v.isModalOpen", true);
   },
  
   closeModel: function(component, event, helper) {
      // Set isModalOpen attribute to false  
      component.set("v.isModalOpen", false);
   },
  
   submitDetails: function(component, event, helper) {
      // Set isModalOpen attribute to false
      //Add your code to call apex method or do some processing
      component.set("v.isModalOpen", false);
   }, 
    }   )

Is this possible?

 
I need guidance in creating an app, installing an app or something that allows for a scrolling news feed relating to the account.
Hi and thanks for any help or direction.

1. Please tell me if this is good Apex class.  By good I mean, up to SF best practices, bulkification etc.
2. I need help in writing a test class.  

@RestResource(urlMapping='/TmwCaseUpdates/v1/*')

global class TmwCaseUpdates 
{

    global class OrderResponse 
    {
        string OrderNumber;
        List<string> Comments = new List<string>();
        List<string> Errors = new List<string>();
        string CaseNumber;
    }
    
  global class FuelOrderItem
    {
        string FuelOrderNumber;
        string FuelType;
        string CaseNumber;
        long FuelOrderedAmount;
        long FuelDeliveredAmount;
    }
    
  global class SalesforceUpdateCase
    {
        string Status;
        string FuelOrderStatus;
        string TMWOrderNumber;
        DateTime DeliveredTime;
        DateTime CarrierConfirmDateTime;
        string[] CaseComments;
        List<FuelOrderItem> FuelOrderItems;
        string NotifiedDate;
        string CreditAlertType;
        Date RequestDeliveryDate;
        string RequestDeliveryTimeframe;
        string Description;
        string Subject;
        string CompanyCode;
        string Origin;
    long QuantityDelivered;
    long QuantityRequested;
    }
    
    global static string GetAccountID(string companyId)
    {
        string cmpID = 'TMW-' + companyId;
        string accountID = [SELECT IntegratedSite__c FROM Translation_Table__c where Surrogate_ID__c='TMW-JMJHOR01' LIMIT 1].Id;
        return accountID;
    }
    
    @HttpPost
    global static List<OrderResponse> UpdateOrders()
    {
        string requestBody = RestContext.request.requestBody.tostring();
        System.debug('input data is ' + requestBody);
        List<SalesforceUpdateCase> updOrders = (List<SalesforceUpdateCase>)JSON.deserialize(requestBody, List<SalesforceUpdateCase>.class);
        System.debug(updOrders);
        // create OrderResponse list to be returned to the caller
        List<OrderResponse> orderList = new List<OrderResponse>();
        // loop through SalesforceUpdateCase objects.  Create new cases for valid orders.  Return any case comments
        for (SalesforceUpdateCase theOrder : updOrders)        
        {
            OrderResponse theResponse = new OrderResponse();
            List<Case> theCases = new List<Case>();
            theCases =   [ select id, status, AccountId, TMW_Order_Num__c, CaseNumber, Fuel_Order_Status__c 
                         FROM case WHERE TMW_Order_Num__c = :theOrder.TMWOrderNumber ];
            System.debug('order # is ' + theOrder.TMWOrderNumber);
            if (theCases.size() > 1)
            {
                theResponse.Errors.Add('Case ' + theCases[0].CaseNumber + 'for TMW Order ' + theOrder.TMWOrderNumber + ' already exists');
                System.debug('Case ' + theCases[0].CaseNumber + 'for TMW Order ' + theOrder.TMWOrderNumber + ' already exists');
                theResponse.OrderNumber = theOrder.TMWOrderNumber;
                theResponse.CaseNumber = theCases[0].CaseNumber;
                orderList.Add(theResponse);
            } else if (theCases.size() == 0)
            {
                // Create new SF case
                Case newCase = new Case();
        newCase.Status = theOrder.Status;
        newCase.Fuel_Order_Status__c = theOrder.FuelOrderStatus;
        newCase.TMW_Order_Num__c = theOrder.TMWOrderNumber;
        newCase.TMWSentDt__c = Date.today();
        newCase.Credit_Alert_Type__c = theOrder.CreditAlerttype;
                newCase.Delivered_Time__c = theOrder.DeliveredTime;
                // Get the company code from the translation table. Company codes are stored as TMW-xxxxx
                string translatedCompanyCode = 'TMW-' + theOrder.CompanyCode;
                System.debug(translatedCompanyCode);
                newCase.AccountId = [SELECT IntegratedSite__c 
                                     FROM Translation_Table__c 
                                     WHERE Surrogate_ID__c = :translatedCompanyCode].IntegratedSite__c;
                newCase.RQ_Delivery_Timeframe__c = theOrder.RequestDeliveryTimeframe;
                newCase.RQ_Delivery_Date__c = theOrder.RequestDeliveryDate;
                newCase.Origin = theOrder.Origin;
                integer i = 0;
                for (FuelOrderItem item : theOrder.FuelOrderItems)
                {
                    i++;
                    switch on i
                    {
                        when 1 
                        {
                            newCase.Fuel1_Requested_Type__c = item.FuelType;
                            if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel1_Delivered_Type__c = item.FuelType;
                                newCase.Fuel1_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }
                        }
                        when 2 
                        {
                            newCase.Fuel2_Requested_Type__c = item.FuelType;
                            if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel2_Delivered_Type__c = item.FuelType;
                                newCase.Fuel2_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }                            
                        }
                        when 3 
                        {
                            newCase.Fuel3_Requested_Type__c = item.FuelType;
                            if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel3_Delivered_Type__c = item.FuelType;
                                newCase.Fuel3_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }                                            
                        }
                        when 4 
                        {
                            newCase.Fuel4_Requested_Type__c = item.FuelType;
              if (theOrder.FuelOrderStatus == 'Delivered')
              {
                newCase.Fuel4_Delivered_Type__c = item.FuelType;
                                newCase.Fuel4_Delivered_Amount__c = item.FuelDeliveredAmount;
                        }                
                        }
                    }
                }
                System.debug('about to insert case');
        Insert newCase;
        theResponse.OrderNumber = theOrder.TMWOrderNumber;
        theResponse.CaseNumber = newCase.CaseNumber;
        orderList.Add(theResponse);
            }
      else
            {
                // Update existing case
                Case updCase = theCases[0];
                if (updCase.Fuel_Order_Status__c != theOrder.FuelOrderStatus)
                {
                    updCase.Status = theOrder.Status;
                    updCase.Fuel_Order_Status__c = theOrder.FuelOrderStatus;
                    updCase.TMW_Order_Num__c = theOrder.TMWOrderNumber;
                    updCase.TMWSentDt__c = Date.today();
                    updCase.Credit_Alert_Type__c = theOrder.CreditAlerttype;
                    // update Delivered fields for completed orders
                    if (theOrder.FuelOrderStatus == 'Delivered')
                    {
                        for (FuelOrderItem item : theOrder.FuelOrderItems)
            {
                            if (updCase.Fuel1_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel1_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
                            else if (updCase.Fuel2_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel2_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
                            else if (updCase.Fuel3_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel3_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
                            else if (updCase.Fuel4_Requested_Type__c == item.FuelType)
                            { 
                                updCase.Fuel4_Delivered_Amount__c = item.FuelDeliveredAmount; 
                            }
            }
                        updCase.Delivered_Time__c = theOrder.DeliveredTime;
                        updCase.Carrier_Confirm_Date_Time__c = theOrder.CarrierConfirmDateTime;
                    }
                    System.debug('about to update case');
            Update updCase;
                    theResponse.OrderNumber = theOrder.TMWOrderNumber;
                    theResponse.CaseNumber = updCase.CaseNumber;
                    orderList.Add(theResponse);
                }
            }            
        }
        return orderList;
    }
}
 
On the Opportunity record I have a quick action to create Contact roles. When I click on the quick action , I am opening a flow screen. And on that screen I need to prepopulate the Opportunity Id from where I came . What is the way ? 

I created a variable called recordID and set the type as input. Foe some reason that is not working. Any help ??