• SidVicious
  • NEWBIE
  • 30 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 6
    Replies
Hi Developers,

I'm using a simple helper parser class to help deserialize my json string. I wanted to convert UsedDate from Long type to DateTime type, but can't figure out how to do it within this class.

Please help, thank you.
 
public class Code {

    public String Code;
	public String Status;
	public Long UsedDate; // how to convert to DateTime

	public static List<Code> parse(String json) {
		return (List<Code>) System.JSON.deserialize(json, List<Code>.class);
	}
}
Hi guys,

In the past, I've used the style "position: running(header)" normally, and did not cause any issues. It rendered the PDF perfectly. But now, I am encountering "PDF generation failed. Check the page markup is valid" whenever I include the line in my markup. I was able to identify the issue by narrowing everything down.

Did something changed? I checked the Known Issues and there isn't any new reports of this happening. The odd thing is, my position: running(footer) works perfectly.

Please see my code below for wholeness:
<apex:page standardController="Account" renderAs="pdf" extensions="AccountVfUtil" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
<html>
    <head>  
        <style type="text/css" media="print">
            @page {
                size: A4;
                margin-top: 3in;
                margin-right: 0.25in;
                margin-bottom: 0.75in;
                margin-left: 0;
                @top-center {
                    content: element(header);
                }
                @bottom-center {
                    content: element(footer);
                }
            }
            .page-break {
                margin-left: 0.75in;
                font-size: 11px;
                font-family: 'Arial Unicode MS', serif, sans-serif;
                display:block;
                page-break-after:auto;
            }
            div.content {
                margin-left: 0.75in;
                font-size: 11px;
                font-family: 'Arial Unicode MS', serif, sans-serif;
                display:block;
                page-break-after:always;
            }
            div.header {
                margin-left: 0.75in;
                margin-top: 0.5in;
                padding: 10px;
                position: running(header);
                font-size : 11px;
                margin-bottom: 0;
            }
            div.footer {
                width: 100%;
                display: block;
                padding-top: 5px;
                position: running(footer);
                font-size: 9px;
                color:  #646060;
                padding-bottom: 50px;
                padding-right: 50px;
                padding-left: 50px;
            }
            body{
                font-family: 'Arial Unicode MS', serif, sans-serif;
                position: relative;
            }
            .center{
                text-align:center;
            }
            .mainText{
                color:  #504d4d; 
            }
            .underline{
                border-bottom: 1px solid #504d4d;
                display: inline-block;
                line-height: 1.15;
            }
        </style>
    </head>
    <body>
        <div class="header">
            <table width="100%">
                <tbody class="mainText">
                    <tr width="100%">
                        <td width="50%" align="left">
                            <apex:image id="logo" width="170"
                            height="50"
                            url="{!URLFOR($Resource.COMPANY_LOGO)}"
                            />
                        </td>
                        <td width="50%" align="right">
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="footer">
            // footer works perfectly
        </div>
        <div class="content">
           // content works perfectly
        </div>
    </body>
</html>
</apex:page>

 
Hi everyone, my test class is finally coming around but in the end am on another jiffy. I was hoping if anyone have an insight as to why the code block below aren't being covered.

