• degmo
  • NEWBIE
  • 80 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 4
    Replies
Hello,
I am working with a lightning component button that lives on a custom object record page.  When the button is clicked, I want to pass the current record to a controller class and do some processing.  I know I can pass the "recordId" and that works fine but I am trying to avoid querying the other fields of the record and attempting to pass "v.record" instead of "v.recordId" but I get a null value inside the controller.  I am trying to do something like this:  Is it possible?
 
myMethod: function(component, event, helper) {
var action = component.get("c.processRecord");
action.setParams(
{
    'curRecord' : component.get("v.record")
}
);
action.setCallback(this, function(response) {
var state = response.getState();
if(state === "SUCCESS")  {
     console.log("--> Data returned is: ", response.getReturnValue());
 }
else
{      
     console.log("--> Data not returned is ");             
});
        $A.enqueueAction(action);
}

 
  • February 25, 2021
  • Like
  • 0
Hi,
I have a custom object called Transaction and on its page layout I have a button that uses a lightning component to create related Transaction_Line_Item__c records with 2 different record types.

Component:
<aura:component controller="myController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
    <div class="slds-grid_vertical-align-center ">
    <lightning:button class="slds-m-top_small" label="Run" onclick="{!c.createLineItems}" />
     </div>
</aura:component>
Controller:
({
    createLineItems : function(component, event, helper) {
        var action = component.get("c.processLineItems");
        action.setParams(
            {
                'currentId' : component.get("v.recordId")
            }
        );
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS")  {
                //display success message
            }else{
                //display error message
            }
        });
        $A.enqueueAction(action);
    })
Apex Controller:
public class myController{

    @AuraEnabled
    public static List<Transaction_LineItems__c>processLineItems(String currentId){ 
         List<Transaction__c> curTransaction = [SELECT Id, field1, field2, field3 FROM Transaction__c WHERE Id=:currentId];

   //Delete all existing line items first
   deleteLineItems(curTransaction);
   //Start creating new line items
   List<Transaction__Lineitem__c> newTranLineItem = createNewLineItems(curTransaction);
}
public List<Transaction_Lineitem__c> createNewLineItems(Transaction__c curTransaction) {

}
}
I have a couple of questions:
1.  In my "processLineItems" method, I am querying the same record that initiated the process.  I need the extra fields and that is why I am querying it there but is it more efficient for the lightning component to pass the object with the fields I need so I don't have to do a SOQL query?
2.  I am passing the Transaction__c object from one method to another and instead of that, can I declare a static varible of type Transaction__c and set it once inside "processLineItems"?
3.  I am creating two types of Transaction_Line_Item__c records (2 record types).  Is it again to efficient to have the record type Ids defined as static and set them once inside "processLineItems"?



 
  • February 21, 2021
  • Like
  • 0
Hello All,
I have one big list of accounts as follows:
List<Account> lstMain = [SELECT Id FROM Account WHERE balance__c > 1000000];

I have several other smaller lists as follows:
List<Account> lstVip = [SELECT Id FROM Account Where vip__c = true];

List<Account>lstSpecial = [SELECT Id FROM Account where special__c = true];

List<Account>lstNearMe = [SELECT Id FROM Account where state =:currentState AND status = 'valid'];

What I need to do is produce a final list.  The final list has to start with 'lstMain' and remove from 'lstMain' those that aren't in 'lstVip' or 'lstSpecial' or 'lstNearMe'.  What is the most efficient way to accomplish this?  Should I use a map instead of a list?
  • February 19, 2021
  • Like
  • 0
Hello All,
I need to build a dynamic SOQL where clause based on 15 fields and wanted to see if anyone can recommend a more efficient approach than what I have below:
 
List<Drive__c> lstDrive = [SELECT Id, field1, field2, field3, field4, field5, field 6, field 7 FROM Drive__c where Id=:currentId LIMIT 1];

