• Adriana Reyes
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies
I have a custom currency field called "Standard Price" on the products object. I need this because a formula field on a related object looks at this field.

I'm trying to see if it's possible to build a trigger that fires everytime the "Standard Price" in the standard price book is updated and updates that custom field to match.

Thanks!
I have an invoice payment child object related to the parent invoice object. I created a trigger on the child, that updates the payment date on the invoice when the full payment is posted. There is a status formula field on the invoice that updates to "PAID" when the balance on the invoice is equal to zero. It doesn't get updated to "PAID" until after the invoice payment record is saved so I think that is causing my trigger to not work and update the payment field. Does anyone have any suggestions on how I can go about this? Thanks!
 
trigger Update_Payment_Date on gii__ARInvoicePayment__c (after insert, after update) {
    List<gii__OrderInvoice__c>lstInvoiceToUpdate = new List<gii__OrderInvoice__c>();
    Map<Id,gii__OrderInvoice__c>invoiceMP;
    
    for(gii__ARInvoicePayment__c pmt:trigger.new)
    {
        if (pmt.gii__PaymentDate__c != null && pmt.Invoice_Status__c == 'PAID')
        {
            lstInvoiceToUpdate.add(new gii__OrderInvoice__c(Id = pmt.gii__Invoice__c, Paid_Date__c = pmt.gii__PaymentDate__c, gii__PaymentDate__c = pmt.gii__PaymentDate__c));
        }
    }
    update lstInvoiceToUpdate;
}

 
I have three for loops in my controller and when I run the test, I get code coverage everywhere except inside of the three for loops. Can someone point me in the right direction?
 
public with sharing class applyPayments_Controller {
    public List<InvoiceWrapper> searched_invoices {get;set;}
    public List<gii__OrderInvoice__c> selectedInvoices {get;set;}
    public string accountName {get;set;}
    public boolean viewTable;
    public date paymentDate {get;set;}
    public string paymentMethod {get;set;}
    public string reference {get;set;}
    public decimal amount {get;set;}
    public string comments {get;set;}
    
    public Boolean getViewTable()
    {
        return this.viewTable;
    }
    
    public applyPayments_Controller()
    {
        viewTable=false;
        searched_invoices = new List<InvoiceWrapper>();
    }
    
    public void searchInvoices()
    {   
        string likeAccountName = '%' + accountName + '%';
        searched_invoices.clear();
        for(gii__OrderInvoice__c i: [select Id, Name, Total_Invoice__c, gii__BalanceAmount__c, Past_Due__c, Account_Name__c, gii__Status__c from gii__OrderInvoice__c 
                                     where (Account_Name__c LIKE :likeAccountName AND gii__Status__c != 'Cancelled' AND Past_Due__c != 'PAID')
                                     order by Account_name__c, Name])
        {
            searched_invoices.add(new InvoiceWrapper(i));
        }
        
        viewTable = true;
    }
    
    public PageReference Next()
    {
        selectedInvoices = new List<gii__OrderInvoice__c>();
        selectedInvoices.clear();
        for (InvoiceWrapper wrapInvoiceObj : searched_invoices)
        {
            if(wrapInvoiceObj.selected == true)
            {
                selectedInvoices.add(wrapInvoiceObj.inv);
            }
        }
        
        paymentDate = System.Today();
        PageReference applyPaymentsVF_2 = new PageReference('/apex/applyPaymentsVF_2');
        return applyPaymentsVF_2;
    }
    
    public void applyPayment()
    {
        for(gii__OrderInvoice__c inv : selectedInvoices)
        {
            gii__ARInvoicePayment__c payment = new gii__ARInvoicePayment__c();
            payment.gii__Invoice__c = inv.id;
            payment.gii__Reference__c = reference;
            payment.gii__Comments__c = comments;
            payment.gii__PaymentMethod__c = paymentMethod;
            payment.gii__PaymentDate__c = paymentDate;
            payment.gii__PaidAmount__c = inv.gii__BalanceAmount__c;
            insert payment;
        }    
    }
    
    //This is wrapper/container class
    public class InvoiceWrapper
    {
        public String accName {get;set;}
        public String invName {get;set;}
        public decimal total {get;set;}
        public decimal balance {get;set;}
        public String status {get;set;}
        public gii__OrderInvoice__c inv {get;set;}
        public Boolean selected {get;set;}
        public InvoiceWrapper(gii__OrderInvoice__c i)
        {
            inv = i;
            selected = false;
            accName = i.Account_Name__c;
            invName = i.Name;
            total = i.Total_Invoice__c;
            balance = i.gii__BalanceAmount__c;
            status = i.Past_Due__c;
        }
    } 
}
 
@isTest
public class applyPayments_ControllerTest {
    public static testMethod void testMyController()
    {  
        gii__SalesOrder__c so = new gii__SalesOrder__c();
        Id RecordTypeIdSO = Schema.SObjectType.gii__SalesOrder__c.getRecordTypeInfosByName().get('Service Call Order').getRecordTypeId();
        so.RecordTypeId = RecordTypeIdSO;
        so.gii__OrderType__c = 'Standard';
        insert so;
        
        gii__OrderInvoice__c inv = new gii__OrderInvoice__c();
        inv.gii__SalesOrder__c = so.Id;
        insert inv;
        
        applyPayments_Controller controller = new applyPayments_Controller();
        applyPayments_Controller.InvoiceWrapper wrp = new applyPayments_Controller.InvoiceWrapper(inv);
        controller.searchInvoices();
        controller.getViewTable();
        controller.Next();
        controller.applyPayment();
    }
}

 
I have a VF page that searches for contacts using the first name and mailing state of the contact. It then returns a list of contacts on that same page that match the search. I would like to be able to select a checkbox next to the returned records and be able to update the mailing state for all of the selected records. Here is what I have:
 
