1

I am trying pass contact id as a parameter to one of the webservices and get value to update in account object. But i am not able to set contact records ID field as a parameter in end point URL.

List<Contact> ContactUpdate = [SELECT id  FROM Contact where Rep__c like 'CRM%'];
     String ContactID;
     HttpRequest req = new HttpRequest();
     req.setTimeout(60000); 
     req.setHeader('Accept','*/*');
     req.setHeader('Content-Type','application/json'); // Content Type
     req.setMethod('GET'); 
     for (Contact c : ContactUpdate)
     {    
     ContactID = c.id;
     req.setEndpoint('https://xxx/xxxx/xxxxx/xxx/xxx-lookup? ContactID= {! ContactID});

     Http http = new Http();
     HTTPResponse res = http.send(req);
     System.debug(res.getBody());

        JSONParser parser = JSON.createParser(res.getBody());

        String GMMID;
        while (parser.nextToken() != null) {
            if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && 
                (parser.getText() == 'GCGMM')) {
                // Get the value.
                parser.nextToken();
                // Compute the grand total price for all invoices.
                GMMID = parser.gettext();
            }
        }
        //ContactUpdate.IsFutureContext__c = true;
        C.Group_ID__c = GMMID;
        update c;
        }

Could someone please guide me in adding variable as parameter in endpoint URL.

  • Do those spaces in your endpoint url really exist in your code, or were they simply a mistake made in copy/pasting/formatting your code block? Also, are you getting an error? – Derek F Mar 1 '17 at 18:06
4

It's just a string. You can't use merge syntax in Apex, you concatenate using the + operator.

String endpoint = '...?contactId=' + contactId;

Note you should remove spaces from your endpoint, unless you actually require them.

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.