You need to sign in to do that
Don't have an account?
rajesh k 10
How can i show Account Table record Name as Picklist of below code?
Hi,
Below code showing Records in Table .How can show these records as picklist
Below code showing Records in Table .How can show these records as picklist
public void fetch() { errMsg = 'Some error occurred, please try again'; try { //----------------------------------- // Login via SOAP/XML web service api //----------------------------------- HttpRequest request = new HttpRequest(); request.setEndpoint('https://' + LOGIN_DOMAIN + '.salesforce.com/services/Soap/u/29.0'); System.debug(request); request.setMethod('POST'); System.debug(request); request.setHeader('Content-Type', 'text/xml;charset=UTF-8'); System.debug(request); request.setHeader('SOAPAction', '""'); System.debug(request); //not escaping username and password because we're setting those variables above //in other words, this line "trusts" the lines above //if username and password were sourced elsewhere, they'd need to be escaped below request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + pwd+ '</password></login></Body></Envelope>'); Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement() .getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/') .getChildElement('loginResponse', 'urn:partner.soap.sforce.com') .getChildElement('result', 'urn:partner.soap.sforce.com'); System.debug(request); //------------------------------- // Grab session id and server url //-------------------------------- final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0]; final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText(); //---------------------------------- // Load first 10 accounts via REST API //--------------------------------- final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/v22.0/query/'); theUrl.getParameters().put('q','Select a.Phone, a.Name, a.CreatedBy.FirstName, a.CreatedById From Account a limit 10'); request = new HttpRequest(); request.setEndpoint(theUrl.getUrl()); request.setMethod('GET'); request.setHeader('Authorization', 'OAuth ' + SESSION_ID); String body = (new Http()).send(request).getBody(); JSONParser parser = JSON.createParser(body); do{ parser.nextToken(); }while(parser.hasCurrentToken() && !'records'.equals(parser.getCurrentName())); parser.nextToken(); acc = (List<Account>) parser.readValueAs(List<Account>.class); } catch(Exception e) { displayError = 'block'; } }For showing picklist i tried like below but its not working.Could you please help
errMsg = 'Some error occurred, please try again'; try { //----------------------------------- // Login via SOAP/XML web service api //----------------------------------- HttpRequest request = new HttpRequest(); request.setEndpoint('https://' + LOGIN_DOMAIN + '.salesforce.com/services/Soap/u/29.0'); System.debug(request); request.setMethod('POST'); System.debug(request); request.setHeader('Content-Type', 'text/xml;charset=UTF-8'); System.debug(request); request.setHeader('SOAPAction', '""'); System.debug(request); //not escaping username and password because we're setting those variables above //in other words, this line "trusts" the lines above //if username and password were sourced elsewhere, they'd need to be escaped below request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + pwd+ '</password></login></Body></Envelope>'); Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement() .getChildElement('Body', 'http://schemas.xmlsoap.org/soap/envelope/') .getChildElement('loginResponse', 'urn:partner.soap.sforce.com') .getChildElement('result', 'urn:partner.soap.sforce.com'); System.debug(request); //------------------------------- // Grab session id and server url //-------------------------------- final String SERVER_URL = resultElmt.getChildElement('serverUrl', 'urn:partner.soap.sforce.com') .getText().split('/services')[0]; final String SESSION_ID = resultElmt.getChildElement('sessionId', 'urn:partner.soap.sforce.com') .getText(); //---------------------------------- // Load first 10 accounts via REST API //--------------------------------- final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/v22.0/query/'); Account [] accounts=[SElECT Name, Id FROM Account]; System.debug('******accounts****'+accounts); //theUrl.getParameters().put('q','Select a.Phone, a.Name, a.CreatedBy.FirstName, a.CreatedById From Account a limit 10'); List<SelectOption> options = new List<SelectOption>(); for (Account a : accounts) { System.debug('******accounts****'+a); options.add(new SelectOption(a.Id,a.Name)); System.debug('******options****'+options); } // accountList =options; request = new HttpRequest(); request.setEndpoint(theUrl.getUrl()); request.setMethod('GET'); request.setHeader('Authorization', 'OAuth ' + SESSION_ID); System.debug('******request****'+request); String body = (new Http()).send(request).getBody(); System.debug('******body ****'+body); JSONParser parser = JSON.createParser(body); do{ parser.nextToken(); }while(parser.hasCurrentToken() && !'records'.equals(parser.getCurrentName())); parser.nextToken(); options= (List<SelectOption>) parser.readValueAs(List<SelectOption>.class); accountList =options; } catch(Exception e) { displayError = 'block'; }Thanks,