• Benedict Yeo 6
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 5
    Replies
Hi, I've a problem with the following code.. I can get the o.AccountId correctly, but whenever I run the SOQL query, the result returned in an empty set.. What am I doing wrong?
 
public class prefillFields {
    
    public static void applyAddress(Order o) {
        System.debug('o.AccountId: ' + o.AccountId);
        String accountId = o.AccountId;
        
        List<Account> accounts = Database.query('SELECT id, Name, BillingCity, Department_NS__c, ReportingCountry_NS__c FROM Account WHERE Id = :accountId');
            //[SELECT id, Name, BillingCity, Department_NS__c, ReportingCountry_NS__c FROM Account]; // WHERE Id = :o.AccountId];
        if(accounts.size() > 0) {
            System.debug('Gotten address..?');
            System.debug('ID: ' + accounts[0].id);
            System.debug('City: ' + accounts[0].billingCity);
            
            for (Account a : accounts) {
                String accountName = a.Name;
                
                String billingCity = a.BillingCity;
                System.Debug('Billing City: ' + billingCity);
            }
        } else {
            System.debug('List is empty!');
        }
    }
}

 
Hi, I'm trying to update addresses on my Orders record from the Account selected. This is my code, but somehow it's getting very low code coverage, and I'm not sure what I'm doing wrong.. Can someone please point me in the right direction? Thanks!
 
trigger fillAddresses on Order (before insert) {
    if (Trigger.isBefore) {
        if (Trigger.isInsert) {
            try {
                Order[] orders = Trigger.new;
                
                prefillFields.applyAddress(orders);
            }
            catch (Exception ex) {
                System.debug('Exception caught: ' + ex.getMessage());
            }
        }
    }
}


 
public class prefillFields {
    
    public static void applyAddress(Order[] orders) {
        for (Order o : orders) {
            Account[] accounts = [SELECT BillingCity, BillingCountry, BillingPostalCode, BillingState, BillingStreet, ShippingCity, ShippingCountry, ShippingPostalCode, ShippingState, ShippingStreet, Department_NS__c, ReportingCountry_NS__c FROM Account WHERE AccountNumber =: o.AccountId];
            
            // System.Debug('a.BillingCountry');
            // for (Account a : accounts) {
                o.BillingCity = 'City';
                o.BillingCountry = 'Country';
                o.BillingPostalCode = '12345';
                o.BillingState = '';
                o.BillingStreet = 'Street';
                o.ShippingCity = 'City';
                o.ShippingCountry = 'Country';
                o.ShippingPostalCode = 'Country';
                o.ShippingState = '';
                o.ShippingStreet = 'Street';
                // Still need to get set fields for Department and Shipping Country
            // }
            
            update o;
        }
    }   
}

 
I've just started using Apex, and am trying to get the Line Items in Orders to reflect into a custom object Collection when a new Collection record is created. I've created another object called Collection Item as well.
However, I really can't get it to work.. Is there anyone who can point me in the correct direction? Thanks!
Hi, I am trying to set which fields are visible and which are not on the Orders creation page. From what I see, whatever is set in the page layout to display will be reflected in the creation page, which is not what I want. For example, there is a field that we have that will only be filled after synchronising the order with our ERP system, but it's appearing in the creation page. Also, we are going to do a workflow to pull the Billing and Shipping Addresses from the Account, so I don't want to display those fields in the creation page.

Is there any way to hide these fields? Thanks!
I would like to allow our salespeople track credit notes on my Salesforce org using an Invoice object that was created. We are going to create a separate record type "Credit Notes" for that.

Are we able to change the signs for the quantities and amounts from positive in the records to negative for reporting? So for example, as a record, I might have 2 items with a value of $100 as a line item, but in our reporting, this reports as -2 items with a value of -$100?

Thanks in advance!
I have a custom object Inventory, which has a many-to-one relationship with the standard object Product. I'm trying to write some VisualForce code to link the two together, but have not had success. Anyone has any idea how this can be done? Thanks!
Hi, I would like to ask if there's a streaming API available for the Orders object? I'm very new in this, but can't find any information about it.. Thanks!
Hi, I would like to create a Person Account through the API, but somehow am unable to do so. Person Accounts are enabled in my org already.
Please help, thanks!
Hi, I would like to create a Person Account through the API, but somehow am unable to do so. Person Accounts are enabled in my org already.
Please help, thanks!
Hi, I'm trying to update addresses on my Orders record from the Account selected. This is my code, but somehow it's getting very low code coverage, and I'm not sure what I'm doing wrong.. Can someone please point me in the right direction? Thanks!
 
trigger fillAddresses on Order (before insert) {
    if (Trigger.isBefore) {
        if (Trigger.isInsert) {
            try {
                Order[] orders = Trigger.new;
                
                prefillFields.applyAddress(orders);
            }
            catch (Exception ex) {
                System.debug('Exception caught: ' + ex.getMessage());
            }
        }
    }
}


 
public class prefillFields {
    
    public static void applyAddress(Order[] orders) {
        for (Order o : orders) {
            Account[] accounts = [SELECT BillingCity, BillingCountry, BillingPostalCode, BillingState, BillingStreet, ShippingCity, ShippingCountry, ShippingPostalCode, ShippingState, ShippingStreet, Department_NS__c, ReportingCountry_NS__c FROM Account WHERE AccountNumber =: o.AccountId];
            
            // System.Debug('a.BillingCountry');
            // for (Account a : accounts) {
                o.BillingCity = 'City';
                o.BillingCountry = 'Country';
                o.BillingPostalCode = '12345';
                o.BillingState = '';
                o.BillingStreet = 'Street';
                o.ShippingCity = 'City';
                o.ShippingCountry = 'Country';
                o.ShippingPostalCode = 'Country';
                o.ShippingState = '';
                o.ShippingStreet = 'Street';
                // Still need to get set fields for Department and Shipping Country
            // }
            
            update o;
        }
    }   
}

 
Hi, I am trying to set which fields are visible and which are not on the Orders creation page. From what I see, whatever is set in the page layout to display will be reflected in the creation page, which is not what I want. For example, there is a field that we have that will only be filled after synchronising the order with our ERP system, but it's appearing in the creation page. Also, we are going to do a workflow to pull the Billing and Shipping Addresses from the Account, so I don't want to display those fields in the creation page.

Is there any way to hide these fields? Thanks!
I would like to allow our salespeople track credit notes on my Salesforce org using an Invoice object that was created. We are going to create a separate record type "Credit Notes" for that.

Are we able to change the signs for the quantities and amounts from positive in the records to negative for reporting? So for example, as a record, I might have 2 items with a value of $100 as a line item, but in our reporting, this reports as -2 items with a value of -$100?

Thanks in advance!
Hi, I would like to ask if there's a streaming API available for the Orders object? I'm very new in this, but can't find any information about it.. Thanks!
Hi, I would like to create a Person Account through the API, but somehow am unable to do so. Person Accounts are enabled in my org already.
Please help, thanks!