• Jacob Elliott 8
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hello, I am trying to unlock a "Matter" record when the record goes into an approval process. A trigger will see that it is locked and then unlock the record. This is working, but my test class is only covering 66%. How can I get it to 100%? Thanks!

Trigger
trigger UnlockMatter on litify_pm__Matter__c (after insert, after update) {
    for(litify_pm__Matter__c matter : trigger.New) {
        If(Approval.isLocked(matter.Id)) {
            Approval.unlock(matter.Id);
        }
    }
}

Test Class
@isTest
public class TestUnlockMatter {
     @isTest static void TestEditMatterInApproval() {
          // Test data setup
          
          // Create A Party to assign to the matter
          Account party = new Account(litify_pm__First_Name__c='Jim', litify_pm__Last_Name__c='Halpert');
          insert party;
          
          // Create A Matter that is locked and unlock and edit it
          litify_pm__Matter__c matter = new litify_pm__Matter__c(litify_pm__Display_Name__c='Jim Halpert vs. Dwight Schrute', litify_pm__Client__c= party.Id);
          insert matter;
          Approval.lock(matter.Id);
         
         //Perform Test
         Test.startTest();
         Approval.unlock(matter.Id);
         matter.litify_pm__Display_Name__c ='Jim Halpert vs. Micheal Scott';
         Test.stopTest();
     }
}

 
I am trying to allow a user to select an object from a dropdown, and based on the chosen object, return a random number of records. The problem I'm having is that I am having trouble returning different types of object lists in the controller. What is the appropriate way to do this?

Controller
public with sharing class SearchObjectsToAudit {
    @AuraEnabled(Cacheable=true)
    public static Account[] searchAccounts(){
         return [SELECT Id, Name FROM Account ORDER BY Name LIMIT 50];
    }
    @AuraEnabled(Cacheable=true)
    public static Bear__c[] searchIntakes(){
         return [SELECT Id, Name FROM Intake ORDER BY Name LIMIT 50];
    }
    @AuraEnabled(Cacheable=true)
    public static Contact[] searchMatters(){
         return [SELECT Id, Name FROM Contact ORDER BY Name LIMIT 50];
    }
    @AuraEnabled(Cacheable=true)
    public static SearchObjects(String searchTerm) {
         System.debug(searchTerm);
         if (searchTerm == 'Account') {
            return searchAccounts();
        }

        else if (searchTerm == 'Intake') {
            return searchIntakes();
        }

        else if (searchTerm == 'Matters') {
            return searchMatters();
        }
        return null;
    }
}

HTML
<template>
    <lightning-combobox
        name="object"
        label="Object"
        value={searchTerm}
        placeholder="Select Object To Audit"
        options={options}
        onchange={handleChange} >
    </lightning-combobox>

    <lightning-card title="Bears" icon-name="utility:animal_and_nature">
			<div class="slds-card__body_inner">
				<!-- Start bear list -->
				<template if:true={bears.data}>
					<lightning-layout multiple-rows="true" pull-to-boundary="small">
						<template for:each={bears.data} for:item="bear">
							<lightning-layout-item key={bear.Id} size="3" class="slds-p-around_x-small">
                                    <p>{bear.Name}</p>
							</lightning-layout-item>
						</template>
					</lightning-layout>
					<!-- No bears found -->
					<template if:false={hasResults}>
						<div class="slds-align_absolute-center slds-m-vertical_small">
							This is beary disturbing, we did not find results...
						</div>
					</template>
				</template>
				<!-- End bear list -->
				<!-- Data failed to load -->
				<template if:true={bears.error}>
					<div class="slds-text-color_error">
						An error occurred while loading the bear list
					</div>
				</template>
			</div>
		</lightning-card>
</template>

JS File
import { LightningElement, track, wire} from 'lwc';
import SearchObjects from '@salesforce/apex/SearchObjectsToAudit.SearchObjects';
export default class ComboboxBasic extends LightningElement {
    @track value = 'Account';
    @track searchTerm = '';
	@wire(SearchObjects, {searchTerm: '$searchTerm'})
	bears;

    get options() {
        return [
            { label: 'Account', value: 'Account' },
            { label: 'Intake', value: 'Intake' },
            { label: 'Matter', value: 'Matter' },
        ];
    }

    handleChange(event) {
        window.clearTimeout(this.delayTimeout);
		const searchTerm = event.target.value;
		// eslint-disable-next-line @lwc/lwc/no-async-operation
		this.delayTimeout = setTimeout(() => {
			this.searchTerm = searchTerm;
		}, 300);

        this.value = event.detail.value;
    }
}


 
Hello, I am trying to iterate over a list of SObjects, but I'm not sure how to get it to display.

Here is the controller
public with sharing class RandomRecordAudit {
    @AuraEnabled(cacheable=true)
    public static map<string, string> getAllObjects(){
        map<string, string> objectList = new map<string, string>();
        for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
        {
            Schema.DescribeSObjectResult objResult = o.getDescribe();
            objectList.put(objResult.getName(), objResult.getLabel());
        }
        return objectList;
    } 
}

Here is the JS file
import { LightningElement, track } from 'lwc';
import getAllObjects from '@salesforce/apex/RandomRecordAudit.getAllObjects';
export default class SObjectList extends LightningElement {
    
        @track objects;
        @track error;
    
        handleLoad() {
            getAllObjects()
                .then(result => {
                    this.objects = result;
                })
                .catch(error => {
                    this.error = error;
                });
        
    }
}

