I wrote this class so that it can be triggered before the the record gets inserted one of its fields will get merged with a different record from an object of the same type. When I've tried to do an if statement to check if the map is not empty it comes up with an error that it has to be boolean and when I try to merge the field it doesn't let me saying that the variable in the map doesn't exist.

public class Fieldmerge

    public static void merge (List<Account> listaccount, map<id, Opportunity> oldmap)
        id[] accid = new list<id>();
        for(Account acc : listAccount) {

        map<Id, Account> maporacle = new map<Id, Account>(
            [select Id, BigMachines__C from Account where ID IN :accid]

        for (Account ac : listAccount)
               ac.Account_Dealer_CRM_ID__c = maporacle.get(ac.BigMachines__c) + "_" +  ac.Account_Dealer_CRM_ID__c; 

Your if statement seems incomplete. All you are doing is getting the Account record without doing any kind of true/false validation which is what you normally do inside a if statement. You could so something like the following:

if(maporacle.get(ac.BigMachines__c) != null){}

Or you could get a field that you check against such as the following:

if(maporacle.get(ac.BigMachines__c).Type == "Admin"){}

If you don't have something like that you don't have a complete if statement.

|improve this answer|||||
  • thanks for the response, I'm quiet new to mapping so I was wondering if checking whether the field is empty using an "ac" is appropriate. would it still get records from the looked up object ? – Greg Jul 12 '17 at 15:56
  • Are you asking if you can get information from the maporacle.get()? Because you will get whatever you have in your Map. Currently you will get an Account Record. Once you get the account record you will need to call a field. So after your if statement you need to choose a field to add to the merge. – Dan Kowalski Jul 12 '17 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.