This is actually a continuation of my Previous Question (https://developer.salesforce.com/forums/?id=9062I000000IOUsQAO).

Apex class:
public override void afterDelete() {

        for(InvoiceLine__c invLine : (List<InvoiceLine__c>) Trigger.old){

            if(invLine.InvoiceId__c != null){

                invLineIdSet.add(invLine.InvoiceId__c);
            }
        }

        List<AggregateResult> invoiceLineList = [SELECT COUNT(Id) counter, InvoiceId__c 
                                                 FROM InvoiceLine__c 
                                                 WHERE InvoiceId__c =: invLineIdSet
                                                 GROUP BY InvoiceId__c];

        List<Invoice__c> invoiceList = [SELECT Id, OpportunityId__c FROM Invoice__c
                                        WHERE Id IN: invLineIdSet];

        Map<Id, Boolean> invLineChecker = new Map<Id, Boolean>();

        Boolean noLineRecords;

        for(Invoice__c invL : invoiceList){

            noLineRecords = true;

            invLineChecker.put(invL.Id, noLineRecords);

            oppIdSet.add(invL.OpportunityId__c);
        }

        for(AggregateResult invoiceLine : invoiceLineList){

            Integer counter = (Integer) invoiceLine.get('counter');

            Id parentInvoiceId = (Id) invoiceLine.get('InvoiceId__c');
            
            if(counter > 0){

                noLineRecords = false;

                invLineChecker.put(parentInvoiceId, noLineRecords);
            }else{

                noLineRecords = true;

                invLineChecker.put(parentInvoiceId, noLineRecords);
            }
        }


        List<Opportunity__c> oppList = [SELECT Id, CurrencyISOCode 
                                        FROM Opportunity__c 
                                        WHERE Id 
                                        IN: oppIdSet];

        if(!oppList.isEmpty()){

            for(Opportunity__c opp : oppList){
                
                if(opp.CurrencyISOCode != orgCurr){

                    oppList1.add(opp.Id);
                }else{

                    oppList2.add(opp.Id);
                }
            }
        }


        invoiceCheckerList = [SELECT Id, OpportunityId__c FROM Invoice__c WHERE OpportunityId__c IN: oppList1];

        opptyMapp = new Map<Id, Integer>();

        invoiceRecWithoutLines = 0;

        for(Invoice__c invoiceCheck : invoiceCheckerList){

            if(invLineChecker.get(invoiceCheck.Id) == true){

                invoiceRecWithoutLines += 1;

                opptyMapp.put(invoiceCheck.OpportunityId__c, invoiceRecWithoutLines);
            }
        }


        for(Id key : opptyMapp.keySet()) {
            
            Integer countr = opptyMapp.get(key);

            if(countr > 0){

                oppListToUpdate.add(new Opportunity__c( Id=key,
                                                        InvoiceTotal__c=0,
                                                        InvoiceGrossProfit__c=0,
                                                        InvoiceDiscountTotal__c=0));
            }else{
                oppList3.add(key);
            }
        }

        if(!oppList3.isEmpty()){
            System.debug('SUCCESS!');
        }
}

I've highlighted the parts above which am not being covered. I'm having difficulty getting them covered in my Test class. The list  oppList3 aren't populated.

Here are the Test class I have so far:
@isTest
    private static void deleteInvoiceLinesWithLineRecords(){

        initializeData();

        insert invoiceLineList;

        System.assertEquals(3, invoiceLineList.size());
		
		List<InvoiceLine__c> delInvList = [SELECT Id FROM InvoiceLine__c LIMIT 1];
		
		System.assertEquals(1, delInvList.size());

        Test.startTest();

        	try
			{
				delete delInvList;
			}Catch(Exception e)
            {
                String errormessage = e.getMessage();
                system.debug(errormessage);
            }

        Test.stopTest();

        delInvList = [SELECT Id FROM InvoiceLine__c];

        System.assertEquals(2, delInvList.size());
    }

    @isTest
    private static void initializeData(){
        
        opportunityRecord = new Opportunity__c();
        opportunityRecord.Account__c = '0012x000002kyl7AAA'; // required field
        opportunityRecord.CurrencyIsoCode = 'USD';
        opportunityRecord.Organisation__c = 'Default';
        opportunityRecord.InvoiceTotal__c = 0;
        insert opportunityRecord;
        invoiceRecord = new Invoice__c();
        invoiceRecord.OpportunityId__c = opportunityRecord.Id; // required field
        invoiceRecord.Account__c = '0012x000002kyl7AAA';
        invoiceRecord.TaxType__c = 'No Tax';
        invoiceRecord.TaxRate__c = 0;
        insert invoiceRecord;
        InvoiceLine__c invoiceLineRecord1 = new InvoiceLine__c();
        invoiceLineRecord1.InvoiceId__c = invoiceRecord.Id; // required field
        invoiceLineRecord1.DiscountType__c = 'Percent';
        invoiceLineRecord1.DiscountPercent__c = 5;
        invoiceLineRecord1.ProductType_Hidden__c = 'Discount';
        invoiceLineRecord1.Description__c = 'TEST';
        invoiceLineRecord1.Product__c = 'a042x00000BXXaZAAX';
        invoiceLineRecord1.Quantity__c = 1;
        invoiceLineRecord1.SalesPrice__c = 500;
        InvoiceLine__c invoiceLineRecord2 = new InvoiceLine__c();
        invoiceLineRecord2.InvoiceId__c = invoiceRecord.Id; // required field
        invoiceLineRecord2.DiscountType__c = 'Amount';
        invoiceLineRecord2.DiscountAmount__c = null;
        invoiceLineRecord2.Description__c = 'TEST';
        invoiceLineRecord2.Product__c = 'a042x00000BXXaZAAX';
        invoiceLineRecord2.Quantity__c = 1;
        invoiceLineRecord2.SalesPrice__c = 100;
        InvoiceLine__c invoiceLineRecord3 = new InvoiceLine__c();
        invoiceLineRecord3.InvoiceId__c = invoiceRecord.Id; // required field
        invoiceLineRecord3.DiscountPercent__c = null;
        invoiceLineRecord3.DiscountAmount__c = 0;
        invoiceLineRecord3.Description__c = 'TEST';
        invoiceLineRecord3.Product__c = 'a042x00000BXXaZAAX';   
        invoiceLineRecord3.Quantity__c = 1;
        invoiceLineRecord3.SalesPrice__c = 200;
        invoiceLineList = new List<InvoiceLine__c>();
        
        invoiceLineList.add(invoiceLineRecord1);
        invoiceLineList.add(invoiceLineRecord2);
        invoiceLineList.add(invoiceLineRecord3); 
    }
}