If(!lstDrive.isEmpty()){

Drive__c currentDrive = lstDrive[0];
String myQuery = 'SELET Id FROM Account Where ';

if(currentDrive.field1 != null) {
myQuery += 'field1 >= ' + currentDrive.field1 + ' AND ';
}
if(currentDrive.field2 != null) {
myQuery += 'field2 >= ' + currentDrive.field2 + ' AND ';
}
if(currentDrive.field3 != null) {
myQuery += 'field3 <=' + currentDrive.field3 + ' AND ';
}
.
.
.
.
}
List<Account> result = Database.query(myQuery);
Basically, I have 15 such 'if' blocks that build the where clause.  Any suggestions or recommendation would be greatly appreciated.
  • February 17, 2021
  • Like
  • 0
All,
I have a total of 15 custom fields on the account object that I need to use to compare to account records with each other.   A few of the fields are:  balance, total_value, property_value.  My requirement is that for a given account, I need find existing accounts that match these values.  If the value is blank or null, it should be skipped.
 
List<Account> matchingAccounts = new List<Account>(); 

List<Account> vipAccount = [SELECT Id, balance__c, total_value__c, property_value__c, FROM Account WHERE Id = 'xxxxxxxxxxxxx' LIMIT 1)

if(!vipAccount.isEmpty()) { 
   Account currentAccount = vipAccount[0]; 
   matchingAccounts = [SELECT Id FROM Account
     Where balance__c =:currentAccount.balance__c &&
     total_value__c =:currentAccount.total_value__c && 
   property_value__c =:currentAccount.total_value__c]; 
}
Now, if any of the fields in vipAccount are null, I don't want to use them for matching.  I only want to match on non-null values.  Any thoughts/ideas on how I can achieve that?
  • February 15, 2021
  • Like
  • 0
Hello All,
On the Account object, I have a several fields that are used for defining a set of thresholds for Account records. There are a total of 12 such fields and a few examples of those fields are:  Account_Balance_Criteria__c, Account_Asset_Criteria__c, Account_Region_Criteria__c, etc.  I also have two custom objects:  Transaction__c and VIP_Member__cTransaction__c  has a lookup to the Account object and VIP_Member__c  has a master detail relationship to Transaction__cVIP_Member__c has two record types; Accepted VIP Members and Denied VIP Members.
 
My requirement is that when a user clicks on a button called 'Generate VIP Members' from a 'Transaction' record page, the system will evaluate all existing Account records based on the criteria fields of the 'Account' related to the 'Transaction' record.  It then creates a 'VIP Members' record for each Account that matches all the criteria defined.  If the user creates 'Generate VIP' again, the 'VIP Members' records will be overwritten. 

For example, let's say I have Transaction A that is related to Account A.  The only criteria field that is populated for Account A is Account Balance and it has a value of $1,000.  Let's also say Accounts B, C, and D have a Balance of $0 and Account E has a Balance of $1000.  In this scenario, a VIP Member record with the record type of 'Accepted VIP Members' will be created for Account E and three VIP Member records with the record type of 'Denied VIP Members' will be created; one each for Accounts B, C, and D.  For the 'Denied VIP Members', it is also necessary for me to keep track of the criteria that caused them to be denied.

 
I am looking for an opinion on the best design approach for this.  I know I have to build an Apex class but I want to make sure it's scalable and efficient.  My initial thoughts were to get a list of Accounts that meet the criteria and maintain two separate lists for 'accepted' and 'denied' and do the evaluation inside of a loop.  Any thoughts or comments will be appreciated.
 
  • February 12, 2021
  • Like
  • 0
Hi,
I have two custom date fields on the account object.  Signup_Date and Contact_Date.  The requirement I have says, if the Signup_Date is greater than 45 calendar days from today, I need to make sure the Contact_Date is Signup_Date minus 45 calendar days.  One important caveat is I have to make sure that Signup_Date minus 45 calendar day doesn't fall on a weekend.  If it falls on Saturday, I need to set it to the Friday before and if it is on a Sunday, i need to set it to the Monday after.  I am struggling with this and hoping somebody can assist me.
  • February 04, 2021
  • Like
  • 0
