• $hwet@
  • NEWBIE
  • 255 Points
  • Member since 2018

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 56
    Replies
public with sharing class HotAccountController {
  public HotAccountController() {  
  }

  @AuraEnabled
  public static Boolean isAccountHot(String accId){
    Account objAccount = [Select Hot_Account__c, Id from Account WHERE Id =: accId];
    return objAccount.Hot_Account__c;
  }

  @AuraEnabled
  public static Boolean callApproval(String accId){
      try{
      UpdateAccount.callApproval(accId);
      return true;
    }catch(Exception excpt){
      return false;
    }
  }
}
Hello,

I have created a lightning component in sandbox to display the lock/ Unlock icon on my record Page.
This needs to create the following Apex method:
public class UnlockRecordUtil {
  @AuraEnabled
    public static Boolean islocked(String recordId){
       return Approval.isLocked(Id.ValueOf(recordId));
     }
    @AuraEnabled
    public static boolean unlockRecord(String objId){
        List<String> unlockrec = new List<string>();
        unlockrec.add(objId);
        Approval.UnlockResult[] unlockedRersult = Approval.unlock(unlockrec);
        return true;
    }
    @AuraEnabled
    public static Boolean LockRecords(String objId){
        List<Account> sobjectre = [Select Id FROM Account WHERE ID =:objId];
        Approval.LockResult[] lrList = Approval.lock(sobjectre, false);
    return true;
    }
}
However, I don't know how to do the test class for this ligthning component.
I have tried to fire approval from my test class but it is not testing these aura method...
Mant thanks in advance.
Best Regards.
==========================
Challenge Requirements
You have a session-based permission set that you’d like to activate, but you don’t code. Create a flow that activates a permission set named Temporary Account Edit. Make sure Lynda Herman can run the flow by enabling the Manage Flow permission on the Read Only Clone profile.
In the Read Only Clone profile you created in the previous unit's challenge, enable the Manage Flowpermission
Create a flow
Flow name: Accounts Temp Access
Make sure the flow references a session-based permission set named Temporary Account Edit as an input
Type: Screen Flow
Activate the flow
=============================

I believe I've done everything that I'm supposed to, I can run the flow and it gives me "YOUR FLOW FINISHED", but I can't activate it.

Any ideas why?User-added imageUser-added image
public class ExtensionVoucherHandler {
   public static Boolean doRun = True;
  public static void VoucherResend(Map <id,Certification_Voucher__c> oldMap, list<Certification_Voucher__c> newlist ){
  
  map<string,Certification_Voucher__c> codemap = new map<string,Certification_Voucher__c>();

   for(Certification_Voucher__c C : newlist){
   
      if(C.Expiration_Date__c != oldMap.get(C.id).Expiration_Date__c){
        
        codemap.put(C.name,C);
     
     }
   
   }
   
   List<Training_Attendee__c> TA = [select id,Voucher_Code__c,Voucher_Expiration_Date__c from Training_Attendee__c where Voucher_Code__c in: codemap.keyset()];
     
   List<Training_Attendee__c> lstUpdate = new List<Training_Attendee__c>();    
       
        for(Training_Attendee__c  train : TA){
        
            if(codemap.containsKey(train.Voucher_Code__c)){
              train.Voucher_Expiration_Date__c = codemap.get(train.Voucher_Code__c).Formatted_Expiration_Date__c ;
               lstUpdate.add(train);
          }
     }
      if(lstupdate != null && lstupdate.size() > 0)     
     database.update (lstUpdate,false);
     
     }
   }
I have the following SOQL query in my custom controller.  I would like to build a page that shows all the parent (case) records and related child (RMA) records in one single table.  I've been able to do this with a single case, but can't seem to figure out how to do it when I want to display all cases.

How would one go about doing this?
 
string searchquery = 'SELECT ID, '
                   + 'casenumber, '
                   + 'subject, '
                   + 'Severity__c, '
                   + 'Case_Type__c, '
                   + 'CreatedDate, '
                   + 'ClosedDate, '
            	   + 'Status, '
                   + 'Status_Comment__c, '
                    + '(select  '
                         + 'Customer_Asset_Type__c, '
                         + ' RMA_Customer_Reported_PO__c, '
                         + ' Date_Received__c, '
                         + 'PO_Contract_Date__c, '
                         + 'RMA_Actual_SN_Returned__c, '
                         + 'RMA_Customer_Reported_Failure_Inform__c, '
                         + 'RMA_Customer_Reported_Part_Number__c, '
                         + 'RMA_Customer_Reported_Qty__c, '
                         + 'RMA_Customer_Reported_SN__c, '
                         + 'Warranty_Status__c '
                         + 'from RMA_Products__r) '
                   + 'FROM Case  '
                   + 'WHERE OwnerId= \'' + UserInfo.getUserID() + '\''
                   + 'ORDER BY casenumber DESC '
                   ;

        caseResults = Database.query(searchquery);

 
Hi everyone,
I am pretty new to Salesforce Development. I have a simple requirement for where in I need to update a field with the count of child records associated with that object. Since the relationship is that of a look up relationship, I had to achieve this with a trigger. I was able to achieve the requirement. But what I am not able to write is test class for it. Can you please help? 
Here is the trigger and helper code :
Trigger:
trigger UpdtNumofsessions on Session__c (after insert, after update, after delete, after undelete) {
   venueupdatetriggerhandler venupdate = new venueupdatetriggerhandler();
    
    if(trigger.isinsert && trigger.isafter){
        venupdate.OnAfterInsert(trigger.new);
    }
   
    if(trigger.isupdate && trigger.isafter){
        venupdate.OnAfterUpdate(trigger.new);
    }
    
    if(trigger.isdelete && trigger.isafter){
        venupdate.OnAfterDelete(trigger.old);
    }
    
    if(trigger.isundelete && trigger.isafter){
        venupdate.OnAfterInsert(trigger.old);
    }
}