Again, any insights to this will be very much appreciated.

Please let me know if you need additional details.

Thank you!

- Sid
 
Hi guys, I've stumbled another obstacle - this time providing code coverage for AggregateResult. The general idea is to "count" the number of Invoice Line records under Invoice then put them inside a Map. I've only included a snippet of my code which I believe are relevant.

Apex class:
public override void afterDelete() {

        for(InvoiceLine__c invLine : (List<InvoiceLine__c>) Trigger.old){

            if(invLine.InvoiceId__c != null){

                invLineIdSet.add(invLine.InvoiceId__c);
            }
        }

        List<AggregateResult> invoiceLineList = [SELECT COUNT(Id) counter, InvoiceId__c 
                                                 FROM InvoiceLine__c 
                                                 WHERE InvoiceId__c =: invLineIdSet
                                                 GROUP BY InvoiceId__c];

        List<Invoice__c> invoiceList = [SELECT Id, OpportunityId__c FROM Invoice__c
                                        WHERE Id IN: invLineIdSet];

        Map<Id, Boolean> invLineChecker = new Map<Id, Boolean>();

        Boolean noLineRecords;

        for(Invoice__c invL : invoiceList){

            noLineRecords = true;

            invLineChecker.put(invL.Id, noLineRecords);

            oppIdSet.add(invL.OpportunityId__c);
        }

        for(AggregateResult invoiceLine : invoiceLineList){

            Integer counter = (Integer) invoiceLine.get('counter');

            Id parentInvoiceId = (Id) invoiceLine.get('InvoiceId__c');
            
            if(counter > 0){

                noLineRecords = false;

                invLineChecker.put(parentInvoiceId, noLineRecords);
            }else{

                noLineRecords = true;

                invLineChecker.put(parentInvoiceId, noLineRecords);
            }
        }

        System.debug('NO RECORDS? :' + invLineChecker);
}

As provided in the snippet above, I've highlighted the block of code where I'm unable to get code coverage. If somehow I'll be able to resolve this, I may figure out the rest.

Finally, below is my test class.

Test Class:
private static Opportunity__c opportunityRecord = new Opportunity__c();
private static List<InvoiceLine__c> invoiceLineList = new List<InvoiceLine__c>();

@isTest
    private static void deleteInvoiceLinesNoRecords(){

        initializeData();

        insert invoiceLineList;

        System.assertNotEquals(0, invoiceLineList.size());

        Test.startTest();

        	try
			{
                delete invoiceLineList;
			}Catch(Exception e)
            {
                String errormessage = e.getMessage();
                system.debug(errormessage);
            }

        Test.stopTest();
    }