<apex:page controller="searchContacts_Controller">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Search" action="{!searchContacts}" reRender="contact-table" />
            </apex:pageBlockButtons>

            <apex:pageBlockSection id="contact-table" columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="FirstName" />
                    <apex:inputText value="{!Firstname}" />
                </apex:pageBlockSectionItem>

                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Mailing State" />
                    <apex:inputText value="{!mailingState}" />
                </apex:pageBlockSectionItem>

                <apex:pageBlockTable value="{!contacts}" var="c">
                    
                    <apex:column >
                        <apex:facet name="header">Name</apex:facet>
                        {!c.FirstName}
                    </apex:column>

                    <apex:column >
                        <apex:facet name="header">Mailing State</apex:facet>
                        {!c.MailingState}
                    </apex:column>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class searchContacts_Controller {
    public List<Contact> contacts { get; set; }
    public String Firstname { get; set; }
    public String mailingState { get; set; }

    public applyPayments_Controller()
    {
        contacts = new List<Contact>();
    }

    public PageReference searchContacts()
    {
        contacts = [select Id
                          ,FirstName
                          ,MailingState 
                     from Contact 
                    where FirstName = :Firstname
                    and MailingState = :mailingState];
        return null;
    }
}

Any help is appreciated. Thanks!
Is there a way so that when certain opportunities are created, the opportunity team and splits are automatically added?
I have a custom currency field called "Standard Price" on the products object. I need this because a formula field on a related object looks at this field.

I'm trying to see if it's possible to build a trigger that fires everytime the "Standard Price" in the standard price book is updated and updates that custom field to match.

Thanks!
I have three for loops in my controller and when I run the test, I get code coverage everywhere except inside of the three for loops. Can someone point me in the right direction?
 
public with sharing class applyPayments_Controller {
    public List<InvoiceWrapper> searched_invoices {get;set;}
    public List<gii__OrderInvoice__c> selectedInvoices {get;set;}
    public string accountName {get;set;}
    public boolean viewTable;
    public date paymentDate {get;set;}
    public string paymentMethod {get;set;}
    public string reference {get;set;}
    public decimal amount {get;set;}
    public string comments {get;set;}
    
    public Boolean getViewTable()
    {
        return this.viewTable;
    }
    
    public applyPayments_Controller()
    {
        viewTable=false;
        searched_invoices = new List<InvoiceWrapper>();
    }
    
    public void searchInvoices()
    {   
        string likeAccountName = '%' + accountName + '%';
        searched_invoices.clear();
        for(gii__OrderInvoice__c i: [select Id, Name, Total_Invoice__c, gii__BalanceAmount__c, Past_Due__c, Account_Name__c, gii__Status__c from gii__OrderInvoice__c 
                                     where (Account_Name__c LIKE :likeAccountName AND gii__Status__c != 'Cancelled' AND Past_Due__c != 'PAID')
                                     order by Account_name__c, Name])
        {
            searched_invoices.add(new InvoiceWrapper(i));
        }
        
        viewTable = true;
    }
    
    public PageReference Next()
    {
        selectedInvoices = new List<gii__OrderInvoice__c>();
        selectedInvoices.clear();
        for (InvoiceWrapper wrapInvoiceObj : searched_invoices)
        {
            if(wrapInvoiceObj.selected == true)
            {
                selectedInvoices.add(wrapInvoiceObj.inv);
            }
        }
        
        paymentDate = System.Today();
        PageReference applyPaymentsVF_2 = new PageReference('/apex/applyPaymentsVF_2');
        return applyPaymentsVF_2;
    }
    
    public void applyPayment()
    {
        for(gii__OrderInvoice__c inv : selectedInvoices)
        {
            gii__ARInvoicePayment__c payment = new gii__ARInvoicePayment__c();
            payment.gii__Invoice__c = inv.id;
            payment.gii__Reference__c = reference;
            payment.gii__Comments__c = comments;
            payment.gii__PaymentMethod__c = paymentMethod;
            payment.gii__PaymentDate__c = paymentDate;
            payment.gii__PaidAmount__c = inv.gii__BalanceAmount__c;
            insert payment;
        }    
    }
    
    //This is wrapper/container class
    public class InvoiceWrapper
    {
        public String accName {get;set;}
        public String invName {get;set;}
        public decimal total {get;set;}
        public decimal balance {get;set;}
        public String status {get;set;}
        public gii__OrderInvoice__c inv {get;set;}
        public Boolean selected {get;set;}
        public InvoiceWrapper(gii__OrderInvoice__c i)
        {
            inv = i;
            selected = false;
            accName = i.Account_Name__c;
            invName = i.Name;
            total = i.Total_Invoice__c;
            balance = i.gii__BalanceAmount__c;
            status = i.Past_Due__c;
        }
    } 
}
 
@isTest
public class applyPayments_ControllerTest {
    public static testMethod void testMyController()
    {  
        gii__SalesOrder__c so = new gii__SalesOrder__c();
        Id RecordTypeIdSO = Schema.SObjectType.gii__SalesOrder__c.getRecordTypeInfosByName().get('Service Call Order').getRecordTypeId();
        so.RecordTypeId = RecordTypeIdSO;
        so.gii__OrderType__c = 'Standard';
        insert so;
        
        gii__OrderInvoice__c inv = new gii__OrderInvoice__c();
        inv.gii__SalesOrder__c = so.Id;
        insert inv;
        
        applyPayments_Controller controller = new applyPayments_Controller();
        applyPayments_Controller.InvoiceWrapper wrp = new applyPayments_Controller.InvoiceWrapper(inv);
        controller.searchInvoices();
        controller.getViewTable();
        controller.Next();
        controller.applyPayment();
    }
}