Helper Code:
 
public with sharing class venueupdatetriggerhandler {
 // update the number of sessions on venue when new session records are inserted from trigger
  public void OnAfterInsert(List<session__c> newRecords){
    updatenumberofsessions(newRecords); 
  }
  // update the primary country when records are updated from trigger  
  public void OnAfterUpdate(List<session__c> updatedRecords){
    updatenumberofsessions(updatedRecords); 
  }
 
    public void OnafterDelete(List <session__c> oldRecords){
        updatenumberofsessions(oldRecords);
    }
    
    public void OnafterUndelete(List<Session__c> oldRecords){
        updatenumberofsessions(oldRecords);
    }
  // updates the sales order with the primary purchased country for the item
    private void updatenumberofsessions(List<Session__c> newRecords){
  // create a list to hold session records whose venue is not null
     List<id> ses = new list <id>();
        for (session__c s:newRecords){
            if(s.venue__C!=null){
                ses.add(s.venue__C);
            }
            
       // list to query all the venue records in the database which is a part of the LIST 'ses'     
       list<venue__C> ven =[select id, no_of_sessions__C,(select id from sessions__r) from venue__C where id in:ses];    
  
            //loops over the query result set of venue and updates the no. of sessions field with the count of the related session records
            for(venue__c v:ven){
                v.no_of_sessions__c=v.sessions__r.size();
                }
            Update ven;
    } 
    }
    
}

Thank you so much.
Hey everyone, I have created a trigger to update a field (Last_Changed_Date) on all related Contacts and I am getting the CPU Time out Limit error. I was hoping somoene could take a look and see if there is anyway to optimize?

trigger CCIAllegianceProvider on Account (before update) {

    //Map keeps track of accounts that have new addresses
    Map<Id, Account> changedProvider = new Map<Id, Account>();

    //Trigger.new is a list of Accounts that will be updated
    //The loop iterates over the list and adds accounts that have new addresses and adds to changedProvider list
    for (Integer i = 0; i < Trigger.new.size(); i++){

        if (   
        (Trigger.old[i].ShippingAddress != Trigger.new[i].ShippingAddress)

                || (Trigger.old[i].BillingAddress != Trigger.new[i].BillingAddress)
                
                || (Trigger.old[i].Phone != Trigger.new[i].Phone)

                || (Trigger.old[i].V12C__PR_Practice_Tax_ID_Number__c != Trigger.new[i].V12C__PR_Practice_Tax_ID_Number__c)

                )  {

            changedProvider.put(Trigger.old[i].id,

            Trigger.new[i]);
        }
    }



    List<Contact> updatedContacts = new List<Contact>();

    //Iterate over SOQL query and bind array with in
    for (Contact c :[SELECT Id, AccountId, Last_Changed_Date__c FROM Contact WHERE V12C__RecordType__c = 'Provider' AND V12C__Inactive__c = False AND AccountId IN :changedProvider.keySet()]){
        Account parentAccount = changedProvider.get(c.AccountId);
        c.Last_Changed_Date__c = Datetime.Now();
        updatedContacts.add(c);
    }

    update updatedContacts;
}
 Created email templates which needs to be send to users .
Ids of the record for which the email needs to be sent has been passed via JS button to the apex class,which will trigger the emails to the users via the Js button. The email is not getting received to the users if send by Jillian's login but its working fine with other users login.
not able to receive email from one user even after giving admin access in production. Functionality is working fine in UAT
  • August 20, 2019
  • Like
  • 0
VF page call component : $A.getCallback() : 'SetParams' undefined
I have two lightning components and the first component is like a login page and once the login is successful the other component should be called. My code is working fine if I add the component in the record page but if I try to call the component via visualforce page it throws me the below error:
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://Userempid/ACTION$getContacts Failing descriptor: {c:NewLoginPage}

where c:NewLoginPage - the login pagei.e First component
Userempid - apex controller for the first component.

can you please help me with this.

Please find the code below:

First Component (which after chick on login should call other component)
<aura:component  controller="Userempid"   implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
                <ltng:require styles="/resource/SLDS24/styles/salesforce-lightning-design-system.css"/>
    <aura:attribute name = "Empiduser" type = "string"/>
     <aura:attribute name = "Empidpwd" type = "string"/>
     <lightning:layout>
        <lightning:layoutItem padding="around-small" size="12" class="main">
                                                <div >
                                                <form class="slds-form--stacked">
                                                                <ui:inputtext aura:id="FormId" label=" User Name " class="" value="{!v.Empiduser}" maxlength="30" placeholder="Employee Id" required="true" size="20"/> <br/>
                                               <ui:inputSecret aura:id="FormId" label=" Password " class="" value="{!v.Empidpwd}" maxlength="10" placeholder="Password" required="true" size="20"/> <br/>
                               <div class="slds-float--left slds-button_brand">
                                              <div class="slds-grid buttons">
                                              <lightning:button variant="brand" label="Login" title="Login" iconPosition = "Left" onclick="{!c.handleLoginButtomClick}"/>
                                               </div>
                                                                </div>
                               </form>
                                                </div>
       </lightning:layoutItem>
   </lightning:layout>
</aura:component>
 