@isTest
    private static void initializeData(){
        
        opportunityRecord = new Opportunity__c();
        opportunityRecord.Account__c = '0012x000002kyl7AAA'; // required field
        insert opportunityRecord;

        invoiceRecord = new Invoice__c();
        invoiceRecord.OpportunityId__c = opportunityRecord.Id; // required field
        insert invoiceRecord;

        InvoiceLine__c invoiceLineRecord1 = new InvoiceLine__c();
        invoiceLineRecord1.InvoiceId__c = invoiceRecord.Id; // required field

        InvoiceLine__c invoiceLineRecord2 = new InvoiceLine__c();
        invoiceLineRecord2.InvoiceId__c = invoiceRecord.Id; // required field

        InvoiceLine__c invoiceLineRecord3 = new InvoiceLine__c();
        invoiceLineRecord3.InvoiceId__c = invoiceRecord.Id; // required field

        invoiceLineList = new List<InvoiceLine__c>();
        
        invoiceLineList.add(invoiceLineRecord1);
        invoiceLineList.add(invoiceLineRecord2);
        invoiceLineList.add(invoiceLineRecord3);
    }

I would appreciate it greatly if anyone can address this issue with me.

What could I be missing here?

Thank you!

- Sid
Hi, everyone. I've hit yet another issue with code coverage for Test classes. This time it's about the Undelete operation.

Trigger
trigger InvoiceLineTrigger on InvoiceLine__c (before insert, before update, before delete, after undelete) {
    new InvoiceLineTriggerHandler().run();
}

Test class
@isTest
    private static void undeleteInvoiceLines(){

        initializeData(); // populates all needed records

        System.assertNotEquals(0, invoiceLineList.size());

        insert invoiceLineList;
        
        delete invoiceLineList;

        Test.startTest();

        	try
			{
                undelete invoiceLineList;
			}Catch(Exception e)
            {
                String errormessage = e.getMessage();
                system.debug(errormessage);
            }

        Test.stopTest();
    }

Apex class
public override void afterUndelete() {

        for(InvoiceLine__c invLine : (List<InvoiceLine__c>) Trigger.old){
            if(invLine.InvoiceId__c != null){
                invLineIdSet.add(invLine.InvoiceId__c);
            }
        }
    }

I'm not able to get code coverage for below line in my Apex class (shown on the code snippet above):
if(invLine.InvoiceId__c != null){
            invLineIdSet.add(invLine.InvoiceId__c);
        }

My assertion above passed, so I know I have the list of Invoice Line records - yet I'm not able to get code coverage for this Undelete operation. 

I'd appreciate any ideas/suggestions on how to resolve this.

Thanks!

- Sid
 
Hi experts, I'm trying to create a Test class for my trigger handler however can't seem to progress. My trigger is a simple AFTER UPDATE that fires whenever the CurrencyIsoCode is changed for the Opportunity record.

A code snippet from my trigger handler follows below:
public class OpportunityTriggerHandler extends TriggerHandler

private void updateCurrencyIsoCode(){

        for(Opportunity__c  oppty : (List<Opportunity__c>) Trigger.new){
            Opportunity__c oldOppty = (Opportunity__c)Trigger.oldMap.get(oppty.Id);

            if (oppty.CurrencyIsoCode != oldOppty.CurrencyIsoCode){

                opptyList.add(oppty);
            }  
        }
    }

I keep failing coverage for this line, as shown above.
opptyList.add(oppty);

Finally, here is my test class:
@isTest
    private static void updateInvoiceFields()
    {
        Opportunity__c opportunityRecord = new Opportunity__c();
        opportunityRecord.Account__c = '0012x000002kyl7AAA';
        opportunityRecord.CurrencyIsoCode = 'USD';
        opportunityRecord.Organisation__c = 'Default';
        insert opportunityRecord;

        List<Opportuntiy__c> opportunityRecordList = new List<Opportunity__c>();
        opportunityRecordList.add(opportunityRecord);

        Test.startTest();
            System.assertNotEquals(0, opportunityRecordList.size());
            for(Opportunity__c opportunityRecord : opportunityRecordList){
                System.assertNotEquals(opportunityRecord.CurrencyIsoCode, 'HKD');
                opportunityRecord.CurrencyIsoCode = 'HKD';
                System.assertEquals(opportunityRecord.CurrencyIsoCode, 'HKD');
            }
            try
            {
                update opportunityRecordList;
            }Catch(Exception e)
            {
                String errormessage = e.getMessage();
                system.debug(errormessage);
            }
        Test.stopTest();
    }

So, I changed the field as shown above however am not able to achieve coverage. By the way, all my assertions above passed.

What am I missing or doing wrong?

Thanks!

- Sid
Hi guys,

