function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BrookesyBrookesy 

Trigger Writing to a field.

Hi,

 

Im quite an amateur coder so this is probably something easily solved. But im hoping after seeing it once i can reuse it across many objects :)

 

Basically i have a custom object (Currencies__c) that holds currency pairs say USD and CAD. These are held in 2 fields Settlement and Currency respectively.

 

I managed to piece together some code that would pull out all the Currency's from the custom object and display them on a visualforce page (along with some help from dev support on the delimiting and display bit, just couldn't get that working!) 

 

What im wondering now is how i can use the code i wrote in the class as a trigger on Accounts that is run after update and after insert. So that any time someone touches the account it will query all the related Currencies from the custom object and write them to a long text area (Currency_List__c) (as there could be 10 to 50+) 

 

Below is the code i used to pull the currencies in a delimited fashion (USD;CAD;GBP etc)

 

Any idea how i can convert this to a trigger? I assume i can reuse a lot of this code to pull the data but i assume il hit govenor limits if there is over 20 records? (i forget exact limits!)

 

Any help would be great!

 

 

public class currencyListTest {public String getSettlementCurrencies2() {    String strCur;    strCur = '';    for (List<Currencies__c> currencyList : [select CurrencySettlement__c from currencies__c where Account__c = :ApexPages.currentPage().getParameters().get('id')]) {        for (Currencies__c currencyItem : currencyList) {            if (strCur != '') {                strCur += ';';            }            strCur += currencyItem.CurrencySettlement__c;        }    }    return strCur;}public List<Currencies__c> getSettlementCurrencies() {    List<Currencies__c> currencyList;    currencyList = [select CurrencySettlement__c from currencies__c where Account__c = :ApexPages.currentPage().getParameters().get('id')];    return currencyList;} 

}