Controller.js
({
                handleLoginButtomClick : function(component, event, helper) {
                                  var testid = component.get("v.Empiduser");
          var testpw = component.get("v.Empidpwd");
          alert('******'+testid+testpw);
                 var action = component.get("c.getContacts");
                  action.setParams({
            "EmpidId": component.get("v.Empiduser"),
            "Emppwd": component.get("v.Empidpwd")
                                });
        alert('******'+testid+testpw);
    
    var self = this;
       action.setCallback(this, function(actionResult) {
               var rtnValue =actionResult.getReturnValue();
           alert('Value :'+rtnValue);
         if(rtnValue = "Correct User Name and Password" && rtnValue!="Wrong Username or Password"){
           var evt = $A.get("e.force:navigateToComponent");
                                evt.setParams({
                               componentDef : "c:ListofAvailableTest",
                               componentAttributes: {
                               AgentId : testid
                                                               }
                                                });
                                                                evt.fire();
 
                                                }
                });
         $A.enqueueAction(action);
       
   }
})
Apex Controller
public class Userempid {
                @AuraEnabled
                public static string getContacts(string EmpidId,string Emppwd) {
        List<custom_object__c> getContactsdebug = [Select Id, Password__c, EmpId__c From custom_object__c Where EmpId__c = :EmpidId and Password__c =:Emppwd];
        system.debug('getContactsdebug'+getContactsdebug);
       // return getContactsdebug;
                                //return [Select Id, Password__c, EmpId__c From custom_object__c Where EmpId__c = :EmpidId and Password__c =:Emppwd Limit 1];
        if(getContactsdebug.size() ==0 || getContactsdebug.isEmpty()){
          Return 'Wrong Username or Password';
        }
        else if(getContactsdebug.size() >0 && !(getContactsdebug.isEmpty()) && getContactsdebug.size() ==1 ){
           Return 'Correct User Name and Password';
        }
        else{
            Return 'Wrong Username or Password';
        }
    }
}
Second Component
<aura:component controller = "ListofAvailableTest" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
                <div class="slds-grid" style="background-color:lightGrey;padding:20px">
               <div class="slds-col" style=" font-size: 18px;font-weight: bold">
               Training Portal
        </div>
       
         <div class="slds-float--right" style=" font-size: 18px;font-weight: bold">
               Signed in as
        </div>
    </div>
   
     <aura:attribute name="AgentsAllowed" type="List" />
     <aura:attribute name="TestHistory" type="List" />
    <aura:attribute name="AgentId" type = "string" />
    <aura:attribute name="Password" type ="String"/>
    <aura:attribute name="recordId" type="String" />
     <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     <lightning:layout class="slds-page-header slds-page-header--object-home" title ="Available Test">
        <lightning:layoutItem Title="Available Test">
            <div class="Tableheading" style="padding:10px">
               Available Test
            </div>
                                <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
              <thead>
                <tr class="slds-text-heading_label">
                  <th scope="col"><div class="slds-truncate" title="ID" style="font-weight:bold">ID</div></th>
                  <th scope="col"><div class="slds-truncate" title="Name" style="font-weight:bold">Name</div></th>
                  <th scope="col"><div class="slds-truncate" title="Test Name" style="font-weight:bold">Test Name</div></th>
                  <th scope="col"><div class="slds-truncate" title="Percentage" style="font-weight:bold">Percentage</div></th>
                </tr>
              </thead>
              <tbody>
                <aura:iteration items="{!v.AgentsAllowed}" var="AgentsAllowedlist">
                    <tr>
                        <th scope="row"><div class="slds-truncate" title="{!AgentsAllowedlist.Id}">{!AgentsAllowedlist.Id}</div></th>
                        <td><div class="slds-truncate" title="{!AgentsAllowedlist.Name}">{!AgentsAllowedlist.Name}</div></td>
                        <td><div class="slds-truncate" title="{!AgentsAllowedlist.Test_Name__r.name}">{!AgentsAllowedlist.Test_Name__r.name}</div></td>
                        <td><div class="slds-truncate" title="{!AgentsAllowedlist.Percentage__c}">{!AgentsAllowedlist.Percentage__c}</div></td>
                    </tr>
                    </aura:iteration>
              </tbody>
               </table>
         </lightning:layoutItem>
    </lightning:layout>
    <lightning:layout class="slds-page-header slds-page-header--object-home" title ="Available Test">
        <lightning:layoutItem Title="Available Test">
            <div class="Tableheading" style="padding:10px;">
               Test History
            </div>
                                <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
              <thead >
                <tr class="slds-text-heading_label">
                  <th scope="col"><div class="slds-truncate" title="Practice Link" style="font-weight:bold">Practice Link</div></th>
                  <th scope="col"><div class="slds-truncate" title="Reset Test" style="font-weight:bold">Reset Test</div></th>
                   <th scope="col"><div class="slds-truncate" title="Mobile - Offline Support" style="font-weight:bold">Mobile - Offline Support</div></th>
                  <th scope="col"><div class="slds-truncate" title="Test Name" style="font-weight:bold">Test Name</div></th>
                  <th scope="col"><div class="slds-truncate" title="Score" style="font-weight:bold">Score</div></th>
                  <th scope="col"><div class="slds-truncate" title="Total Questions" style="font-weight:bold">Total Questions</div></th>
                  <th scope="col"><div class="slds-truncate" title="Flag" style="font-weight:bold">Flag</div></th>
                </tr>
              </thead>
              <tbody>
                <aura:iteration items="{!v.TestHistory}" var="TestHistorylist">
                    <tr>
                        <th scope="row"><div class="slds-truncate" title="{!TestHistorylist.Id}">Practice Link</div></th>
                        <td><div class="slds-truncate" title="{!TestHistorylist.id}"><a href= "{!recordId }" >Reset </a></div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Name}">{TestHistorylist.Name}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Test_Name__c}">{!TestHistorylist.Test_Name__c}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Percentage__c}">{!TestHistorylist.Percentage__c}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Total_Questions__c}">{!TestHistorylist.Total_Questions__c}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Test_Completed__c}">{!TestHistorylist.Test_Completed__c}</div></td>
                       
                    </tr>
                    </aura:iteration>
              </tbody>
               </table>
         </lightning:layoutItem>
    </lightning:layout>
