4

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

  • rewrite your question with an example of the data (fully blown) you want to fetch and the query you use for. because i don't think someone here understand what you are trying to do – Revln9 Jun 27 '16 at 16:01
  • Hi Sam, Can you please explain what you mean by "example of data(fully blown)"? I myself am not very familiar with all the accounts, I am just trying to work with the partial code my company has provided me. – afzaaldeveloper1 Jun 27 '16 at 16:05
  • i'm not a salesforce guy but take a look at this question http://stackoverflow.com/questions/21059620/salesforce-apex-query-accounts-based-on-activity-history?rq=1 – Revln9 Jun 27 '16 at 16:18

1 Answers1

1

I think you need a combination of your two attempts. Try the code below 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";
Psymn
  • 372
  • 2
  • 13