Hi,
We have a requirement where picklist values for a custom field on a standard object are over 255 characters long.  SF has a limitation of 255 characters and I was wondering if anyone has worked around this preferablly w/o custom code.  Any thoughts/suggestions are greatly appreciated.
  • January 11, 2021
  • Like
  • 0
Hi,
I have custom object called 'question' where a SF user maintains a list of questions that he/she will ask when dealing with a customer.  They are constantly adding more questions and there is a flag that indicates whether a question is active or not.  There is a second custom object called 'answer' that is a junction object between 'Account' and 'Question'.  
The requirement is that when the user is talking to the customer, he/she needs to answer as many of the active questions as possible.  The user should be presented with the list of unanswered questions when clicking on a button 'answer questions' that will be placed on the account page.

The client wants this implemented via declarative tool.  I was thinking about using a flow but not sure if it's possible to display a list of unanswered questions in a flow, collect the answers, and save the answer associated to each question.  Is this feasible via a flow?
  • December 09, 2020
  • Like
  • 0
Hi All,
I have custom field on a custom object called Review.  It has a field called Review_Number__c that is supposed to be generated as follows:  last two digits of current year followed by the last 8 digits of Review_Number__c from the most recent record plus one.  

So, if the most recent review record has a Review_Number__c of 2012345678, the new record that gets inserted today will get the number 2012345679.  If today was 1/1/21, then the new record that gets inserted will get the number 2100000001. 

I already have a flow that does executes other business logic when a review record gets created and was thinking I can build the formula in the flow but not sure if that the most optimum solution.  Can it be done in a flow?  If so, i can use some guidance.  Much appreciated.
  • November 24, 2020
  • Like
  • 0
Hi,
I have master detail relationship between two custom objects.  The master object is called transaction has a date field called 'transaction_date__c' and detail object is called items has a field called 'item_added_date'.  What I am trying to do is, for a given transaction, get the line items whose item_added_date is < the transaction_date.  Could someone point me in the write direction to writing a SOQL for this?
  • November 10, 2020
  • Like
  • 0
public class flowHandler {

@invocablemethod()
public static void processRecords(List<custom> incomingRecs) {

}

}

 
  • November 06, 2020
  • Like
  • 0
Hi All,
I am working on a feature where a Salesforce record is submitted to an external service via a callout.  There is a requirement that if the external service returns a response code that isn't a 200 or 201 or there is other connection issues, a status field on the record needs to be updated with the value 'Callout Failed'.  

The only way I can think of it to put the logic that does the status update inside of the finally block.  Was wondering if this is best pattern or other have different approaches.
@future(callout=true)
public static void doPost(Id recId) {
       Boolean calloutFailed = false;
       try {
             HttpResponse response = sendToExternal(recId);
             if( response.getStatusCode != 200 || response.getStatusCode != 201) {
                 calloutFailed = true;
             }
       }  catch(exception e) {
          calloutFailed = true;
          Util.logError(e, 'Error inside doPost()');
      }
      finally {
        if(calloutFailed) {
            List<custom_object__c> curr = [SELECT Id FROM custom_object__c WHERE 
            Id =: recId);
            if(curr.size() > 0) {
                curr[0].status = 'callout failed';
                update curr;
            }
        }
     }
}

public static HttpResponse sendToExternal(Id recordId) {
       Http http = new Http();
       HttpRequest request = new HttpRequest();
       request.setEndpoint('xxxx');
       request.setMethod('POST');
       request.setBody('xxxxxxxxxxxx');
       
       try {
            Http response = http.send(request);
            return response;
       }  catch (exception e) {
               throw e;
       }
}

 
  • October 30, 2020
  • Like
  • 0