and here is the HTML
<template>
    <lightning-card title="ApexImperativeMethod" icon-name="custom:custom63">
        <div class="slds-m-around_medium">
            <template if:true={objects}>
                <template for:each={objects} for:item="object">
                    <p key={object.Id}>{object.Name}</p>
                </template>
            </template>
            <template if:true={error}>
                <p>Error</p>
                <c-error-panel errors={error}></c-error-panel>
            </template>
        </div>
    </lightning-card>
</template>

Any help is greatly appreciated, thanks!​​​​​​​
Hello, I am trying to unlock a "Matter" record when the record goes into an approval process. A trigger will see that it is locked and then unlock the record. This is working, but my test class is only covering 66%. How can I get it to 100%? Thanks!

Trigger
trigger UnlockMatter on litify_pm__Matter__c (after insert, after update) {
    for(litify_pm__Matter__c matter : trigger.New) {
        If(Approval.isLocked(matter.Id)) {
            Approval.unlock(matter.Id);
        }
    }
}

Test Class
@isTest
public class TestUnlockMatter {
     @isTest static void TestEditMatterInApproval() {
          // Test data setup
          
          // Create A Party to assign to the matter
          Account party = new Account(litify_pm__First_Name__c='Jim', litify_pm__Last_Name__c='Halpert');
          insert party;
          
          // Create A Matter that is locked and unlock and edit it
          litify_pm__Matter__c matter = new litify_pm__Matter__c(litify_pm__Display_Name__c='Jim Halpert vs. Dwight Schrute', litify_pm__Client__c= party.Id);
          insert matter;
          Approval.lock(matter.Id);
         
         //Perform Test
         Test.startTest();
         Approval.unlock(matter.Id);
         matter.litify_pm__Display_Name__c ='Jim Halpert vs. Micheal Scott';
         Test.stopTest();
     }
}

 
Can Anyone helps we I am trying to deploy below Task trigger from Sandbox to Production but getting error "the following triggers have 0% code coverage. Each trigger must have at least 1% code coverage."

In the below trigger I am trying to create update lead status to "Intro call" when a task is create with Subject contain "Intro call" this code work fine in sandbox but gives code coverage error while deployment.

I am new to devolopment /Coding 

trigger changeLeadStatus on Task (before insert, before update) {
    String desiredNewLeadStatus = 'Intro Call';
    String myString;

    List<Id> leadIds=new List<Id>();
    for(Task t:trigger.new){
    mystring=t.subject.toUpperCase();
        if(t.Status=='Completed' && myString.contains('INTRO CALL')){
            if(String.valueOf(t.whoId).startsWith('00Q')==TRUE){//check if the task is associated with a lead
                leadIds.add(t.whoId);
            }//if 2
        }//if 1
    }//for
    List<Lead> leadsToUpdate=[SELECT Id, Status FROM Lead WHERE Id IN :leadIds AND IsConverted=FALSE];
    For (Lead l:leadsToUpdate){
        l.Status=desiredNewLeadStatus;
    }//for
    
    try{
        update leadsToUpdate;
    }catch(DMLException e){
        system.debug('Leads were not all properly updated.  Error: '+e);
    }
}//trigger
I have a simple SOQL query that I can run using developer console or workbench and it runs fine. But when I copy/paste it into anonymous apex it complains the the field I'm requesting does not exist.  How can that be?  I am running this as a system admin and I *do* have authority to the field. 

Here's a screenshot showing the query in developer workbench side-by-side with anonymous apex and the results.

SOQL Query vs Apex soql query
 
Hello, I am trying to iterate over a list of SObjects, but I'm not sure how to get it to display.

Here is the controller
public with sharing class RandomRecordAudit {
    @AuraEnabled(cacheable=true)
    public static map<string, string> getAllObjects(){
        map<string, string> objectList = new map<string, string>();
        for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() )
        {
            Schema.DescribeSObjectResult objResult = o.getDescribe();
            objectList.put(objResult.getName(), objResult.getLabel());
        }
        return objectList;
    } 
}

Here is the JS file
import { LightningElement, track } from 'lwc';
import getAllObjects from '@salesforce/apex/RandomRecordAudit.getAllObjects';
export default class SObjectList extends LightningElement {
    
        @track objects;
        @track error;
    
        handleLoad() {
            getAllObjects()
                .then(result => {
                    this.objects = result;
                })
                .catch(error => {
                    this.error = error;
                });
        
    }
}

and here is the HTML
<template>
    <lightning-card title="ApexImperativeMethod" icon-name="custom:custom63">
        <div class="slds-m-around_medium">
            <template if:true={objects}>
                <template for:each={objects} for:item="object">
                    <p key={object.Id}>{object.Name}</p>
                </template>
            </template>
            <template if:true={error}>
                <p>Error</p>
                <c-error-panel errors={error}></c-error-panel>
            </template>
        </div>
    </lightning-card>
</template>

Any help is greatly appreciated, thanks!​​​​​​​
Hello,

I have been a certified admin for almost a year now and want to take the next step and learn to be a Salesforce developer. I'm concerned though since I've never written a line of code in my life and have no dev. experience.

In reading some of the Developer 1 trailhead modules, it seems like they already expect you to have development experience before you take the trailheads. My question is this:

Can you learn to be an SF developer from nothing else but the trailhead modules or do you realistically need to learn to program before you start them to have any frame of reference? If the ladder is true, which programming language(s) do I need to learn? I'm kind of lost.

Please help.
Thanks.