</aura:component>
 
Controller.js
({
      doInit: function(component, event, helper) {
               helper.getAgentsAllowedHelper(component);
      }
  
})
Helper
({
      // Fetch the accounts from the Apex controller
      getAgentsAllowedHelper: function(component) {
        var action = component.get('c.getAgentsAllowed');
        action.setParams({"AgentId":component.get("v.AgentId")});
         
        // Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
         component.set('v.AgentsAllowed', actionResult.getReturnValue());
        self.getTestHistoryHelper(component);
        });
        $A.enqueueAction(action);
      },
    getTestHistoryHelper: function(component) {
        var action = component.get('c.getTestHistory');
        // Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
         component.set('v.TestHistory', actionResult.getReturnValue());
        });
        $A.enqueueAction(action);
      }
    })
Apex Controller : 2nd component
public class ListofAvailableTest {
      @AuraEnabled
     public static List<Agents_Allowed__c> getAgentsAllowed(string AgentId) { 
        List<Agents_Allowed__c> listToReturn = [SELECT Id, name,Agent_Name__c,Emp_ID__c,Full_Name__c,Test_Name__c,Percentage__c,Agent_Name__r.EmpId__c  FROM Agents_Allowed__c WHERE Agent_Name__r.EmpId__c =: AgentId];
                system.debug('listToReturn'+listToReturn);
         return listToReturn;
      
     }
    @AuraEnabled
    public static List <Agents_Test_Result__c> getTestHistory() {
        return [SELECT Id, name,Agent_Name__c,Agent_Full_Name__c,Test_Name__c,Test_Name__r.name,Percentage__c,Total_Questions__c,Test_Completed__c FROM Agents_Test_Result__c where Test_Completed__c = true];
      }
    }
Visualforce Page:
<apex:page showHeader="false" standardStylesheets="false">
     <apex:includeLightning />
 <div id="loginpageId" />
<script>
        $Lightning.use("c:LoginPageApp",
            function(){
                $Lightning.createComponent(
                "c:NewLoginPage",
                    {},
                    "loginpageId",
                    function(cmp){
                    console.log('done');
                     window.alert('i am in');
                    }
                );
            }
        );
    </script>
         
</apex:page>
 
  • April 05, 2019
  • Like
  • 0
I have two lightning components and the first component is like a login page and once the login is successful the other component should be called. My code is working fine if I add the component in the record page but if I try to call the component via visualforce page it throws me the below error:
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://Userempid/ACTION$getContacts Failing descriptor: {c:NewLoginPage}

where c:NewLoginPage - the login pagei.e First component
Userempid - apex controller for the first component.

can you please help me with this.
 
  • December 04, 2018
  • Like
  • 0

Hello all,

I am able to query all the active users in a specific profile:

select user.id, user.FirstName, user.LastName, user.profile.name, user.Username, user.IsActive FROM user, user.profile where profile.name = 'xxxxx' AND IsActive=True


That just returns the active users for the profile, but I am trying to query only the active system admins in a specific profie.

What am I doing wrong please?:)

 

We have some strict requirements on account sharing amongst sales teams members in our org. I have created a custom object which holds the rules of who can see which account based on the Owner on the account. I wrote a trigger which makes use of AccountTeamMember object. Everything is working fine. However I would like to bulkify my trigger but have not been able too after a few attempts.
Below is part of my trigger I would like to bulkify: (the rest of it has code unrelated to account sharing).
Could someone suggest a solution?

Thank you
List<AccountTeamMember> atmToAdd = new List<AccountTeamMember>();

for (Account a : trigger.new) 
{
	//Custom object holding sharing rules
	SharingRuleMap__c[] sMap = [SELECT SharingWith_ID__c, 
										TeamMemberRole__c, 
										AccountAccessLevel__c, 
										ContactAccessLevel__c, 
										CaseAccessLevel__c, 
										OpportunityAccessLevel__c 
								   FROM SharingRuleMap__c
								  WHERE Dealing_Rep__c = :a.OwnerId];
	 
	if (sMap.size() > 0) 
	{ 
		For (Integer i=0; i<sMap.size();i++) 
		{
			AccountTeamMember atm = new AccountTeamMember();
			atm.AccountId = a.Id;
			atm.UserId = sMap.get(i).SharingWith_ID__c;
			atm.TeamMemberRole = sMap.get(i).TeamMemberRole__c;
			atm.AccountAccessLevel = sMap.get(i).AccountAccessLevel__c;
			atm.ContactAccessLevel = sMap.get(i).ContactAccessLevel__c;
			atm.CaseAccessLevel = sMap.get(i).CaseAccessLevel__c;
			atm.OpportunityAccessLevel = sMap.get(i).OpportunityAccessLevel__c;
			atmToAdd.add(atm);
		}
	}
}

