1

Trying to return true for renderELEMENT based on the user being either on the AccountTeam OR having a field checked on their user record. Able to produce based on just either part, but Not able to get the either / or quality working. thanks for help!

 public class AccountTeamChecker {
    private ApexPages.StandardController sc;
    public AccountTeamChecker(ApexPages.StandardController sc) {
        this.sc = sc;
    }
    // Returns true if the user is an account team member
    public Boolean renderELEMENT{
        get {
            if (renderELEMENT== null) {
                renderELEMENT= [
                        select count()
                        from AccountTeamMember
                        where AccountId = :sc.getId()
                        and UserId = :UserInfo.getUserId()
                   //   and AccountAccessLevel in ('Read', 'Edit', 'All')
                        ] > 0;


            } else {
                        renderELEMENT= [
                    select Admin_Team__c
                    from User
                    where Id = :Userinfo.getUserId()
                    ].Admin_Team__c;

            system.debug('====================='+renderELEMENT);
            }

            return renderELEMENT;
        }
        private set;
    }
}
1

Checking them one after another like this is probably the cleanest way to do it:

public Boolean renderELEMENT{
    get {
        if (renderELEMENT == null) {
            renderELEMENT = checkUser();
        }
        return renderELEMENT;
    }
    private set;
}

private Boolean checkUser() {
    if ([select count() from User
            where Id = :UserInfo.getUserId() and Admin_Team__c = true] > 0) {
        return true;
    }
    if ([select count() from AccountTeamMember
            and UserId = :UserInfo.getUserId() and AccountId = :sc.getId()] > 0) {
        return true;
    }
    return false;
}
0

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.