Apex: Different condition for Accountid

Asked

Viewed 164 times

0

In the code below I used the variable AccountId to obtain the account with the name "Integration AWS", but I need the consultation to not take accounts that were changed by "Integration AWS".

How can I do on the consultation part "Account. LastModifiedById =: AccountId" not to leave the hard code "Account. LastModifiedById <> '0002265448786545'?

    Id AccountId  = Schema.SObjectType.User.getRecordTypeInfosByDeveloperName().get('Integration AWS').getRecordTypeId(); 
    public void executeLog() {         
        for(AccountHistory event: [SELECT Account.CPF__c, Account.Name, Field, OldValue, NewValue, CreatedDate, Account.RecordTypeId
                                   FROM AccountHistory                                   
                                   WHERE CreatedDate = Today And Account.RecordTypeId =: recordTypePersonAccount And Account.LastModifiedById =: AccountId]) {                           
            generateLog(event);     
                                               
        }    

1 answer

0

I made this new code for the Apex class no longer to become hard code according to good practices for Salesforce, follow my solution.

public class GenerateFraud {
List<Case> logs = new List<Case>();
Id recordTypePersonAccount = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('PersonAccount').getRecordTypeId(); 
List<User> userId = [SELECT id FROM User WHERE Name = 'Integration AWS' limit 1];
public void executeLog() {         
    for(AccountHistory event: [SELECT Account.CPF__c, Account.Name, Field, OldValue, NewValue, CreatedDate, Account.RecordTypeId
                               FROM AccountHistory                                   
                               WHERE CreatedDate = Today And Account.RecordTypeId =: recordTypePersonAccount And Account.LastModifiedById <> :userId]) {                           
        generateLog(event);     
                                           
    }    
    try {
        if(logs.isEmpty()) {
            return; 
        }
        else {
            insert logs; 
        }
    }
    catch (DmlException e) {
        System.debug('The following exception has ocurred: ' + e.getMessage()); 
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.