insert atmToAdd;

 
I am a total newbie to this system and when trying to delete multiple 'selected' contacts in my contacts list, I hit delete and it proptly went and deleted every SINGLE contact listed!! HELP!
I thought I was doing it correctly by making sure that each contact that I wanted to remove was marked with a tick in the box on the left hand side of the page, obviously not....
I have tryied to search for some kind of recycle bin or deleted items but to no avail. I have also tried running CSV imports from our main system (Microsoft NAV), but that doesnt seem to show anything in my contacts page - even though I recieve an email saying how many contacts it has uploaded..??
However, it does seem that they are still stored somewhere as when I go into someone's account there is a contact listed againt the account..!?
Please can somebody help me with this!!  Thanks in advance! :)
public with sharing class HotAccountController {
  public HotAccountController() {  
  }

  @AuraEnabled
  public static Boolean isAccountHot(String accId){
    Account objAccount = [Select Hot_Account__c, Id from Account WHERE Id =: accId];
    return objAccount.Hot_Account__c;
  }

  @AuraEnabled
  public static Boolean callApproval(String accId){
      try{
      UpdateAccount.callApproval(accId);
      return true;
    }catch(Exception excpt){
      return false;
    }
  }
}
Hello,

I have created a lightning component in sandbox to display the lock/ Unlock icon on my record Page.
This needs to create the following Apex method:
public class UnlockRecordUtil {
  @AuraEnabled
    public static Boolean islocked(String recordId){
       return Approval.isLocked(Id.ValueOf(recordId));
     }
    @AuraEnabled
    public static boolean unlockRecord(String objId){
        List<String> unlockrec = new List<string>();
        unlockrec.add(objId);
        Approval.UnlockResult[] unlockedRersult = Approval.unlock(unlockrec);
        return true;
    }
    @AuraEnabled
    public static Boolean LockRecords(String objId){
        List<Account> sobjectre = [Select Id FROM Account WHERE ID =:objId];
        Approval.LockResult[] lrList = Approval.lock(sobjectre, false);
    return true;
    }
}
However, I don't know how to do the test class for this ligthning component.
I have tried to fire approval from my test class but it is not testing these aura method...
Mant thanks in advance.
Best Regards.
Hi All,

On the System Overview page I have the information that I have xyz number of Apex Classes in the system. However, when I go to 'Apex Classes' section in setup then I have different amount of classess than on the System Overview page (less). 
Do you know where to search for the remaining classes?

Thanks,
Magda
 
Hi, 

  For Class   
public class LeadTriggerUtils {
    
    public static void processLeadOnUpdate(Map<id, Lead> newMap, Map<id, Lead> oldMap) { 
        List<Lead> leadLst = new List<Lead>();
        for (Lead lead : newMap.values()) {
            Lead oldLead = oldMap.get(lead.id);
            if(lead.rvpe__IsDealRegistration__c && lead.rvpe__RVAccount__c != null && lead.rvpe__RVAccount__c != oldLead.rvpe__RVAccount__c) {
        leadLst.add(lead);
            }
        }
        if(!leadLst.isEmpty()) {
      processChangeOwnerAsPartnerAccount(leadLst); 
        }
    }
    
    public static void processLeadOnInsert(List<Lead> newLst) {
      processChangeOwnerAsPartnerAccount(newLst);
    }
    public static void processChangeOwnerAsPartnerAccount(List<Lead> newLst) {
        List<ID> rvAcctIDs = new List<ID>();
        for(Lead lead : newLst) {
            if(lead.rvpe__IsDealRegistration__c && (lead.Global_Region__c == 'EMEA' || lead.Global_Region__c == 'LATAM') && lead.rvpe__RVAccount__c != null) {
                rvAcctIds.add(lead.rvpe__RVAccount__c);
            }
        }
        Map<ID, rvpe__RVAccount__c> rvActMap = new Map<Id, rvpe__RVAccount__c>([select id, rvpe__SFAccount__c, rvpe__SFAccount__r.OwnerId from rvpe__RVAccount__c where id in :rvAcctIDs]);
        for(Lead lead : newLst) {
            rvpe__RVAccount__c rvAct = rvActMap.get(lead.rvpe__RVAccount__c);
            if(rvAct != null && rvAct.rvpe__SFAccount__c != null) {
                lead.OwnerId = rvAct.rvpe__SFAccount__r.OwnerId;
            }
        }
    }
}

Below is the test class it has 90% code coverage. 
@isTest(seealldata = true)
public class LeadTriggerUtilsTest{
    @istest
        public static void leadTest(){
        
          rvpe__RVAccount__c rpv = [select id from rvpe__RVAccount__c where rvpe__SFAccount__c <> null and rvpe__PartnerLevel__c = 'NA Reseller' limit 1];
        
            Lead l1 = new Lead();
            l1.FirstName = 'Pranavan';
            l1.LastName = 'Karthi';
            l1.Email = 'karthi@pranavan.com';
            l1.Company = 'Pranavan';
            l1.country = 'United States';
            l1.rvpe__IsDealRegistration__c = true;
            l1.Global_Region__c = 'EMEA'; 
            l1.rvpe__RVAccount__c = rpv.id;
            
            insert l1;
            
            l1.FirstName = 'Velu';
            
            update l1;
            
       }
       
       public static void leadTest_two(){
       
        Lead l = [select id from lead where rvpe__IsDealRegistration__c  = true and Global_Region__c  <> null and rvpe__RVAccount__c  <> null limit 1];
        
        l.firstname = 'sudhir';
        
        update l;
  
        
       }
}
Only below lines are not covered. 
User-added image
 
