- TobyKutler
- NEWBIE
- 144 Points
- Member since 2020
- Salesforce Developer
- Salesforce
-
ChatterFeed
-
4Best Answers
-
1Likes Received
-
1Likes Given
-
3Questions
-
57Replies
hi, i need to get my max salary from the custom object(employye__c)from give passing parameter called position__c if any postion given in parameter a max salary should be get.
List<Employee__c> existingEmployees = [SELECT Id, Name, Position__c, Salary__c FROM Employee__c];
integer MaxSalary= existingEmployees[0].Salary__c;
for(Employee__c emp:existingEmployees){
if((emp.Position__c==position)&&(emp[1].Salary__c>MaxSalary)){
MaxSalary=emp[1].Salary__c;
}
}system.debug('The max salary of'+position+ 'and its salary is'+MaxSalary);
}
pls help me with my code and here is my code. am getting 2 errors as illegal assignemnt from Decimal to integer and Expression must be list type:Employee__c
- Visithra
- March 30, 2023
- Like
- 0
- Continue reading or reply
Most efficient way to compare two collections, lists, maps or other
Hi Community,
I'm new to developing and I'm keen to learn the best way to compare two collections for future use on a trigger or method.
For example for an investigation into org missing data if I wanted to compare Leads and Accounts to check which Leads had matching email addresses with Accounts but other personal information was diffrerent.
At the moment I only know how to do this with two for loops but there must be a better way? possibly using maps or a map and list?
Account[] personalAccounts = [SELECT Id, FirstName, LastName, Phone, PersonMobilePhone, PersonEmail, EmployerCode__c, DOB__c FROM Account WHERE LastName != null AND PersonEmail != null AND DOB__c != null];
Lead[] leads = [SELECT Id, FirstName, LastName, Phone, MobilePhone, Email, Employer_Code__c, DOB__c FROM Lead WHERE Email != null AND DOB__c != null];
Sudo code
for Leads {
for Accounts {
If (Lead.email == Account.PersonalEmail && Lead.DOB__c != Account.DOB__c && Lead.EmployerCode__c != Account.EmployerCode__c etc )
cleanUpMap.put(Lead.Id, Account.Id);
}
}
Appreciate the help, sorry for the terrible code.
- Brendan M
- March 28, 2023
- Like
- 0
- Continue reading or reply
LWC - Show icons Horizontally
Can you help to display the icons horizontally
i used this .icon { display: inline-block; } but its not working
code:
<template>
<lightning-card>
<div class="icon">
<fieldset class="slds-form-element">
<legend class="slds-form-element__legend slds-form-element__label">feedback form</legend>
<lightning-helptext content="Your feed back helps us to improve"></lightning-helptext>
<div class="slds-form-element__control">
<template if:true={options}>
<template for:each={options} for:item="opt">
<span key={opt.key} class="slds-radio">
<input type="radio" id={opt.key} value={opt.value} name="default" onchange={handleOnchange} />
<label class="slds-radio__label" for={opt.key}>
<span class="slds-radio_faux"></span>
<span class="slds-form-element__label">
<lightning-icon icon-name={opt.icon_name} alternative-text="Approved" title="Approved" size="large" class={opt.class}>
</lightning-icon>
</span>
</label>
</span>
</template>
</template>
</div>
</fieldset>
</div>
<div class="slds-box">
<p>{value}</p>
</div>
<div class="slds-box">
<p>{valueList}</p>
</div>
<lightning-icon icon-name="utility:info_alt" alternative-text="Approved" title="Approved" size="small">
</lightning-icon>
</lightning-card>
</template>
=========================
import { LightningElement } from 'lwc';
export default class RadioGroupButton extends LightningElement {
value = '';
valueList = [];
options = [
{ label: 'Happy', value: 'Happy', icon_name: 'utility:smiley_and_people', class: 'green-rocket' },
{ label: 'UnHappy', value: 'UnHappy', icon_name: 'utility:emoji', class: 'blue-icon' },
{ label: 'Neutral', value: 'Neutral', icon_name: 'utility:sentiment_neutral', class: 'orange-rocket' },
{ label: 'Negative', value: 'Extremely Unhappy - Escalate', icon_name: 'utility:sentiment_negative', class: 'red-icon' },
];
connectedCallback() {
const copy = [];
for (let i = 0; i < this.options.length; i++) {
copy.push({ key: i, label: this.options[i].label, value: this.options[i].value, icon_name: this.options[i].icon_name, class: this.options[i].class })
};
this.options = copy;
}
handleOnchange(event) {
console.log('event', event.target.name);
console.log('event', event.target.value);
this.value = event.target.value;
this.valueList.push(event.target.value);
}
}
=================
.css
.icon { display: inline-block; }
- Lwc Seekar
- December 17, 2022
- Like
- 0
- Continue reading or reply
Hide and show text on a single button click
I have requirement, when I ckick a button text shoud come and when I ckick the same button the text shoud hide. I'm not able to hide on the same button click. Please assist. Below is my code.
html- <lightning-button label={ShowText} title="Show text" onclick={handleClick} class="slds-m-left_x-small"></lightning-button> <div style=" margin-top: -30%; left: 550%; margin-left: -30px; background: linear-gradient(#fff, #dbe4eb); border-color:#555 transparent transparent transparent;color: #111; border: 1px solid black;" if:true={showText1}>{textValue}</div> JS- @track ShowText='Show text' @track showText1 = false; textValue = 'Some text value'; handleClick(event){ const label=event.target.label; if(label==='Show text'){ this.Showtext='Hide text'; this.showText1 = true; }else if(label==='Hide text'){ this.Showtext='Show text'; this.showText1 = false; } }
- Amy J
- August 22, 2022
- Like
- 0
- Continue reading or reply
Salesforce Pipeline Inspector Not showing Users at top of the hierarchy other users
I cannot choose from any other users in my org other than me. According to this documentation (https://help.salesforce.com/s/articleView?id=sf.pipeline_inspection_considerations.htm&type=5) the User can see other users below them in the hierarchy. I am at the top of the hierarchy but still see no users. Does anyone have any idea what else could be causing it?
- TobyKutler
- March 30, 2023
- Like
- 0
- Continue reading or reply
redirect not working in firefox
public PageReference redirectToOpportunity(){ String opportunityId = getId(); system.debug('in go back to opportunity apex' + opportunityId); return new PageReference('/lightning/r/Opportunity/'+opportunityId+'/view'); }
The above code works perfectly fine in Chrome but does not redirect when using Firefox. I get the following logs when testing in firefox:
- TobyKutler
- March 10, 2023
- Like
- 1
- Continue reading or reply
Create Lightning email template with task as related entity type
- TobyKutler
- August 23, 2022
- Like
- 0
- Continue reading or reply
redirect not working in firefox
public PageReference redirectToOpportunity(){ String opportunityId = getId(); system.debug('in go back to opportunity apex' + opportunityId); return new PageReference('/lightning/r/Opportunity/'+opportunityId+'/view'); }
The above code works perfectly fine in Chrome but does not redirect when using Firefox. I get the following logs when testing in firefox:
- TobyKutler
- March 10, 2023
- Like
- 1
- Continue reading or reply
Salesforce Pipeline Inspector Not showing Users at top of the hierarchy other users
I cannot choose from any other users in my org other than me. According to this documentation (https://help.salesforce.com/s/articleView?id=sf.pipeline_inspection_considerations.htm&type=5) the User can see other users below them in the hierarchy. I am at the top of the hierarchy but still see no users. Does anyone have any idea what else could be causing it?
- TobyKutler
- March 30, 2023
- Like
- 0
- Continue reading or reply
hi, i need to get my max salary from the custom object(employye__c)from give passing parameter called position__c if any postion given in parameter a max salary should be get.
List<Employee__c> existingEmployees = [SELECT Id, Name, Position__c, Salary__c FROM Employee__c];
integer MaxSalary= existingEmployees[0].Salary__c;
for(Employee__c emp:existingEmployees){
if((emp.Position__c==position)&&(emp[1].Salary__c>MaxSalary)){
MaxSalary=emp[1].Salary__c;
}
}system.debug('The max salary of'+position+ 'and its salary is'+MaxSalary);
}
pls help me with my code and here is my code. am getting 2 errors as illegal assignemnt from Decimal to integer and Expression must be list type:Employee__c
- Visithra
- March 30, 2023
- Like
- 0
- Continue reading or reply
Most efficient way to compare two collections, lists, maps or other
Hi Community,
I'm new to developing and I'm keen to learn the best way to compare two collections for future use on a trigger or method.
For example for an investigation into org missing data if I wanted to compare Leads and Accounts to check which Leads had matching email addresses with Accounts but other personal information was diffrerent.
At the moment I only know how to do this with two for loops but there must be a better way? possibly using maps or a map and list?
Account[] personalAccounts = [SELECT Id, FirstName, LastName, Phone, PersonMobilePhone, PersonEmail, EmployerCode__c, DOB__c FROM Account WHERE LastName != null AND PersonEmail != null AND DOB__c != null];
Lead[] leads = [SELECT Id, FirstName, LastName, Phone, MobilePhone, Email, Employer_Code__c, DOB__c FROM Lead WHERE Email != null AND DOB__c != null];
Sudo code
for Leads {
for Accounts {
If (Lead.email == Account.PersonalEmail && Lead.DOB__c != Account.DOB__c && Lead.EmployerCode__c != Account.EmployerCode__c etc )
cleanUpMap.put(Lead.Id, Account.Id);
}
}
Appreciate the help, sorry for the terrible code.
- Brendan M
- March 28, 2023
- Like
- 0
- Continue reading or reply
country field as Multi-select of countries which will be saved as a comma separated list
I have a requirement where I've to use Country field as multi-select of countries which will be saved as a comma separated list. I display this field on the screen flow. Could anyone help on this "how to achieve multi-select field of countries which will be saved as a comma separated list.
Thanks in advance!
- Shreyanka
- March 27, 2023
- Like
- 0
- Continue reading or reply
Need assistance with a countUP timer
I'm trying to create a countup timer. I need a timer that counts the seconds, minutes, and hours while working within an object. When the object is closed it should save the time spent... when it is reopened the clock countup should start where it was left off. I would need an override button to cease all counting.
Thank you,
-Adam
- Advantage Sleep Centers
- March 15, 2023
- Like
- 0
- Continue reading or reply
redirect not working in firefox
public PageReference redirectToOpportunity(){ String opportunityId = getId(); system.debug('in go back to opportunity apex' + opportunityId); return new PageReference('/lightning/r/Opportunity/'+opportunityId+'/view'); }
The above code works perfectly fine in Chrome but does not redirect when using Firefox. I get the following logs when testing in firefox:
- TobyKutler
- March 10, 2023
- Like
- 1
- Continue reading or reply
Multiple IF functions
Hello,
I need help with a IF formula. I am attempting to calculate the number of times a patron has participated in an activity within our organization.
Right now I am using the formula below to calculate how many people within a report have donated since joining.
IF(Group_Roster__c.eGroup_Join_Date__c > Contact.npo02__FirstCloseDate__c, 0, 1)
This formula is working. However I want to take it a step further by also calculating how many people have given, served at an event. Basically I am trying to combine two IF formulas together but I keep getting an error saying there are too many IF functions.
IF(Group_Roster__c.eGroup_Join_Date__c < Contact.npo02__FirstCloseDate__c,0, 1)IF(Group_Roster__c.eGroup_Join_Date__c < Contact.GW_Volunteers__First_Volunteer_Date__c,0, 1)
Is it possible to combine two IF functions and if not is there another way I can do this? I am trying to calculate the number of people who took an additional step of participating within our organization after joining.
Any advice woud be appreciated!
- Chelsey Dietz
- March 08, 2023
- Like
- 0
- Continue reading or reply
How to select checkbox when we click anywhere in the Layout
1.layout item=checkbox
2.layout item =Text
3.layout item =button
Now I want to select this checkbox when I click anywhere in that layout.
- User Seth
- December 28, 2022
- Like
- 0
- Continue reading or reply
Am I getting this error when I run following code? Insufficient Privileges Errors.
<apex:pageBlock title="Registration">
<apex:pageBlockSection title="Related Info" columns="1">
<apex:outputField value="{!Account.Name}"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="Related Info" columns="1">
<apex:relatedList list="Cases"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
- Javaid Hussain
- December 23, 2022
- Like
- 0
- Continue reading or reply
Refresh LWC component
I have a LWC component which shows list of records . I am fetching the records from apex with WIRE decorator if a case staus is 'New'. Now if I change the status to New to Close , I still can see the data. I have to manually refresh the data to make it disappear. I want as soon I change the status from new to close at that time the LWC should auto refresh.
Please help me on this. Thanks in advance.
P.S. - I am updating the status from Case's standard UI.
- Shuhbam Sinha
- December 23, 2022
- Like
- 0
- Continue reading or reply
Auto Creation using automation
Contract
Order
Order Line Items
----------------------------------------
Order is lookup to Contract
Order Line Item is lookup with Order
--------------------------------------------------
Need to do an automation that,
First order will be dispatched on the upcoming Wednesday. Every order after that will be dispatched on Wednesday, a month after the first order.
Contract object is having a picklist field having value Paused and Canceled.
Thanks
- Sudeep Singh
- December 23, 2022
- Like
- 0
- Continue reading or reply
How to design a custom button.?
Hello Folks,
I want to design a custom button such that when user click on that custom button, a drop down should appear with list of emeil template, followed by editable Email Body and recipient name. Finally, clocking on Send button in dropdown, Email will be sent to recipient. How to perform this tak? Using Trigger or Lightning Flows? Plz Suggest.
- Kunal Purohit 4
- December 23, 2022
- Like
- 0
- Continue reading or reply
Unable to make ContactId field to Null on Case object
Tried calling a Queueable class to update case record on Case After update trigger, but it still did not work when the owner is community user.
Please suggest. below is the Queueable class called from case after update trigger context. (used after update context even though update is on same object, tried before update and could see ContactId was getting updated back to case owner)
public class CaseContactUpdateQueueable implements Queueable { private Map<Id,Case> newMap; public CaseContactUpdateQueueable(Map<Id,Case> newMap) { this.newMap = newMap; } public void execute(QueueableContext context) { List<Case> caseList = new List<Case>(); for(Case cs:newMap.values()){ if(cs.ContactId != null)){ caseList.add(new Case(Id = cs.Id,ContactId = null)); } } update caseList; } }
- sshawkins
- December 22, 2022
- Like
- 0
- Continue reading or reply
create 2 custom object main Object & Copy Object
- Prakhyat sapra
- December 21, 2022
- Like
- 0
- Continue reading or reply
How to create Mock test methods for an Apex class that contains a method with a return type as void?
First, see the below example that I have taken from trailhead modules.
public class AnimalsCallouts { public static HttpResponse makePostCallout() { Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint('https://th-apex-http-callout.herokuapp.com/animals'); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json;charset=UTF-8'); request.setBody('{"name":"mighty moose"}'); HttpResponse response = http.send(request); // Parse the JSON response if(response.getStatusCode() != 201) { System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus()); } else { System.debug(response.getBody()); } return response; } }
@isTest global class AnimalsHttpCalloutMock implements HttpCalloutMock { // Implement this interface method global HTTPResponse respond(HTTPRequest request) { // Create a fake response HttpResponse response = new HttpResponse(); response.setHeader('Content-Type', 'application/json'); response.setBody('{"animals": ["majestic badger", "fluffy bunny", "scary bear", "chicken", "mighty moose"]}'); response.setStatusCode(200); return response; } }
@isTest static void testPostCallout() { // Set mock callout class Test.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock()); // This causes a fake response to be sent // from the class that implements HttpCalloutMock. HttpResponse response = AnimalsCallouts.makePostCallout(); // Verify that the response received contains fake values String contentType = response.getHeader('Content-Type'); System.assert(contentType == 'application/json'); String actualValue = response.getBody(); System.debug(response.getBody()); String expectedValue = '{"animals": ["majestic badger", "fluffy bunny", "scary bear", "chicken", "mighty moose"]}'; System.assertEquals(expectedValue, actualValue); System.assertEquals(200, response.getStatusCode()); }
Here in the above case, we are faking our response in Mock class so whenever the test class method is going to call our apex class we are going to receive a mocked response which we going to put in assertion with our expected response.
In our project, apex classes contain a future method with the return type as void (actually they are getting called by triggers to post something externally whenever a record is created in salesforce). So in that case, is there a way to receive a fake response in test class when my apex class methods return nothing? (Assume below as my project classes)
public class AnimalsCallouts { public static void makePostCallout() { Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(...); request.setMethod('POST'); request.setBody(...); HttpResponse response = http.send(request); if(response.getStatusCode() != 201) { System.debug('...'); } else { System.debug('...'); } } }
@isTest global class AnimalsHttpCalloutMock implements HttpCalloutMock { global HTTPResponse respond(HTTPRequest request) { .... .... return response; } }
@isTest static void testPostCallout() { Test.setMock(HttpCalloutMock.class, new AnimalsHttpCalloutMock());HttpResponse response =AnimalsCallouts.makePostCallout(); (i can't recieve this inside a variable because method is returning nothing.) String actualValue = response.getBody(); String expectedValue = '....'; System.assertEquals(expectedValue, actualValue); }
- ACN Connect
- December 06, 2022
- Like
- 0
- Continue reading or reply
Apex how to check view is Salesforce Classic or Lightning.
How i can check on controller if page is opened using 'Salesforce Classic' or 'Salesforce lightning' UI(for winter 16 release).
Thanks,
Kanwalpreet Singh
- Kanwalpreet Singh
- September 01, 2015
- Like
- 2
- Continue reading or reply
I implemented a Double Linked List in Apex - check it out!
All of the code will be continually updated here - https://github.com/iamjake648/ApexLinkedList. Feel free to submit pull requests as well! I'll post the current code below.
/** * LinkedList - Written by Jacob Schultz 13.4.16 * A simple double linked list class written in apex * This LL allows you to store SObjects and values/weights, and then add * them in order to a list and keep them sorted - unlike a map. * * #TODO: Methods * -Merge Sort * -Delete by Object * -Delete by Value * * This is still under development, and is subject to change. * This could also be easily modified to store Lists of SObjects */ public class LinkedList { private SNode head; private Integer size; private SNode tail; /** * Constructor - Creates a new Linked List */ public LinkedList(){ this.head = null; this.size = 0; } /** * addToList - Creates a new SNode from an SObject and value, * and then adds it to the list NOT IN ORDER, just adds to the end. * @param SObject obj - Any SObject (User, Case, Opp, etc.) * @param Int value - A weight or index to give the SObject */ public void addToList(SObject obj, Integer value){ //Create a new SNode SNode n = new SNode(obj, value); Snode temp = this.head; //First Item in the List if (temp == null){ head = n; } else { //Walk to the end of the list while(temp.getNext() != null){ temp = temp.getNext(); } //Add to the end of the list temp.setNext(n); n.setPrevious(temp); } //Increase the size of the list this.size++; } /** * deleteAtIndex - Deletes an SNode at a given Index * Walks down the list until it reaches the index provided, * then deletes the SNode and retains list order. * @param Int i - Index to delete at */ public void deleteAtIndex(Integer i){ //Make sure that index is in the list if (i < getSize()){ SNode temp = this.head; Integer c = 0; //Walk down the list to the index while (c < i){ c++; temp = temp.getNext(); } SNode toDelete = temp; //Remove from list by changing the two nodes around it toDelete.getPrevious().setNext(toDelete.getNext()); toDelete.getNext().setPrevious(toDelete.getPrevious()); //Set the old objects to null temp = null; toDelete = null; } else { System.debug('Unable to delete at this index.'); } } /** * addInOrder - Creates a new SNode and adds it to the list in order * This allows the list to remain sorted, without * ever calling a sort method. * @param SObject obj - Any SObject (User, Case, Opp, etc.) * @param Int value - A weight or index to give the SObject */ public void addInOrder(SObject obj, Integer value){ SNode n = new SNode(obj, value); Snode temp = this.head; //First Item in the List if (temp == null){ head = n; } else { Integer depth = 0; //Walk down the list while (temp.getNext() != null && temp.getValue() < value){ temp = temp.getNext(); depth++; } //If the value is less than the head if (depth == 0){ //Add after head if (n.getValue() > temp.getValue()){ n.setPrevious(temp); n.setNext(temp.getNext()); temp.setNext(n); //New Head } else { n.setNext(temp); temp.setPrevious(n); this.head = n; } } else { //Adding in the middle if (temp.getNext() != null){ addToListInOrder(n, temp); //Adding at the end } else { if (value > temp.getValue()){ //Adding at the end temp.setNext(n); n.setPrevious(temp); } else { //Add before the end addToListInOrder(n, temp); } } } } //Increase the size this.size++; } /** * addToListInOrder - A simple helper method used by the addInOrderMethod * This helper method handles reassociating the relationships * when adding between two SNodes in the list. */ private void addToListInOrder(SNode n, SNode temp){ temp.getPrevious().setNext(n); n.setNext(temp); n.setPrevious(temp.getPrevious()); temp.setPrevious(n); } /** * debugList - Prints the List to the salesforce Dev Console * Should be used when debugging the list */ public void debugList(){ SNode temp = this.head; Integer i = 0; System.debug('List' + i + ' : ' + temp.getValue() + ' ' + temp.getObject()); while (temp.getNext() != null){ temp = temp.getNext(); i++; System.debug('List' + i + ' : ' + temp.getValue() + ' ' + temp.getObject()); } System.debug('================================================================'); } public Integer getSize(){ return this.size; } /** * convertToList * This method converts a LinkedList to a stanard * salesforce list. Only SObject data is presevered, * value is dropped. */ public List<SObject> convertToList(){ List<SObject> l = new List<SObject>(); SNode temp = this.head; //Walk the linkedlist and add every item to a apex list while (temp.getNext() != null){ l.add(temp.getObject()); temp = temp.getNext(); } return l; } /** * convertToListDesc * This method converts a LinkedList to a standard Apex * list, and then loops through backwards, so the larger * objects are returned first. */ public List<SObject> convertToListDesc(){ List<SObject> l = new List<SObject>(); SNode temp = this.head; //Walk the list and add all objects to a list while (temp.getNext() != null){ l.add(temp.getObject()); temp = temp.getNext(); } List<SObject> ld = new List<Sobject>(); //Start at the end and walk backwards for (Integer i = l.size()-1; i >=0; i--){ ld.add(l.get(i)); } return l; } /** * bubbleSort - A simple method to sort the linkedList * Bubble sort has a runtime of n^2 where n is the number of elements. */ public void bubbleSort(){ //Tracker variable to check if the list has been sorted boolean done = false; while (!done) { //Temp node to walk the list SNode temp = head; done = true; //Loop the list for (Integer i = 0; i < getSize() -1; i++){ //Check the current node and the next node's value if (temp.getNext().getValue() < temp.getValue()) { //If next is less, than swap them swap(temp, temp.getNext()); done = false; } //Continue down the list temp = temp.getNext(); } } } /** * swap - Used by bubble sort to swap node values objects. */ private void swap(SNode a, SNode b){ //Temp variables to store a's values. Integer i = a.getValue(); SObject s = a.getObject(); //Switch the values a.setValue(b.getValue()); a.setObject(b.getObject()); b.setValue(i); b.setObject(s); } public boolean isEmpty(){ if (getSize() > 0){ return false; } else { return true; } } }
/** * SNode - Written by Jacob Schultz 13.4.16 * * A simple node class used by the Apex Linked List class. * This node will hold any SObject (User, Opp, Case, Etc.) * It will also hold a value/weight/index - whatever int you would like * Since the LinkedList is a doubly linkedlist there are also fields * for the next and previous node. * */ public class SNode { private SObject obj; private Integer value; private SNode previous; private SNode next; public SNode(){ this.obj = null; this.value = 0; this.previous = null; this.next = null; } public SNode(SObject obj, Integer value){ this.obj = obj; this.value = value; } public SObject getObject(){ return this.obj; } public Integer getValue(){ return this.value; } public void setObject(SObject obj){ this.obj = obj; } public void setValue(Integer i){ this.value = i; } public void setNext(SNode n){ this.next = n; } public void setPrevious(SNode p){ this.previous = p; } public SNode getPrevious(){ return this.previous; } public SNode getNext(){ return this.next; } }
- Jacob Schultz
- April 15, 2016
- Like
- 2
- Continue reading or reply