• Dustin Mayfield
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 2
    Replies
We have a visual force page that will upsert a list of records based on user input. Normally, users are only upserting 1 - 5 records, however, on ocassion there is a need to upsert 12+ records. In result, we are having another issue with a flow we have built that does a psuedo rollup summary to another object, and it is now hitting a recent update by Salesforce that limits record updates to only 12 in one call. We can't figure out how to optimize the flow to not hit the limits, so our best bet is to update how the upsert is done. I've partially adjusted our class to do the following:
 
try{
                if(tlToAdd.size() < 12) {
                	upsert tlToAdd;   
                    
                }
                else {
                   
                    
                    
                }
However i'm not sure how to complete the else statement. I'm not sure if there is a simple method to limit the upsert. Any thoughts?
 
I created a class that I'd like to schedule with apex jobs to run on certain days. The class is working as intended, but i'm struggling with the test class. I'm not sure how I'm supposed to cover the email portion of the class:
 
public with sharing class TimesheetReminder {
    public static void TimesheetReminder() {

        //Get list of active employees 
        List <sabersolutions__Employee__c> listOfRoles = [SELECT id, sabersolutions__Work_Email__c, sabersolutions__First_Name__c, Name FROM sabersolutions__Employee__c WHERE Status__c = 'Active'];
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();


        for (sabersolutions__Employee__c role : listOfRoles) {

                    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();

                    String[] toAddresses = new String[] {role.sabersolutions__Work_Email__c};
            //      String[] ccAddresses = new String[] {'hr@company.com'};
            //      email.setccAddresses(ccAddresses);                                        
                    email.setToAddresses(toAddresses);
                    email.SetReplyTo('hr@company.com');
                    email.setSenderDisplayName('Human Resources - Timekeeping Reminder');
                    email.setBccSender(false);
                    email.setUseSignature(false);
                    email.SetSubject('Timesheet Reminder || Reminder to Complete');                   
                    email.setHtmlBody('Hello '+role.sabersolutions__First_Name__c+' '+role.Name+',<br><br>This is a friendly reminder to please complete your timesheet before close of business today.');

                    mails.add(email);
        }

        Messaging.sendEmail(mails);
    } 
}
This is the test class I have so far, however it only covers 33% of the class...
 
@isTest
public class TimesheetReminderTest {

    @istest public static void Test1() { 
        sabersolutions__Employee__c emp = new sabersolutions__Employee__c();
        emp.sabersolutions__First_Name__c = 'TestFirstName';
        emp.Name = 'TestLastName';
        emp.sabersolutions__Work_Email__c = 'test@test.com';
        insert emp;



        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {emp.sabersolutions__Work_Email__c};

        email.setToAddresses(toAddresses);
        email.SetReplyTo('hr@company.com');
        email.setSenderDisplayName('Human Resources - Timekeeping Reminder');
        email.setBccSender(false);
        email.setUseSignature(false);  
        email.SetSubject('Timesheet Reminder || Reminder to Complete');
        email.setHtmlBody('Hello '+emp.sabersolutions__First_Name__c+' '+emp.Name+',<br><br>This is a friendly reminder to please complete your timesheet before close of business today.');

        TimesheetReminder.TimesheetReminder();
        Integer emailInvocations = Limits.getEmailInvocations();
        system.assertEquals(1, emailInvocations, 'An email should be sent');


        }

}

Any suggestions on how i can increase the code coverage? Thanks so much!
 
I am fairly new with VF pages but am really interested in creating a company calendar that will display when people have planned to take time off. We use a custom object in SF called "Time Off Requests" which essentially asks for Name, Start Date, End Date, and Hours Taken and then goes to a manager via flow for approval (they set the field "Status" to "Approved"). I'd love it if we could take advantage of this data and create a calendar that we can display using VF. To be honest i'm not certain to get started and I feel like this has been done in some fashion before. I don't want to reinvent the wheel so are there any examples I can pull from and customize myself to get me started? Anything would help and would be much appreciated!
Hello - We are trying to get the standard pricebook entry price from a product into another custom object "Installed Product". There is a field called "Product Price" on "Installed Product" object that we would like to equal the price of the standard pricebook entry price. I wish we could accomplish this through a formula, but i believe it needs to be an APEX trigger which we have light familiarity on. There is a lookup on Installed Product to the product itself, so I assume we'd use that as a reference to find the price. Any guidance or help on creating this trigger would be extremely appreciated!
I am fairly new to VF and apex development but I am learning quite a lot. One of the things we need is to create a VF page that allows us to input an Account name as a search and then output that account (or accounts if it returns more then one in the search) and then displays the record informatino along with contact details. I found another great post on the forums that had the 2nd part all figured out, but it didn't incorporate any search or input functionality. What would it take to add the ability to search for an account name using this below

Page:
 
<apex:page standardController="Account" recordSetVar="accounts" tabstyle="account" sidebar="false" extensions="DisplayContact" >
  <apex:pageBlock title="Account" >
    <apex:form >
      
      <apex:pageBlockTable value="{!accounts}" var="a" id="list">
      
        <apex:column headerValue="Account Name">
        <apex:commandLink rerender="contactDetails" value=" {!a.Name}" action="{!ContactLists}">
         
         <apex:param name="id" value="{!a.id}"/>
       </apex:commandLink> 
         </apex:column>
        <apex:column value="{!a.type}" />
        <apex:column value="{!a.billingstreet}"/>
        <apex:column value="{!a.billingCity}" />
        <apex:column value="{!a.billingCountry}" />
        <apex:column value="{!a.billingPostalCode}"/>
        <apex:column value="{!a.createdById}"/>
      </apex:pageBlockTable>
     
    </apex:form>
   
  </apex:pageBlock>
  <apex:pageBlock title="Contact">
   <apex:outputPanel id="contactDetails">
     <apex:pageBlockTable value="{!conList}" var="con" id="conlist" title="Contact">
     <apex:column value="{!con.Name}"/>
     <apex:Column value="{!con.Phone}" />
     <apex:Column value="{!con.Email}" />
     </apex:pageBlockTable>
        
  
    </apex:outputPanel>
  </apex:pageBlock>
  
</apex:page>
Controller:
 
public with sharing class DisplayContact {
    public List<Contact> conList {get;set;}
    public DisplayContact(ApexPages.StandardSetController controller) {

    }
    
    public PageReference ContactLists()
    {
    if(ApexPages.currentPage().getParameters().get('id') != null)
      conList = [Select id,Name,Phone,Email from contact where accountId =: ApexPages.currentPage().getParameters().get('id')];
     return null;
    }   

}


 
I use a controller that faciliates a type of "login" that queries a SF contact username and password fields and allows users to login to a dashboard where ideally they can navigate, by buttons, to various visualforce pages depending on their need. The main thing I'm stuck on is figuring out how to pass (ideally securely) their contact username to the various other controllers and VF pages. As an example, a user would login with username and password, it would take them to a dashboard where they can click on a button "PTO Request" and then it redirects to a new VF (with a new controller) and it will display at the top "Welcome Bob Smith". 
 
public without sharing class STGeneralLogin {
      
    public String STUsername {get;set;}
    public String STPassword {get;set;}
    public String result {get;set;}
    public String curPage{get;set;}
    public String contactID {get;set;}
    public List<Contact> c{get;set;}


   
    public PageReference doLogin(){
    
        c = [Select id,TKP_Password__c,Name from Contact where TKP_Username__c =: STUsername];
        if (c.size() > 0){
            if (STPassword.equals(c[0].TKP_Password__c)){
                contactID = c[0].id;
                result = 'True';
                
               
                PageReference pageRef = Page.STEmployeeApps;
                pageRef.setRedirect(false);
                
                return pageRef;
                
            }       
            else{
                result = 'Login failed, please try again.';
                return null;
            }
        }
        
        
        else{
            result = 'Login failed, please try again.';
            return null;
        }
    }
   

    public PageReference checkContact(){
        PageReference pageRef = Page.STLoginPage;
        PageReference pageRefPass = Page.STEmployeeApps;
            pageRef.setRedirect(true);
        try{
            if(c== null){
            
            return pageRef;
            }
        }
        
       catch(Exception e){
            // errorEmail (e);
        
            return pageRef;
        }
        return null;
 
	}
  
    public PageReference gotoPTOReq(){
        // PageReference pageRef = Page.PTO_Request || new PageReference('apex/PTO_Request');
       // newPage.getParameters().put(VAR_NAME, VALUE);
	   // newPage.setRedirect(true);
        
        return pageRef;
 
	}
}

Page 1 (VF apps Dashboard)
 
<apex:page showHeader="false" controller="STGeneralLogin" action="{!checkContact}"> 
<apex:pageBlock title="Employee Apps">	
	<apex:form >
		<apex:commandButton value="PTO Request" action="{!gotoPTOReq}"/>
	</apex:form>    
</apex:pageBlock>

</apex:page>

Page 2 (PTO Request)
<apex:page controller="PTORequest">
     
    <apex:form >
        <apex:inputField style="display:none" required="true" value="{!c.Name}"/>
        <apex:pageMessages />
        <apex:pageBlock title="Time Off Request">
            <apex:pageBlockSection >
            	<apex:inputField required="true" value="{!c.Type__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField required="true" value="{!c.Employee__c}"/>
            </apex:pageBlockSection>
             <apex:pageBlockSection >
                <apex:commandButton value="Submit Request" action="{!submitrequest}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
 
</apex:page>

As you can see, the PTO Request page uses a different controller, which is what I think we would want... Are there any suggestions on how we may accomplish this? 
Right now our company is challenged with a lack of user adoption due to a cluttered user interface and displaying of fields that don't have revelance to that users role. We have worked with teams to improve the layout of each object, but the adminitrative level of effort is quite high due to multiple custom objects and hundreds of custom fields. Are there any tools that exist on the appexchange that can help our IT administrators improve the layout and profiles of our users? Are there any other quick wins we can accomplish in terms of making the user expierence more friendly and efficient?

We are currently using Salesforce Classic and will eventually work to migrate to Lightning
Hello - We are trying to get the standard pricebook entry price from a product into another custom object "Installed Product". There is a field called "Product Price" on "Installed Product" object that we would like to equal the price of the standard pricebook entry price. I wish we could accomplish this through a formula, but i believe it needs to be an APEX trigger which we have light familiarity on. There is a lookup on Installed Product to the product itself, so I assume we'd use that as a reference to find the price. Any guidance or help on creating this trigger would be extremely appreciated!
I use a controller that faciliates a type of "login" that queries a SF contact username and password fields and allows users to login to a dashboard where ideally they can navigate, by buttons, to various visualforce pages depending on their need. The main thing I'm stuck on is figuring out how to pass (ideally securely) their contact username to the various other controllers and VF pages. As an example, a user would login with username and password, it would take them to a dashboard where they can click on a button "PTO Request" and then it redirects to a new VF (with a new controller) and it will display at the top "Welcome Bob Smith". 
 
public without sharing class STGeneralLogin {
      
    public String STUsername {get;set;}
    public String STPassword {get;set;}
    public String result {get;set;}
    public String curPage{get;set;}
    public String contactID {get;set;}
    public List<Contact> c{get;set;}


   
    public PageReference doLogin(){
    
        c = [Select id,TKP_Password__c,Name from Contact where TKP_Username__c =: STUsername];
        if (c.size() > 0){
            if (STPassword.equals(c[0].TKP_Password__c)){
                contactID = c[0].id;
                result = 'True';
                
               
                PageReference pageRef = Page.STEmployeeApps;
                pageRef.setRedirect(false);
                
                return pageRef;
                
            }       
            else{
                result = 'Login failed, please try again.';
                return null;
            }
        }
        
        
        else{
            result = 'Login failed, please try again.';
            return null;
        }
    }
   

    public PageReference checkContact(){
        PageReference pageRef = Page.STLoginPage;
        PageReference pageRefPass = Page.STEmployeeApps;
            pageRef.setRedirect(true);
        try{
            if(c== null){
            
            return pageRef;
            }
        }
        
       catch(Exception e){
            // errorEmail (e);
        
            return pageRef;
        }
        return null;
 
	}
  
    public PageReference gotoPTOReq(){
        // PageReference pageRef = Page.PTO_Request || new PageReference('apex/PTO_Request');
       // newPage.getParameters().put(VAR_NAME, VALUE);
	   // newPage.setRedirect(true);
        
        return pageRef;
 
	}
}

Page 1 (VF apps Dashboard)
 
<apex:page showHeader="false" controller="STGeneralLogin" action="{!checkContact}"> 
<apex:pageBlock title="Employee Apps">	
	<apex:form >
		<apex:commandButton value="PTO Request" action="{!gotoPTOReq}"/>
	</apex:form>    
</apex:pageBlock>

</apex:page>

Page 2 (PTO Request)
<apex:page controller="PTORequest">
     
    <apex:form >
        <apex:inputField style="display:none" required="true" value="{!c.Name}"/>
        <apex:pageMessages />
        <apex:pageBlock title="Time Off Request">
            <apex:pageBlockSection >
            	<apex:inputField required="true" value="{!c.Type__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:inputField required="true" value="{!c.Employee__c}"/>
            </apex:pageBlockSection>
             <apex:pageBlockSection >
                <apex:commandButton value="Submit Request" action="{!submitrequest}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
 
</apex:page>

As you can see, the PTO Request page uses a different controller, which is what I think we would want... Are there any suggestions on how we may accomplish this?