In the past, I've used the style "position: running(header)" normally, and did not cause any issues. It rendered the PDF perfectly. But now, I am encountering "PDF generation failed. Check the page markup is valid" whenever I include the line in my markup. I was able to identify the issue by narrowing everything down.

Did something changed? I checked the Known Issues and there isn't any new reports of this happening. The odd thing is, my position: running(footer) works perfectly.

Please see my code below for wholeness:
<apex:page standardController="Account" renderAs="pdf" extensions="AccountVfUtil" showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false">
<html>
    <head>  
        <style type="text/css" media="print">
            @page {
                size: A4;
                margin-top: 3in;
                margin-right: 0.25in;
                margin-bottom: 0.75in;
                margin-left: 0;
                @top-center {
                    content: element(header);
                }
                @bottom-center {
                    content: element(footer);
                }
            }
            .page-break {
                margin-left: 0.75in;
                font-size: 11px;
                font-family: 'Arial Unicode MS', serif, sans-serif;
                display:block;
                page-break-after:auto;
            }
            div.content {
                margin-left: 0.75in;
                font-size: 11px;
                font-family: 'Arial Unicode MS', serif, sans-serif;
                display:block;
                page-break-after:always;
            }
            div.header {
                margin-left: 0.75in;
                margin-top: 0.5in;
                padding: 10px;
                position: running(header);
                font-size : 11px;
                margin-bottom: 0;
            }
            div.footer {
                width: 100%;
                display: block;
                padding-top: 5px;
                position: running(footer);
                font-size: 9px;
                color:  #646060;
                padding-bottom: 50px;
                padding-right: 50px;
                padding-left: 50px;
            }
            body{
                font-family: 'Arial Unicode MS', serif, sans-serif;
                position: relative;
            }
            .center{
                text-align:center;
            }
            .mainText{
                color:  #504d4d; 
            }
            .underline{
                border-bottom: 1px solid #504d4d;
                display: inline-block;
                line-height: 1.15;
            }
        </style>
    </head>
    <body>
        <div class="header">
            <table width="100%">
                <tbody class="mainText">
                    <tr width="100%">
                        <td width="50%" align="left">
                            <apex:image id="logo" width="170"
                            height="50"
                            url="{!URLFOR($Resource.COMPANY_LOGO)}"
                            />
                        </td>
                        <td width="50%" align="right">
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="footer">
            // footer works perfectly
        </div>
        <div class="content">
           // content works perfectly
        </div>
    </body>
</html>
</apex:page>

 
Hi everyone, my test class is finally coming around but in the end am on another jiffy. I was hoping if anyone have an insight as to why the code block below aren't being covered.

