Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am a new developer and I have a task I need to complete and I am totally clueless on how to tackle. This is an angular calendar App. And my task in this big project is to simply make it function so that when a user types a field in the search query, it searches against a specific "Agency" and "MasterAgency" accounts instead of searching against All the accounts. So this is an Apex, Angular application. I created a RecordHelper class and here is a snippet below:

public static Set<Id> getAgencyRecordTypeIds(){

        Set<Id> recordTypeIds = new Set<Id>();

        recordTypeIds.add(GetRecordTypeIdByDeveloperName('Account','Agency'));

        recordTypeIds.add(GetRecordTypeIdByDeveloperName('Account','MasterAgency'));

        return recordTypeIds;

    }

Then I created another class so that I can use the remoteAction to pass it on Angular, snippet shown below:

@RemoteAction

    public static Set<Id> passRecordsIds() {

        Set<Id> fetchRecordTypeIds = RecordTypeHelper.getAgencyRecordTypeIds();

        return fetchRecordTypeIds;

    }

Then I used a .vfr method to pass this remoteaction results to Angular. Here is the Angular code for it:

var passRecordsIds = vfr.send('S1_PAV_CalendarController.passRecordsIds', $scope.data.SFSendOpts, false);
            passRecordsIds().then(function(result){
                                        $scope.typeRecord = result;
                                        $log.debug($scope.typeRecord);
                                    }
                                    ,function(error){
                                        $log.error('passRecordsIds error');
                                        $log.error(error);
                                        $window.alert(error.message);
        });
So where I am stuck is that in my Angular code, I need to modify the Query statements so that it searches against the Account and MasterAccount only. I think my query after the AND statement is totally wrong. My boss was saying I need to loop through it but I don't know how to tackle this.
var queryString = $scope.ACCOUNT_SELECT_PART + "  FROM Account WHERE" + " (Name Like '%" + searchTerm + "%' OR Safeco_Sub_Stat__c  Like '%" + searchTerm + "%') AND RecordTypeId IN ('Agency', 'MasterAgency')";

I originally had written

var queryString = $scope.ACCOUNT_SELECT_PART + "  FROM Account WHERE" + " (Name Like '%" + searchTerm + "%' OR Safeco_Sub_Stat__c  Like '%" + searchTerm + "%') AND typeRecord IN :passRecordsIds"; 
But it didn't work and the boss said it was incorrect and that I needed to include the field name RecordTypeId. I know I have skipped on a lot of code but these are the modifications I have made. Any help would be greatly appreciated. Thank you

1 Answer

0 votes
by (32.1k points)
edited by

Seems like you'd need a combination of two different attempts. Try the code beneath because I believe the ID's of the recordtypes you want are int passRecordIds.

var queryString = $scope.ACCOUNT_SELECT_PART + "  FROM Account WHERE" + " (Name Like '%" + searchTerm + "%' OR Safeco_Sub_Stat__c  Like '%" + searchTerm + "%') AND RecordTypeId IN : passRecordsIds";

To learn in-depth about Workflow in Salesforce, sign up for industry-based Salesforce Training!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...