Hello All,
I have an existing future method that does a callout to an external service.   All it does is send data to an external service and if the response is not a 200, it just logs a message to the debug log.  This method obviously doesn't return anything and it doesn't perform any action on the SF side that I can use to do my assertions.

I have created a mock class and used it to invoke this future method inside of Test.StartTest & Test.StopTest.  I am getting 100% code coverage but I don't have any assertions.  I am struggling with what to use for my assertions?  Since the method doesn't return anything, I can't use the response from my mock class.  Any thoughts?  Here is a code snippet of the class  
@Future(Callout = true)
public static void callExternalSystem(Id recordId) {

     String body = buildMessage(recordId);
     HttpRequest req = new HttpRequest();
     req.setEndpoint('https://xyz.com/test');
     req.setMethod('Post');
     req.setHeader('');
     req.setBody(body);
     Http http = new Http();
     HttpResponse response = http.send(req);

     if(response.getStatusCode() != 200) {
          system.debug('Status is: ' + response.getStatus + '  ' + response.getBody());
     }

}

public static string buildMessage(Id recordId)
{
  // logic to build the request body
}

 
  • October 26, 2020
  • Like
  • 0
Hi,
I am trying to create a test for a class that has if/else logic based on different lookup values for a field.  Below is a snippet of the code that I need to test.  I typcially would like to use Test Data Factory and testSetup when writing my unit tests.  I am trying to figure out the most efficient way to accomplish this.  

Should I create different student records with the different affliate lookup values in the Test Data Factory or is it more efficient to create one student record do a fetch a update with the different values in each test method?
 
if(student__c.affiliate__c == 'freshman') {
   // do stuff
}
else if(student__c.affiliate__c == 'sophomore') {
  // do stuff
}
else if (student__c.affiliate__c == 'junior') {
  // do stuff
}

Both student__c and affiliate__c are custom object.  There is a lookup r/ship b/n them.

 
  • October 24, 2020
  • Like
  • 0
Hi,
I am working with a client on an issue where a few custom profiles are missing from the UI.  When I run the following query via the developer console's query editor, I see the missing profiles listed.  
select id, name from profile
I also am able to view the profiles from workbench.  It's just odd that they are missing from the Salesforce UI and I made sure there are no filters in the view.  I also went to an APEX class and see if I can add the missing profiles to the class, but they are not listed in the available list of profile.  I tried in both classic and lightning views and I also tried in incognito window.  Any ideas?  
 
  • October 14, 2020
  • Like
  • 0
Hello,
I am troubleshooting an issue where permissions where removed/edited by an automated process.  I exported the logs from "view setup audit trail".  I found a bunch of entries like this 
Removed the ModifyAllRecords on 01I6A000001icPZ object permission from Profile 00e6A000000vIEC
 

I have two questions that I am hoping someone can help me with.

Question #1
To identify the object that was impacted, I wrote the follwoing code 

Id someId = '01I6A000001icPZ';
System.debug(someId.getSObjectType());
System.debug(someId.getSObjectType().getDescribe().getName());
Both of these return "CustomEntityDefinition" and not the actual object name.  Am I missing something?

Question #2
To get the profile name, I wrote the following query
Select name from profile where id = '00e6A000000vIEC'
The profile name i get back isn't in the list of profiles that are avialble in the UI.  I made sure to select "all" so I know I am looking at the list of all available profiles.  Is it possible for the profile to be deleted and but the SOQL would still return it back?
 
  • October 13, 2020
  • Like
  • 0
Hello,
A team member asked me to assit her with test coverage on a project that she is working on.  Due to strict security requirements, the best way for me to assist her would be for her to package up the pertinent objects, classes, and test classes so I can install it on my own developer org (it will be an unrelated developer org).  What is the best way for her to package this all up for me and what will be the steps?  Any help will be greatly appreciated.
  • October 05, 2020
  • Like
  • 0
