0

I have a class that looks like this:

public class NWTAttachCMController { 
    private final static String urlFieldName = 'AttachNWTLetters__c';
    private String partnerServerUrl;
    private ApexPages.StandardSetController controller;
    private List<String> NWTIds = new List<Id>();
    
    public String CMUrl {get; private set;}
    
    public NWTAttachCMController(ApexPages.StandardSetController controller) {
        this.controller = controller;
    
        for (DHR_No_Wage_Terms__c NWT : (List<DHR_No_Wage_Terms__c>)controller.getSelected()){
            NWTIds.add(NWT.Id);
        }
    
        partnerServerUrl = 'https://'+ApexPages.currentPage().getHeaders().get('Host')+'/services/Soap/u/26.0/'+UserInfo.getOrganizationId();
    }
    
    public PageReference prepareCMUrl() {
        CMUrl = 'https://composer.congamerge.com' + 
        '?SessionId=' + UserInfo.getSessionID() +
        '&ServerUrl=' + partnerServerUrl +
        '&Id=' + UserInfo.getUserId() +
        '&QueryId=[DHRNoWageTermQ]a3c2R000004JF9PQAW?pv0=' + '\''+ String.join(new List<String>(NWTIds),'\'|\'')+'\'';
    
    
        return null;
    }
}

and it works for a batch that I run that downloads merged templates but when I try to use it to create attachments, it gives the following error.

MALFORMED_QUERY: DHR_No_Wage_Terms__c where Id IN (''a492R0000033AkdQAE','a492R0000033AkcQAE'')
^
ERROR at Row:1:Column:277
expecting a right parentheses, found 'a492R0000033AkdQAE'

Here is the query:

SELECT Id,Account__R.Name,DHR_Employee__r.First_Name__c, DHR_Employee__r.Last_Name__c, DHR_Employee__r.Address1__c, DHR_Employee__r.Address2__c, DHR_Employee__r.City__c, DHR_Employee__r.State__c, DHR_Employee__r.Zip__c, Last_Paid_On__c FROM DHR_No_Wage_Terms__c where Id IN ('{pv0}')

Has anyone run across this or see my error?

1 Answer 1

2

You're quoting your strings too many times.

    '&QueryId=[DHRNoWageTermQ]a3c2R000004JF9PQAW?pv0=' + '\''+ String.join(new List<String>(NWTIds),'\'|\'')+'\'';
    

Here, you wrap each Id in single quotes, which is correct.

Here, it appears you're doing the same thing over again, assuming that pv0 here is the value generated above:

where Id IN ('{pv0}')   

Note the extra pair of single quotes around the already-quoted pv0 value.

1
  • That did the trick!! Thanks David.
    – DeWayne
    Dec 21, 2020 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .