I have a custom object in salesforce. Every record has many fields. One is a lookup field in which we select an opportunity from lookup. What we want is another lookup field: Account__c which has to be automatically populated with account name of that respective opportunity.

In the code below, "After insert" is working but before update is not working properly.

 trigger trigger_name on object__c (after insert, before update) {

    List&lt;object__c&gt; listOfSfdcRecords  =[SELECT Opportunity__r.AccountId,Opportunity__r.Account.Name FROM object__c WHERE ID IN :trigger.newMap.keySet()];
    Map&lt;String, Id&gt; myMap = new Map&lt;String, Id&gt;(); 
    for(object__c eachRec : listOfSfdcRecords){
        System.debug(listOfSfdcRecords);          
        myMap.put(eachRec.Id, eachRec.Opportunity__r.AccountId);
    }
    if(trigger.isAfter){
        List &lt;object__c&gt; updateList = new List &lt;object__c&gt;();
        for(object__c eachSfdc: listOfSfdcRecords){
            System.debug(eachSfdc.Opportunity__r.AccountId);
            object__c sfdc = new object__c(Id = eachSfdc.Id);
            sfdc.Test_Account__c = eachSfdc.Opportunity__r.AccountId;
            updateList.add(sfdc);
        }
        update updateList;
    }
    if(trigger.isBefore){
        for(object__c eachSfdc: trigger.new){
            //System.debug('before update'+eachSfdc.Opportunity__r.AccountId);
            System.debug('b4 update'+myMap.get(eachSfdc.id));
            eachSfdc.Test_Account__c = myMap.get(eachSfdc.id);
        }
    }

}



Question: What is the best way (price wise) to travel from Japan to Mexico and Venezuela, then come back?
Answer: I do like to push them - once again, if you're really stuck and don't know where to look, consider Flightfox.  I'm not affiliated, although I do compete on there as one of their 'experts'.  Basically they have a bunch of 'experts' that compete to find you the best price.  With what may work best as an open-jawed flight or a double-return (Japan->Mexico return, Mexico->Venezuela return) will be investigated by people on there.

It's not a free service, but if you do want to use it, check out my profile on here for a discount link.

Alternatively sites like kayak and skyscanner are a good start if you want to do all the grunt work yourself.