When I try to deploy in production it is giving code coverage error.  Please suggest me how to fix. 

Thanks
GMASJ
simple controller with a SOQL query returning data. Need help writing the test class for this! An admin with minimal development experience...

 
public with sharing class CommunitiesNotificationsList {
@AuraEnabled
    
public static List <Communities__c> notifications(String Name, String Position){

        return [SELECT Full_Description__c, Related_Product__c FROM Communities__c 
                WHERE RecordType.Name = 'Notification' AND Related_Product__c =: Name LIMIT 1];
        
}
}

 
VF page call component : $A.getCallback() : 'SetParams' undefined
I have two lightning components and the first component is like a login page and once the login is successful the other component should be called. My code is working fine if I add the component in the record page but if I try to call the component via visualforce page it throws me the below error:
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://Userempid/ACTION$getContacts Failing descriptor: {c:NewLoginPage}

where c:NewLoginPage - the login pagei.e First component
Userempid - apex controller for the first component.

can you please help me with this.

Please find the code below:

First Component (which after chick on login should call other component)
<aura:component  controller="Userempid"   implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
                <ltng:require styles="/resource/SLDS24/styles/salesforce-lightning-design-system.css"/>
    <aura:attribute name = "Empiduser" type = "string"/>
     <aura:attribute name = "Empidpwd" type = "string"/>
     <lightning:layout>
        <lightning:layoutItem padding="around-small" size="12" class="main">
                                                <div >
                                                <form class="slds-form--stacked">
                                                                <ui:inputtext aura:id="FormId" label=" User Name " class="" value="{!v.Empiduser}" maxlength="30" placeholder="Employee Id" required="true" size="20"/> <br/>
                                               <ui:inputSecret aura:id="FormId" label=" Password " class="" value="{!v.Empidpwd}" maxlength="10" placeholder="Password" required="true" size="20"/> <br/>
                               <div class="slds-float--left slds-button_brand">
                                              <div class="slds-grid buttons">
                                              <lightning:button variant="brand" label="Login" title="Login" iconPosition = "Left" onclick="{!c.handleLoginButtomClick}"/>
                                               </div>
                                                                </div>
                               </form>
                                                </div>
       </lightning:layoutItem>
   </lightning:layout>
</aura:component>
 
Controller.js
({
                handleLoginButtomClick : function(component, event, helper) {
                                  var testid = component.get("v.Empiduser");
          var testpw = component.get("v.Empidpwd");
          alert('******'+testid+testpw);
                 var action = component.get("c.getContacts");
                  action.setParams({
            "EmpidId": component.get("v.Empiduser"),
            "Emppwd": component.get("v.Empidpwd")
                                });
        alert('******'+testid+testpw);
    
    var self = this;
       action.setCallback(this, function(actionResult) {
               var rtnValue =actionResult.getReturnValue();
           alert('Value :'+rtnValue);
         if(rtnValue = "Correct User Name and Password" && rtnValue!="Wrong Username or Password"){
           var evt = $A.get("e.force:navigateToComponent");
                                evt.setParams({
                               componentDef : "c:ListofAvailableTest",
                               componentAttributes: {
                               AgentId : testid
                                                               }
                                                });
                                                                evt.fire();
 
                                                }
                });
         $A.enqueueAction(action);
       
   }
})
Apex Controller
public class Userempid {
                @AuraEnabled
                public static string getContacts(string EmpidId,string Emppwd) {
        List<custom_object__c> getContactsdebug = [Select Id, Password__c, EmpId__c From custom_object__c Where EmpId__c = :EmpidId and Password__c =:Emppwd];
        system.debug('getContactsdebug'+getContactsdebug);
       // return getContactsdebug;
                                //return [Select Id, Password__c, EmpId__c From custom_object__c Where EmpId__c = :EmpidId and Password__c =:Emppwd Limit 1];
        if(getContactsdebug.size() ==0 || getContactsdebug.isEmpty()){
          Return 'Wrong Username or Password';
        }
        else if(getContactsdebug.size() >0 && !(getContactsdebug.isEmpty()) && getContactsdebug.size() ==1 ){
           Return 'Correct User Name and Password';
        }
        else{
            Return 'Wrong Username or Password';
        }
    }
}
Second Component
<aura:component controller = "ListofAvailableTest" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
                <div class="slds-grid" style="background-color:lightGrey;padding:20px">
               <div class="slds-col" style=" font-size: 18px;font-weight: bold">
               Training Portal
        </div>
       
         <div class="slds-float--right" style=" font-size: 18px;font-weight: bold">
               Signed in as
        </div>
    </div>
   
     <aura:attribute name="AgentsAllowed" type="List" />
     <aura:attribute name="TestHistory" type="List" />
    <aura:attribute name="AgentId" type = "string" />
    <aura:attribute name="Password" type ="String"/>
    <aura:attribute name="recordId" type="String" />
     <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
     <lightning:layout class="slds-page-header slds-page-header--object-home" title ="Available Test">
        <lightning:layoutItem Title="Available Test">
            <div class="Tableheading" style="padding:10px">
               Available Test
            </div>
                                <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
              <thead>
                <tr class="slds-text-heading_label">
                  <th scope="col"><div class="slds-truncate" title="ID" style="font-weight:bold">ID</div></th>
                  <th scope="col"><div class="slds-truncate" title="Name" style="font-weight:bold">Name</div></th>
                  <th scope="col"><div class="slds-truncate" title="Test Name" style="font-weight:bold">Test Name</div></th>
                  <th scope="col"><div class="slds-truncate" title="Percentage" style="font-weight:bold">Percentage</div></th>
                </tr>
              </thead>
              <tbody>
                <aura:iteration items="{!v.AgentsAllowed}" var="AgentsAllowedlist">
                    <tr>
                        <th scope="row"><div class="slds-truncate" title="{!AgentsAllowedlist.Id}">{!AgentsAllowedlist.Id}</div></th>
                        <td><div class="slds-truncate" title="{!AgentsAllowedlist.Name}">{!AgentsAllowedlist.Name}</div></td>
                        <td><div class="slds-truncate" title="{!AgentsAllowedlist.Test_Name__r.name}">{!AgentsAllowedlist.Test_Name__r.name}</div></td>
                        <td><div class="slds-truncate" title="{!AgentsAllowedlist.Percentage__c}">{!AgentsAllowedlist.Percentage__c}</div></td>
                    </tr>
                    </aura:iteration>
              </tbody>
               </table>
         </lightning:layoutItem>
    </lightning:layout>
    <lightning:layout class="slds-page-header slds-page-header--object-home" title ="Available Test">
        <lightning:layoutItem Title="Available Test">
            <div class="Tableheading" style="padding:10px;">
               Test History
            </div>
                                <table class="slds-table slds-table_bordered slds-table_striped slds-table_cell-buffer slds-table_fixed-layout">
              <thead >
                <tr class="slds-text-heading_label">
                  <th scope="col"><div class="slds-truncate" title="Practice Link" style="font-weight:bold">Practice Link</div></th>
                  <th scope="col"><div class="slds-truncate" title="Reset Test" style="font-weight:bold">Reset Test</div></th>
                   <th scope="col"><div class="slds-truncate" title="Mobile - Offline Support" style="font-weight:bold">Mobile - Offline Support</div></th>
                  <th scope="col"><div class="slds-truncate" title="Test Name" style="font-weight:bold">Test Name</div></th>
                  <th scope="col"><div class="slds-truncate" title="Score" style="font-weight:bold">Score</div></th>
                  <th scope="col"><div class="slds-truncate" title="Total Questions" style="font-weight:bold">Total Questions</div></th>
                  <th scope="col"><div class="slds-truncate" title="Flag" style="font-weight:bold">Flag</div></th>
                </tr>
              </thead>
              <tbody>
                <aura:iteration items="{!v.TestHistory}" var="TestHistorylist">
                    <tr>
                        <th scope="row"><div class="slds-truncate" title="{!TestHistorylist.Id}">Practice Link</div></th>
                        <td><div class="slds-truncate" title="{!TestHistorylist.id}"><a href= "{!recordId }" >Reset </a></div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Name}">{TestHistorylist.Name}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Test_Name__c}">{!TestHistorylist.Test_Name__c}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Percentage__c}">{!TestHistorylist.Percentage__c}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Total_Questions__c}">{!TestHistorylist.Total_Questions__c}</div></td>
                        <td><div class="slds-truncate" title="{!TestHistorylist.Test_Completed__c}">{!TestHistorylist.Test_Completed__c}</div></td>
                       
                    </tr>
                    </aura:iteration>
              </tbody>
               </table>
         </lightning:layoutItem>
    </lightning:layout>
</aura:component>
 
Controller.js
({
      doInit: function(component, event, helper) {
               helper.getAgentsAllowedHelper(component);
      }
  
})
Helper
({
      // Fetch the accounts from the Apex controller
      getAgentsAllowedHelper: function(component) {
        var action = component.get('c.getAgentsAllowed');
        action.setParams({"AgentId":component.get("v.AgentId")});
         
        // Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
         component.set('v.AgentsAllowed', actionResult.getReturnValue());
        self.getTestHistoryHelper(component);
        });
        $A.enqueueAction(action);
      },
    getTestHistoryHelper: function(component) {
        var action = component.get('c.getTestHistory');
        // Set up the callback
        var self = this;
        action.setCallback(this, function(actionResult) {
         component.set('v.TestHistory', actionResult.getReturnValue());
        });
        $A.enqueueAction(action);
      }
    })
Apex Controller : 2nd component
public class ListofAvailableTest {
      @AuraEnabled
     public static List<Agents_Allowed__c> getAgentsAllowed(string AgentId) { 
        List<Agents_Allowed__c> listToReturn = [SELECT Id, name,Agent_Name__c,Emp_ID__c,Full_Name__c,Test_Name__c,Percentage__c,Agent_Name__r.EmpId__c  FROM Agents_Allowed__c WHERE Agent_Name__r.EmpId__c =: AgentId];
                system.debug('listToReturn'+listToReturn);
         return listToReturn;
      
     }
    @AuraEnabled
    public static List <Agents_Test_Result__c> getTestHistory() {
        return [SELECT Id, name,Agent_Name__c,Agent_Full_Name__c,Test_Name__c,Test_Name__r.name,Percentage__c,Total_Questions__c,Test_Completed__c FROM Agents_Test_Result__c where Test_Completed__c = true];
      }
    }
Visualforce Page:
<apex:page showHeader="false" standardStylesheets="false">
     <apex:includeLightning />
 <div id="loginpageId" />
<script>
        $Lightning.use("c:LoginPageApp",
            function(){
                $Lightning.createComponent(
                "c:NewLoginPage",
                    {},
                    "loginpageId",
                    function(cmp){
                    console.log('done');
                     window.alert('i am in');
                    }
                );
            }
        );
    </script>
         
</apex:page>
 
  • April 05, 2019
  • Like
  • 0
Hi everyone,

