• Adriana Reyes 26
  • NEWBIE
  • 19 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 7
    Replies
Hello!

So I have a list of parent records called ServiceContract, and as I'm looping through each parent record, I query for the child records called ContractLineItem for that specific parent record, then I use those line items to do something else. My first instinct is to query for those child records inside of the for loop, and I know that is not the correct way to do it. I was hoping someone could show me how to fix my code the correct way. I appreciate the help.
 
//ServiceContract parent record list
        for (ServiceContract selectedContract : selectedContracts) {
            
            //Get child contract line records
            List<ContractLineItem> contractLines =[SELECT id, Product2Id, Quantity, Discount, UnitPrice, ServiceContractId, Description, Product_Reference_ID__c 
                                                   FROM ContractLineItem WHERE ServiceContractId = :selectedContract.Id];
            
            for (ContractLineItem contractLine : contractLines)
            {
                gii__ServiceOrderLine__c serviceLine = new gii__ServiceOrderLine__c ();
                serviceLine.gii__SalesOrder__c = selectedContract.Sales_Order__c;
                serviceLine.gii__OrderQuantity__c = contractLine.Quantity;
                serviceLine.gii__UnitPrice__c = contractLine.UnitPrice;

                serviceLineList.add(serviceLine);
            }
        }
        
        insert serviceLineList;
Hello!

So I'm trying to figure out how to tell if the date entered in a date field falls on a holiday in Apex. I've been using the isWithin() method in the BusinessHours object to tell if a date is not within business hours, but the requirement has recently changed to go even further. The reason behind this is because we charge different rates on holidays. For example, Saturday would normally be considered "after hours" rates but if Saturday is Christmas Day, then we need a way to mark that in a checkbox or something so we can bill a holiday rate.

Any help is appreciated. Thank you!
So we have a visualforce page that overrides the standard View page on a custom object called Service Calls. The VF has buttons that lead them to other VF pages, and it all seems to work as long as they are not working out of a Lightning Console app. When they're working out of the console, the regular View standard page is displayed. Does anyone know how I can get it to override even within a console app?

Thanks!
I'm trying to calculate quantity * unit cost to display a total for each line within the Visualforce page so that it changes as the user enters in new values. I also want that column to display a grand total in the footer, but when the page loads, the line totals are calculated, but the grand total doesn't. If I do get the grand total to work, it'll only work if I change the input fields. I'm not really sure how to set it up so that this will work. Any help is appreciated. Thanks!
 
<apex:page lightningStylesheets="true"
           docType="html-5.0"
           standardController="Purchase_Order_Line__c"
           extensions="createVendorInvoice"
           recordSetVar="POLines"
           action="{!retreiveLines}">
    <apex:form >
        <apex:pageBlock title="Create Vendor Invoice from PO Lines">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!Cancel}" value="Cancel"/>
                <apex:commandButton action="{!createVendorInvoice}" value="Submit"/>
            </apex:pageBlockButtons>

            
            <apex:variable var="total" value="{!0}"/>
            <apex:variable var="grandTotal" value="{!0}"/>
            <apex:pageBlockTable value="{!selectedLines}" var="line" >
                <apex:column value="{!line.Name}"/>
                <apex:column value="{!line.Product__c}"/>
                <apex:column value="{!line.Order_Quantity__c}"/>
                <apex:column value="{!line.Open_Quantity__c}"/>
                <apex:column value="{!line.Quantity_Received__c}"/>
                <apex:column headerValue="Invoice Quantity">
                    <apex:actionRegion >
                        <apex:inputField value="{!line.Set_Invoice_QTY__c}">
                            <apex:actionSupport event="onchange" reRender="total"/>
                        </apex:inputField>
                    </apex:actionRegion> 
                </apex:column>
                <apex:column headerValue="Unit Price">
                    <apex:actionRegion >
                        <apex:inputField value="{!line.Unit_Cost__c}">
                            <apex:actionSupport event="onchange" reRender="total"/>
                        </apex:inputField>
                    </apex:actionRegion>    
                </apex:column>
                <apex:column headerValue="Total" id="column">
                    <apex:outputText id="total" value="{0, number, 0.00}">
                        <apex:param value="{!line.Set_Invoice_QTY__c * line.Unit_Cost__c }"/>
                        <apex:variable id="x" var="grandTotal" value="{!grandTotal + total}"/>
                    </apex:outputText>
                    <apex:facet name="footer">
                        <apex:outputText id="grandTotal" value="{0, number, 0.00}">
                            <apex:param value="{!grandTotal}" />
                        </apex:outputText>
                    </apex:facet> 
                </apex:column>  
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form> 
</apex:page>

 
My users want the creation of cases to be an interactive visualflow. I've created this flow which includes lightning components. This means it has to run in lightning runtime. Since I can only use VF pages for the "New" button on cases I had to follow this article: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_flows_lightningruntime.htm to get it to run in lightning from within a VF page. It works, but it looks funny. The text boxes are tiny and it just looks off. Does anyone have any experience with this or any ideas on how I can fix the formatting? Thanks!

User-added image
So I have this visualforce page:
<apex:page id="Page" showHeader="false" controller="AcceptedCallPage" action="{!InitPage}" cache="false">
    <apex:form >
        Thank you! You have successfully accepted this call.
    </apex:form>
</apex:page>