This is actually a continuation of my Previous Question (https://developer.salesforce.com/forums/?id=9062I000000IOUsQAO).

Apex class:
public override void afterDelete() {

        for(InvoiceLine__c invLine : (List<InvoiceLine__c>) Trigger.old){

            if(invLine.InvoiceId__c != null){

                invLineIdSet.add(invLine.InvoiceId__c);
            }
        }

        List<AggregateResult> invoiceLineList = [SELECT COUNT(Id) counter, InvoiceId__c 
                                                 FROM InvoiceLine__c 
                                                 WHERE InvoiceId__c =: invLineIdSet
                                                 GROUP BY InvoiceId__c];

        List<Invoice__c> invoiceList = [SELECT Id, OpportunityId__c FROM Invoice__c
                                        WHERE Id IN: invLineIdSet];

        Map<Id, Boolean> invLineChecker = new Map<Id, Boolean>();

        Boolean noLineRecords;

        for(Invoice__c invL : invoiceList){

            noLineRecords = true;

            invLineChecker.put(invL.Id, noLineRecords);

            oppIdSet.add(invL.OpportunityId__c);
        }

        for(AggregateResult invoiceLine : invoiceLineList){

            Integer counter = (Integer) invoiceLine.get('counter');

            Id parentInvoiceId = (Id) invoiceLine.get('InvoiceId__c');
            
            if(counter > 0){

                noLineRecords = false;

                invLineChecker.put(parentInvoiceId, noLineRecords);
            }else{

                noLineRecords = true;

                invLineChecker.put(parentInvoiceId, noLineRecords);
            }
        }


        List<Opportunity__c> oppList = [SELECT Id, CurrencyISOCode 
                                        FROM Opportunity__c 
                                        WHERE Id 
                                        IN: oppIdSet];

        if(!oppList.isEmpty()){

            for(Opportunity__c opp : oppList){
                
                if(opp.CurrencyISOCode != orgCurr){

                    oppList1.add(opp.Id);
                }else{

                    oppList2.add(opp.Id);
                }
            }
        }


        invoiceCheckerList = [SELECT Id, OpportunityId__c FROM Invoice__c WHERE OpportunityId__c IN: oppList1];

        opptyMapp = new Map<Id, Integer>();

        invoiceRecWithoutLines = 0;

        for(Invoice__c invoiceCheck : invoiceCheckerList){

            if(invLineChecker.get(invoiceCheck.Id) == true){

                invoiceRecWithoutLines += 1;

                opptyMapp.put(invoiceCheck.OpportunityId__c, invoiceRecWithoutLines);
            }
        }


        for(Id key : opptyMapp.keySet()) {
            
            Integer countr = opptyMapp.get(key);

            if(countr > 0){

                oppListToUpdate.add(new Opportunity__c( Id=key,
                                                        InvoiceTotal__c=0,
                                                        InvoiceGrossProfit__c=0,
                                                        InvoiceDiscountTotal__c=0));
            }else{
                oppList3.add(key);
            }
        }

        if(!oppList3.isEmpty()){
            System.debug('SUCCESS!');
        }
}

I've highlighted the parts above which am not being covered. I'm having difficulty getting them covered in my Test class. The list  oppList3 aren't populated.

Here are the Test class I have so far:
@isTest
    private static void deleteInvoiceLinesWithLineRecords(){

        initializeData();

        insert invoiceLineList;

        System.assertEquals(3, invoiceLineList.size());
		
		List<InvoiceLine__c> delInvList = [SELECT Id FROM InvoiceLine__c LIMIT 1];
		
		System.assertEquals(1, delInvList.size());

        Test.startTest();

        	try
			{
				delete delInvList;
			}Catch(Exception e)
            {
                String errormessage = e.getMessage();
                system.debug(errormessage);
            }

        Test.stopTest();

        delInvList = [SELECT Id FROM InvoiceLine__c];

        System.assertEquals(2, delInvList.size());
    }

    @isTest
    private static void initializeData(){
        
        opportunityRecord = new Opportunity__c();
        opportunityRecord.Account__c = '0012x000002kyl7AAA'; // required field
        opportunityRecord.CurrencyIsoCode = 'USD';
        opportunityRecord.Organisation__c = 'Default';
        opportunityRecord.InvoiceTotal__c = 0;
        insert opportunityRecord;
        invoiceRecord = new Invoice__c();
        invoiceRecord.OpportunityId__c = opportunityRecord.Id; // required field
        invoiceRecord.Account__c = '0012x000002kyl7AAA';
        invoiceRecord.TaxType__c = 'No Tax';
        invoiceRecord.TaxRate__c = 0;
        insert invoiceRecord;
        InvoiceLine__c invoiceLineRecord1 = new InvoiceLine__c();
        invoiceLineRecord1.InvoiceId__c = invoiceRecord.Id; // required field
        invoiceLineRecord1.DiscountType__c = 'Percent';
        invoiceLineRecord1.DiscountPercent__c = 5;
        invoiceLineRecord1.ProductType_Hidden__c = 'Discount';
        invoiceLineRecord1.Description__c = 'TEST';
        invoiceLineRecord1.Product__c = 'a042x00000BXXaZAAX';
        invoiceLineRecord1.Quantity__c = 1;
        invoiceLineRecord1.SalesPrice__c = 500;
        InvoiceLine__c invoiceLineRecord2 = new InvoiceLine__c();
        invoiceLineRecord2.InvoiceId__c = invoiceRecord.Id; // required field
        invoiceLineRecord2.DiscountType__c = 'Amount';
        invoiceLineRecord2.DiscountAmount__c = null;
        invoiceLineRecord2.Description__c = 'TEST';
        invoiceLineRecord2.Product__c = 'a042x00000BXXaZAAX';
        invoiceLineRecord2.Quantity__c = 1;
        invoiceLineRecord2.SalesPrice__c = 100;
        InvoiceLine__c invoiceLineRecord3 = new InvoiceLine__c();
        invoiceLineRecord3.InvoiceId__c = invoiceRecord.Id; // required field
        invoiceLineRecord3.DiscountPercent__c = null;
        invoiceLineRecord3.DiscountAmount__c = 0;
        invoiceLineRecord3.Description__c = 'TEST';
        invoiceLineRecord3.Product__c = 'a042x00000BXXaZAAX';   
        invoiceLineRecord3.Quantity__c = 1;
        invoiceLineRecord3.SalesPrice__c = 200;
        invoiceLineList = new List<InvoiceLine__c>();
        
        invoiceLineList.add(invoiceLineRecord1);
        invoiceLineList.add(invoiceLineRecord2);
        invoiceLineList.add(invoiceLineRecord3); 
    }
}