I am trying to write a trigger for a requirement where a new record should not be created if the dates overlap. There are 2 objects Event1 (Campaign renamed) and Attendee. There is a junction object Event Attendee which allows an attendee to register for an Event. If an attendee is already registered for an event then he/she should not be able to register for any other event which falls on those dates or whose start or end dates overlap the already registered event dates. When I execute my trigger, I get an error for every event-attendee record instead of only for those which satisfies the condition. Please help me with the trigger.
This is the trigger:
 
@isTest
private class venueupdatetriggerhandlerTest{
     static testmethod void TestRecordCreate(){
     
            venue__c Ven = new venue__c();           
            campaign evn = new campaign();
             Ven.Name = 'test1';
             Ven.Location__c = 'Pune';
             Ven.Capacity__c = 100;
            insert Ven;
         system.debug('Venue created with id'+ ven.Id);
            evn.name = 'Test Event';
            insert evn;
            Session__c sesstest = new   Session__c();
            sesstest .Name = 'test2';
            sesstest .venue__c = Ven.id;
            sesstest.Event1__c = evn.id;
            sesstest.Start_Time__c=datetime.newInstance(2019, 4, 20, 12, 30, 0);
            sesstest.End_Time__c=datetime.newInstance(2019, 4, 20, 12, 40, 0);
            sesstest.Level__c = 'Beginner';
            sesstest.Type__c = 'Workshop';
            insert sesstest ;
            
                 
         system.assertequals(1, [select count() from session__c where venue__c=:ven.id] );
        }
         static testmethod void TestRecordUpdate(){
             campaign evn = new campaign();
             evn.name = 'Test Event 2';
             insert evn;
            List<venue__c> Ven = new List<venue__c>();
            venue__c Ven1 = new venue__c();
            Ven1 .Name = 'test1';
             Ven1.Location__c = 'Pune';
             Ven1.Capacity__c = 100;
            Ven.add(Ven1);
            venue__c Ven2 = new venue__c();
            Ven2.Name = 'test2';
             Ven2.Location__c = 'Pune';
             Ven2.Capacity__c = 100;
            Ven.add(Ven2);
            insert Ven;
            
            Session__c sesstest = new   Session__c();
            sesstest .Name = 'test2';
            sesstest .venue__c = Ven1.id;
            sesstest.Event1__c = evn.Id;
            sesstest.Start_Time__c=datetime.newInstance(2019, 4, 20, 12, 30, 0);
            sesstest.End_Time__c=datetime.newInstance(2019, 4, 20, 12, 40, 0);
            sesstest.Level__c = 'Beginner';
            sesstest.Type__c = 'Workshop';
            insert sesstest ;
            sesstest .venue__c = Ven2.id;
            update sesstest;
            system.assertequals(1, [select count() from session__c where venue__c=:ven2.id] );
            system.assertequals(0, [select count() from session__c where venue__c=:ven1.id] );
            
        }
        static testmethod void TestRecordAfterDelete(){
            campaign evn = new campaign();
            evn.name = 'Test Event 3';
            insert evn;
            List<venue__c> Ven = new List<venue__c>();
            venue__c Ven1 = new venue__c();
            Ven1 .Name = 'test1';
            Ven1.Location__c = 'Pune';
             Ven1.Capacity__c = 100;
            Ven.add(Ven1);
            insert Ven;
            
            Session__c sesstest = new   Session__c();
            sesstest .Name = 'test2';
            sesstest .venue__c = Ven1.id;
            sesstest.Event1__c = evn.Id;
            sesstest.Start_Time__c=datetime.newInstance(2019, 4, 20, 12, 30, 0);
            sesstest.End_Time__c=datetime.newInstance(2019, 4, 20, 12, 40, 0);
            sesstest.Level__c = 'Beginner';
            sesstest.Type__c = 'Workshop';
            insert sesstest ;
            Delete sesstest;
            system.assertequals(0, [select count() from session__c where venue__c=:ven1.id] );
            
            
        }
        static testmethod void TestRecordAfterUndelete(){
            campaign evn = new campaign();
            evn.name = 'Test Event 4';
            insert evn;
            List<venue__c> Ven = new List<venue__c>();
            venue__c Ven1 = new venue__c();
            Ven1 .Name = 'test1';
            Ven1.Location__c = 'Pune';
             Ven1.Capacity__c = 100;
            Ven.add(Ven1);
            insert Ven;
            
            Session__c sesstest = new   Session__c();
            sesstest .Name = 'test2';
            sesstest .venue__c = Ven1.id;
            sesstest.Event1__c = evn.id;
            sesstest.Start_Time__c=datetime.newInstance(2019, 4, 20, 12, 30, 0);
            sesstest.End_Time__c=datetime.newInstance(2019, 4, 20, 12, 40, 0);
            sesstest.Level__c = 'Beginner';
            sesstest.Type__c = 'Workshop';
            insert sesstest ;
            Delete sesstest;
            Undelete sesstest;
            system.assertequals(1, [select count() from session__c where venue__c=:ven1.id] );
            
            
        }
        
 }
Hi,
i need to create a report with leads and opportunity's goal with month wise .here i have attached the image for refernce User-added image
I have two lightning components and the first component is like a login page and once the login is successful the other component should be called. My code is working fine if I add the component in the record page but if I try to call the component via visualforce page it throws me the below error:
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Callback failed: apex://Userempid/ACTION$getContacts Failing descriptor: {c:NewLoginPage}

where c:NewLoginPage - the login pagei.e First component
Userempid - apex controller for the first component.

can you please help me with this.
 
  • December 04, 2018
  • Like
  • 0