All,
I have a total of 15 custom fields on the account object that I need to use to compare to account records with each other.   A few of the fields are:  balance, total_value, property_value.  My requirement is that for a given account, I need find existing accounts that match these values.  If the value is blank or null, it should be skipped.
 
List<Account> matchingAccounts = new List<Account>(); 

List<Account> vipAccount = [SELECT Id, balance__c, total_value__c, property_value__c, FROM Account WHERE Id = 'xxxxxxxxxxxxx' LIMIT 1)

if(!vipAccount.isEmpty()) { 
   Account currentAccount = vipAccount[0]; 
   matchingAccounts = [SELECT Id FROM Account
     Where balance__c =:currentAccount.balance__c &&
     total_value__c =:currentAccount.total_value__c && 
   property_value__c =:currentAccount.total_value__c]; 
}
Now, if any of the fields in vipAccount are null, I don't want to use them for matching.  I only want to match on non-null values.  Any thoughts/ideas on how I can achieve that?
  • February 15, 2021
  • Like
  • 0
Hi All,
I have custom field on a custom object called Review.  It has a field called Review_Number__c that is supposed to be generated as follows:  last two digits of current year followed by the last 8 digits of Review_Number__c from the most recent record plus one.  

So, if the most recent review record has a Review_Number__c of 2012345678, the new record that gets inserted today will get the number 2012345679.  If today was 1/1/21, then the new record that gets inserted will get the number 2100000001. 

I already have a flow that does executes other business logic when a review record gets created and was thinking I can build the formula in the flow but not sure if that the most optimum solution.  Can it be done in a flow?  If so, i can use some guidance.  Much appreciated.
  • November 24, 2020
  • Like
  • 0
Hello All,
I have an existing future method that does a callout to an external service.   All it does is send data to an external service and if the response is not a 200, it just logs a message to the debug log.  This method obviously doesn't return anything and it doesn't perform any action on the SF side that I can use to do my assertions.

I have created a mock class and used it to invoke this future method inside of Test.StartTest & Test.StopTest.  I am getting 100% code coverage but I don't have any assertions.  I am struggling with what to use for my assertions?  Since the method doesn't return anything, I can't use the response from my mock class.  Any thoughts?  Here is a code snippet of the class  
@Future(Callout = true)
public static void callExternalSystem(Id recordId) {

     String body = buildMessage(recordId);
     HttpRequest req = new HttpRequest();
     req.setEndpoint('https://xyz.com/test');
     req.setMethod('Post');
     req.setHeader('');
     req.setBody(body);
     Http http = new Http();
     HttpResponse response = http.send(req);

     if(response.getStatusCode() != 200) {
          system.debug('Status is: ' + response.getStatus + '  ' + response.getBody());
     }

}

public static string buildMessage(Id recordId)
{
  // logic to build the request body
}

 
  • October 26, 2020
  • Like
  • 0
Hello,
I am troubleshooting an issue where permissions where removed/edited by an automated process.  I exported the logs from "view setup audit trail".  I found a bunch of entries like this 
Removed the ModifyAllRecords on 01I6A000001icPZ object permission from Profile 00e6A000000vIEC
 

I have two questions that I am hoping someone can help me with.

Question #1
To identify the object that was impacted, I wrote the follwoing code 

Id someId = '01I6A000001icPZ';
System.debug(someId.getSObjectType());
System.debug(someId.getSObjectType().getDescribe().getName());
Both of these return "CustomEntityDefinition" and not the actual object name.  Am I missing something?

Question #2
To get the profile name, I wrote the following query
Select name from profile where id = '00e6A000000vIEC'
The profile name i get back isn't in the list of profiles that are avialble in the UI.  I made sure to select "all" so I know I am looking at the list of all available profiles.  Is it possible for the profile to be deleted and but the SOQL would still return it back?
 
  • October 13, 2020
  • Like
  • 0