Again, any insights to this will be very much appreciated.

Please let me know if you need additional details.

Thank you!

- Sid
 
Hi experts, I'm trying to create a Test class for my trigger handler however can't seem to progress. My trigger is a simple AFTER UPDATE that fires whenever the CurrencyIsoCode is changed for the Opportunity record.

A code snippet from my trigger handler follows below:
public class OpportunityTriggerHandler extends TriggerHandler

private void updateCurrencyIsoCode(){

        for(Opportunity__c  oppty : (List<Opportunity__c>) Trigger.new){
            Opportunity__c oldOppty = (Opportunity__c)Trigger.oldMap.get(oppty.Id);

            if (oppty.CurrencyIsoCode != oldOppty.CurrencyIsoCode){

                opptyList.add(oppty);
            }  
        }
    }

I keep failing coverage for this line, as shown above.
opptyList.add(oppty);

Finally, here is my test class:
@isTest
    private static void updateInvoiceFields()
    {
        Opportunity__c opportunityRecord = new Opportunity__c();
        opportunityRecord.Account__c = '0012x000002kyl7AAA';
        opportunityRecord.CurrencyIsoCode = 'USD';
        opportunityRecord.Organisation__c = 'Default';
        insert opportunityRecord;

        List<Opportuntiy__c> opportunityRecordList = new List<Opportunity__c>();
        opportunityRecordList.add(opportunityRecord);

        Test.startTest();
            System.assertNotEquals(0, opportunityRecordList.size());
            for(Opportunity__c opportunityRecord : opportunityRecordList){
                System.assertNotEquals(opportunityRecord.CurrencyIsoCode, 'HKD');
                opportunityRecord.CurrencyIsoCode = 'HKD';
                System.assertEquals(opportunityRecord.CurrencyIsoCode, 'HKD');
            }
            try
            {
                update opportunityRecordList;
            }Catch(Exception e)
            {
                String errormessage = e.getMessage();
                system.debug(errormessage);
            }
        Test.stopTest();
    }

So, I changed the field as shown above however am not able to achieve coverage. By the way, all my assertions above passed.

What am I missing or doing wrong?

Thanks!

- Sid
There's documentation and a number of articles about how you can have an LWC component open a page, including with query parameters (such as this one (https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.use_navigate_add_params_url) from the official documentation). There's also documentation about how you open different types of page, though the NavigationMixin doesn't support direct VF page access.

It appears that, while we can set up a custom tab that wraps the VF page, the VF page is then embedded in an iframe and, due to the lightning and VF pages residing on different domains, there's no communication possible across the iframe boundary (so the query parameters are not visible).

I need to be able to open a VF page from an LWC and pass it several query parameters. My issue is that none of the mechanisms explain how I can get the base URL for a VF page that will work from my LWC (I need to do this for standard and community portal usages).

There's even an article, here (https://developer.salesforce.com/blogs/developer-relations/2017/01/lightning-visualforce-communication.html), that discusses the basic issue (at least in the Aura context). Unfortunately it entirely glosses over how to get the URL for the VF page, simply saying:
 
"vfHost is the host Visualforce pages are loaded from in your environment. In a real-life application, you should obtain this value dynamically instead of hardcoding it"

Do you know how I can obtain the VF page URL in a robust and automatic way from Salesforce (since this component will be part of a package I can't hard-code the access)?
  • August 19, 2019
  • Like
  • 0
In Organization-Wide Sharing Defaults I can see Standard Objects but it Shows few Custom Objects only.I Can't find some Custom Objects in OWD.Kindly give an Explanation on this.
Thanks in Advance!