And this controller:
public class AcceptedCallPage {
    public string ObjectId {get;set;}
    public string AcceptedResponse {get;set;}
    public AcceptedCallPage () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        AcceptedResponse = ApexPages.currentPage().getParameters().get('AcceptedResponse');
    }
    public PageReference InitPage() {
        List<Service_Call__c> ServiceCalls = [Select Id, Status__c From Service_Call__c Where Id=:ObjectId LIMIT 1];
        if(!ServiceCalls.isEmpty()) {
            ServiceCalls[0].Status__c = AcceptedResponse;
            Update ServiceCalls;
        }
     return null;   
    }
}

I'm trying to get 100% code coverage, but I don't really know what I'm doing. Here is what I have:
@isTest
public class AcceptedCTRTest {
    public static testMethod void testMyController() {
        Service_Call__c sc = new Service_Call__c();
        sc.Status__c = 'Entered';
        insert sc;
        
        Test.startTest();
        	PageReference pageRef = Page.CallAccepted;
        	pageRef.getParameters().put('ObjectId', String.valueOf(sc.Id));
        	pageRef.getParameters().put('AcceptedResponse','Accepted');
        	Test.setCurrentPage(pageRef);
        Test.stopTest();
    }
}

Any help is appreciated. Thanks!​
trigger AfterHoursTrigger on Service_Call__c (after insert) {
    //Get the default business hours
    BusinessHours bh = [Select Id From BusinessHours Where isDefault = true];
    
    Datetime CreatedTime = System.Today();
    
    //Find whether CreatedDate is whithin those business hours
    for (Service_Call__C Calls : Trigger.new){

    Boolean isWithin = BusinessHours.isWithin(bh.id, CreatedTime);
        if (isWithin = FALSE)
        Calls.After_Hours__c = True;
    }

}

So this is my very first attempt to write a trigger in Salesforce so be patient with me. Basically I want something that will check a checkbox called "After Hours" if the created date of the record doesn't fall within the business hours set up in Salesforce. It's not working, and I have no idea why. Any help is appreciated. Thanks
Hello!

So I have a list of parent records called ServiceContract, and as I'm looping through each parent record, I query for the child records called ContractLineItem for that specific parent record, then I use those line items to do something else. My first instinct is to query for those child records inside of the for loop, and I know that is not the correct way to do it. I was hoping someone could show me how to fix my code the correct way. I appreciate the help.
 
//ServiceContract parent record list
        for (ServiceContract selectedContract : selectedContracts) {
            
            //Get child contract line records
            List<ContractLineItem> contractLines =[SELECT id, Product2Id, Quantity, Discount, UnitPrice, ServiceContractId, Description, Product_Reference_ID__c 
                                                   FROM ContractLineItem WHERE ServiceContractId = :selectedContract.Id];
            
            for (ContractLineItem contractLine : contractLines)
            {
                gii__ServiceOrderLine__c serviceLine = new gii__ServiceOrderLine__c ();
                serviceLine.gii__SalesOrder__c = selectedContract.Sales_Order__c;
                serviceLine.gii__OrderQuantity__c = contractLine.Quantity;
                serviceLine.gii__UnitPrice__c = contractLine.UnitPrice;

                serviceLineList.add(serviceLine);
            }
        }
        
        insert serviceLineList;
So I have this visualforce page:
<apex:page id="Page" showHeader="false" controller="AcceptedCallPage" action="{!InitPage}" cache="false">
    <apex:form >
        Thank you! You have successfully accepted this call.
    </apex:form>
</apex:page>

And this controller:
public class AcceptedCallPage {
    public string ObjectId {get;set;}
    public string AcceptedResponse {get;set;}
    public AcceptedCallPage () {
        ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
        AcceptedResponse = ApexPages.currentPage().getParameters().get('AcceptedResponse');
    }
    public PageReference InitPage() {
        List<Service_Call__c> ServiceCalls = [Select Id, Status__c From Service_Call__c Where Id=:ObjectId LIMIT 1];
        if(!ServiceCalls.isEmpty()) {
            ServiceCalls[0].Status__c = AcceptedResponse;
            Update ServiceCalls;
        }
     return null;   
    }
}

I'm trying to get 100% code coverage, but I don't really know what I'm doing. Here is what I have:
@isTest
public class AcceptedCTRTest {
    public static testMethod void testMyController() {
        Service_Call__c sc = new Service_Call__c();
        sc.Status__c = 'Entered';
        insert sc;
        
        Test.startTest();
        	PageReference pageRef = Page.CallAccepted;
        	pageRef.getParameters().put('ObjectId', String.valueOf(sc.Id));
        	pageRef.getParameters().put('AcceptedResponse','Accepted');
        	Test.setCurrentPage(pageRef);
        Test.stopTest();
    }
}

Any help is appreciated. Thanks!​
trigger AfterHoursTrigger on Service_Call__c (after insert) {
    //Get the default business hours
    BusinessHours bh = [Select Id From BusinessHours Where isDefault = true];
    
    Datetime CreatedTime = System.Today();
    
    //Find whether CreatedDate is whithin those business hours
    for (Service_Call__C Calls : Trigger.new){

    Boolean isWithin = BusinessHours.isWithin(bh.id, CreatedTime);
        if (isWithin = FALSE)
        Calls.After_Hours__c = True;
    }

}

So this is my very first attempt to write a trigger in Salesforce so be patient with me. Basically I want something that will check a checkbox called "After Hours" if the created date of the record doesn't fall within the business hours set up in Salesforce. It's not working, and I have no idea why. Any help is appreciated. Thanks