• Surjendu
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 16
    Replies
The following code gives me an XML parsing error. If the value of the node contains & then the parsing fails.

reader.getText() returns the value of the node till & which is wrong. It should
return everything as & is escaped with &

Code:
public class myClass 
{

static testMethod void myTest() 
{
String xmlString = '<—xml version="1.0" encoding="ISO-8859-1"–><project-entities><response><users><user><user-id>surone@surl &amp; t.com</user-id><code>Success</code><desc>User Created</desc></user></users></response></project-entities>';
XmlStreamReader xsr = new XmlStreamReader(xmlString);
parseResponse(xsr);
}

static void parseResponse(XmlStreamReader reader)
 {

  while(reader.hasNext()) 
  {
   
   if(reader.getEventType() == XmlTag.START_ELEMENT)
   {
    if(reader.getLocalName() == 'user-id')
    {
     System.debug('I am here');
     reader.next(); 
     if(reader.getEventType() == XmlTag.CHARACTERS)
     {
      System.debug(reader.getText());
     }
     reader.nextTag();
     reader.nextTag();
     
     if(reader.getEventType() == XmlTag.START_ELEMENT)
     {
      if(reader.getLocalName() == 'code')
      {
       reader.next();
       if(reader.getEventType() == XmlTag.CHARACTERS)
       {
        System.debug(reader.getText());
       }
      }
     }
     reader.nextTag();
     reader.nextTag(); 
     if(reader.getEventType() == XmlTag.START_ELEMENT)
     {
      if(reader.getLocalName() == 'desc')
      {
       reader.next();
       if(reader.getEventType() == XmlTag.CHARACTERS)
       {
        System.debug(reader.getText());
       }
      }
     }    
    }
   }
  reader.next();
  }
 }
}

 
what is the VisualForce control to create a drop-down menu? I dont see anything like that in the developer guide.
I have the following usecase:

I have a visualForce tab. On click of a command-link I want to open up a url(which is dynamic) in another webtab.?

I cannot create a webtab because it asks for a static URL like ww.google.com
But I create the URL dynamically based upon some logic in my code. I would like to open up the url in another tab. I dont care whether the other
tab is a web tab or visualforce tab.

Any insights would be highly appreciated.

Regads
Surjendu
I have a VisualForce page where I am using SalesForce controls like inputText..

I want to provide field level validations for the controls like inputText i am using in the VF page. I provided the filed validation as

Rule Name     No_Special_Characters_ExName  

Error Condition Formula     NOT(REGEX( Extranet_Name__c, "/^([a-zA-Z0-9_-]+)$/"))
Error Message     No Special Characters Allowed for this field.

But the problem is its not showing the validation error in the same page but showing it in the next page. The exception it showed is

Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, No Special Characters Allowed for this field.: [Id]


Why should it even go to insert? The validation should happen much before an insert. Please help
I want to send a request to a site outside SalesForce. Is there a way to put something in the request param so that the accepting server will know that the request is a vaild request and coming from SalesForce. How do I do this?
I want to send a response to a site outside SalesForce. Is there a way to put something in the request param so that the accepting server will know that the request is a vaild request and coming from SalesForce. How do I do this?
I want to send a request to a site outside of salesforce. I can do

PageReference ref = new PageReference('http://www.abc.com');
But I also want to send some RequestHeader in the HTTP Request. Can it be possible? If yes, How?
Also I want to show the new page(google.com) in a new tab. I know I can create a web tab but the thing to notice here is the url can be dynamic and hence I cannot create a web tab, as while creating web tab it asks for a URL which might change depending upon scenarios.

Any help from gurus???
Please let me know how to solve this usecase:

I have two tabs A and B

Tab A:

As part of Tab A, a VF page is invoked which has a custom controller. The VF page has a link. On click of the link I call one custom method in the controller.

<apex:commandLink action="{!openBrowser}"><apex:outputText value="Invoke extranet"/></apex:commandLink>

In the custom controller I have to create a HTTP Request , set some parameters in the request header(for Single Sign On) and send it to an endpoint outside SalesForce. Once the request is received by the intended server it, the server checks the
request header(for Single Sign On) and logs the user in the application and returns the homepae of the user. I want to show the homepage of the user in a separate Tab B in SalesForce. How do I achieve this?

public PageReference openBrowser() 
{
HttpRequest req = new HttpRequest();
req.setEndpoint('someendpoint');
req.setMethod('GET');
req.setHeader('XXX', 'SSOEnabled');

Http http = new Http();
HTTPResponse res = http.send(req);
//Now my question is how do i show the response which is an html on a separate tab
return new PageReference('/servlet/servlet.Integration?lid=01r700000006480&ic=1');
}

I know I can create a Web Tab but in that case I have to hard code the URL of the web tab. In that case i cannot set the request
headers.

Any help???



<apex:messages style="font-style:italic;font-weight:bold;color:red" layout="list"></apex:messages>

  • j_id0:j_id2:j_id3:j_id9:name: Validation Error: Value is required.
  • j_id0:j_id2:j_id3:j_id9:domainName: Validation Error: Value is required.
How do i supress the cryptic message and just print something like ValueA is required.

The reason I dont want to use SelectCheckBox  because I am not able to apply CSS on the SelectOptions. So I want to create a pageBlockList with relevant data for each record and
a checkbox for each record(for insert or delete the individual record).

If I do not want to use SelectCheckBox control of VisualForce and instead want to an iteration of checkboxes. Example

I have n records which are dynamic. That means I do not know how many records will be there. Its database driven.

UserName1      Email1      Phone1    CheckBox1
UserName2      Email2      Phone 2   CheckBox2
UserName3      Email3      Phone3    CheckBox3
...................       ...........      ...........     ....................

In this case how do I find out which of the checkboxes are selected. And how do I send the array of selected checkboxes to the controller?
Can I use javascript? If yes, plz send me some code snippets.
My code works like this. I have n number of Lead objects. When I click a checkbox I am trying to pass the value to a javascript function. It is not working. Any help. Also How do i achieve this functionality?

<apex:page controller="registerDomainController" tabStyle="Lead">
<script>
function addUsers(userid)
{
var idsToAdd = new Array();
alert('Before adding' + userid);
idsToAdd.add(userid);
}
</script>
<apex:sectionHeader title="Add User">
<apex:form>

<apex:pageBlock>
<apex:facet name="footer">

<apex:pageBlockSection title="Add Users to the Extranet">
<apex:dataTable value="{!allLeads}" var="user" cellspacing="0" cellpadding="4" border="0" width="800px">
<apex:column>
<apex:facet name="header">First Name</apex:facet>
<apex:outputText>{!user.firstname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Last Name</apex:facet>
<apex:outputText>{!user.lastname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Email Address</apex:facet>
<apex:outputText>{!user.email}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Phone number</apex:facet>
<apex:outputText>{!user.phone}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Add User</apex:facet>
<apex:inputCheckbox value="{!user.id}" onclick='addUsers({!user.id})'/>
</apex:column>

</apex:dataTable>

</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:sectionHeader>
</apex:page>
In XML StreamReader class what is the equivalent of the java method Node.getNodeValue();
Without this method how do I get the node value of a particular node?
I have the following XML
<project-entities>
 <response>
<users>
    <user>
         <user-id>testthree</user-id>
         <code>Failure</code>
        <desc>User with the same email address exists</desc>
    </user>
    <user>
        <user-id>testtwo</user-id>
        <code>Failure</code>
        <desc>User with the same email address exists</desc>
    </user>
 </users>
</response>
</project-entities>


How do I parse the xml to get corresponding value for userid,code,desc etc

I know i can use XMLStreamReader class but I just cant able to figure out how to parse to get the mapping (such as user-id testthree  has a code of failure). I can parse the whole tree but how do I make sure that a particular user block is parsed correctly. I need to parse the tree and create separate User objects.

public void parseResponse(XmlStreamReader reader)
{
while(reader.hasNext())
{
if(reader.getEventType() == XmlTag.START_ELEMENT)
{

}

if(reader.getEventType() == XmlTag.CHARACTERS)
{
System.debug('Text :::' + reader.getText());
}
reader.next();
}
}

How do i resolve this...This is my code...I am sending an XML to an endpoint n number of times(its in a for loop)...Cant i do that?

public PageReference saveUsers() {
String[] listOfSelectedUsers = getUsers();
String domainId = System.currentPageReference().getParameters().get('ex');
for(String presentVar: listOfSelectedUsers)
{

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://84.40.30.147/cm/spws');
req.setMethod('POST');

TestExtranet__c extranet = [select Extranet_Name__c from TestExtranet__c where id = :domainId];
Lead lead = [select id,firstname,lastname,email from Lead where id = :presentVar];
String requestXML = buildXMLRequest('createUser',extranet.Extranet_Name__c,lead.id,lead.firstname,lead.lastname,lead.email);

req.setBody(requestXML);
HttpResponse res = h.send(req);
XmlStreamReader reader = res.getXmlStreamReader();
boolean errorExists = parseResponseForError(reader);
if(!errorExists)
{
Extranet_User_Mapping__c mapping = new Extranet_User_Mapping__c();
mapping.Extranet_Id__c = domainId;
mapping.Leads__c = presentVar;
insert mapping;
}else
{

}


}
PageReference userConfPage = new PageReference('/apex/userConfirmation?ex='+ System.currentPageReference().getParameters().get('ex'));
return Page.userConfirmation;
}


I need to show a outputPanel depending on some clause.

IF(errorExists)
{
    <apex:pageBlockSection>
        <apex:outputText style="font-style:italic;font-weight:bold;color:red" value="{!error.errorDescription}"/>
    </apex:pageBlockSection>
}
else
{
    //show something else
}

How do I do this in VisualForce Page? Also the errorExists has to be read from the custom controller. Something like IF({!error.errorExists})???

Please help?
I know i can do the following to get userid,firstname,lastname by using the static UserInfo class. But there is no method to get Email address. How do i get email address in a controller??

  String userId = UserInfo.getUserId();
String firstName = UserInfo.getFirstName();
String lastName = UserInfo.getLastName();

I know i can do {!$User.Email} but that would only be in the visualforce pages.
How do I get the email address of the logged in user in controller.


Here is my code. I am using XMLReader class. Please let me know how to parse the xml to get the error-code and error-desc

<?xml version="1.0"?>
<project-entities>
<error>
    <error-code>Failure</error-code>
    <error-desc>I dont know</error-desc>
</error>
</project-entities>


Hi

I want to test some webservice callouts. I have created an XML and trying to send this XML to a server. It says "Testmethods do not support webservice callouts".  How can I test my code?

Plz somebody help.

My Code:

public class XMLIntegrationController
{

public static TestMethod void basicTest()
{
XMLIntegrationController demo = new XMLIntegrationController();
demo.receiveResponse();
}

public void receiveResponse()
{
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://84.40.30.147/cm/spws');
req.setMethod('POST');
String requestXML = buildXMLRequest();
System.debug(requestXML);
req.setBody(requestXML);
HttpResponse res = h.send(req);
System.debug(res.getBody());
XmlStreamReader reader = res.getXmlStreamReader();
while(reader.hasNext())
{
System.debug('Event Type:' + reader.getEventType());
if (reader.getEventType() == XmlTag.START_ELEMENT)
{
System.debug(reader.getLocalName());
}
reader.next();
}

}

public String buildXMLRequest()
{
XmlStreamWriter w = new XmlStreamWriter();
w.writeStartDocument(null, '1.0');
w.writeStartElement(null,'request',null);
w.writeStartElement(null,'invoke-api',null);

w.writeStartElement(null,'api-name',null);
w.writeCharacters('createDomain');
w.writeEndElement();//end api-name

w.writeStartElement(null,'domainName',null);
w.writeCharacters('forcewikiextranet');
w.writeEndElement();//end domainName

w.writeStartElement(null,'userId',null);
w.writeCharacters('forceuser');
w.writeEndElement();//end userid

w.writeStartElement(null,'firstName',null);
w.writeCharacters('surFirstName');
w.writeEndElement();//end firstName

w.writeStartElement(null,'lastName',null);
w.writeCharacters('surlastName');
w.writeEndElement();//end lastName

w.writeStartElement(null,'email',null);
w.writeCharacters('abc@abc.com');
w.writeEndElement();//end email

w.writeEndElement();//end invoke-api
w.writeEndElement();//end request

w.writeEndDocument();
String xmlOutput = w.getXmlString();
w.close();
return xmlOutput;
}

}

I have a picklist which have some leads. I want to send an AJAX request to show the details of the list when the user just clicks on any of the leads in the picklist. How do I do that?
I have seen some examples on dataTable and actionSupport but not able to figure out how do i do that with picklist? Any help will be appreciated.
How can i get distinct elements from the database? Does SOQL not provide something like unique or distinct?
I want to send a request to a site outside SalesForce. Is there a way to put something in the request param so that the accepting server will know that the request is a vaild request and coming from SalesForce. How do I do this?
The reason I dont want to use SelectCheckBox  because I am not able to apply CSS on the SelectOptions. So I want to create a pageBlockList with relevant data for each record and
a checkbox for each record(for insert or delete the individual record).

If I do not want to use SelectCheckBox control of VisualForce and instead want to an iteration of checkboxes. Example

I have n records which are dynamic. That means I do not know how many records will be there. Its database driven.

UserName1      Email1      Phone1    CheckBox1
UserName2      Email2      Phone 2   CheckBox2
UserName3      Email3      Phone3    CheckBox3
...................       ...........      ...........     ....................

In this case how do I find out which of the checkboxes are selected. And how do I send the array of selected checkboxes to the controller?
Can I use javascript? If yes, plz send me some code snippets.
My code works like this. I have n number of Lead objects. When I click a checkbox I am trying to pass the value to a javascript function. It is not working. Any help. Also How do i achieve this functionality?

<apex:page controller="registerDomainController" tabStyle="Lead">
<script>
function addUsers(userid)
{
var idsToAdd = new Array();
alert('Before adding' + userid);
idsToAdd.add(userid);
}
</script>
<apex:sectionHeader title="Add User">
<apex:form>

<apex:pageBlock>
<apex:facet name="footer">

<apex:pageBlockSection title="Add Users to the Extranet">
<apex:dataTable value="{!allLeads}" var="user" cellspacing="0" cellpadding="4" border="0" width="800px">
<apex:column>
<apex:facet name="header">First Name</apex:facet>
<apex:outputText>{!user.firstname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Last Name</apex:facet>
<apex:outputText>{!user.lastname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Email Address</apex:facet>
<apex:outputText>{!user.email}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Phone number</apex:facet>
<apex:outputText>{!user.phone}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Add User</apex:facet>
<apex:inputCheckbox value="{!user.id}" onclick='addUsers({!user.id})'/>
</apex:column>

</apex:dataTable>

</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:sectionHeader>
</apex:page>
I need to show a outputPanel depending on some clause.

IF(errorExists)
{
    <apex:pageBlockSection>
        <apex:outputText style="font-style:italic;font-weight:bold;color:red" value="{!error.errorDescription}"/>
    </apex:pageBlockSection>
}
else
{
    //show something else
}

How do I do this in VisualForce Page? Also the errorExists has to be read from the custom controller. Something like IF({!error.errorExists})???

Please help?
Hello all,
I'm a newbie on Salesforce and still learning. I'm coming across one problem for which i need your utmost help.
 
This is for the development of Employee Info application where the detail information of each employee is feeded into the application and can be managed accordingly... so,
How can i add(insert) a new record in my custom object where i have created a custom command button.
Below is the apex code for my controller:
 
here EmpInfo__c is custom object where all the information should be saved.
 

******************************

<apex:commandButton action="{!Save}" value="Save" /> // onclick of save button, a new record should be inserted

******************************

 

 

public class EmpCon {

String[] YOE = new String[]{};

String[] Desg = new String[]{};

EmpInfo__c emp;

String Id=System.currentPageReference().getParameters().get('IDInput');

String name=System.currentPageReference().getParameters().get('NameInput');

String add=System.currentPageReference().getParameters().get('AddInput');

String phone=System.currentPageReference().getParameters().get('PhoneInput');

String dob=System.currentPageReference().getParameters().get('DOBInput');

String doj=System.currentPageReference().getParameters().get('DOJInput');

String exp=System.currentPageReference().getParameters().get('ExpInput');

String desg1=System.currentPageReference().getParameters().get('DesgInput');

String skill=System.currentPageReference().getParameters().get('SkillInput');

 

public PageReference Save() {

PageReference curPage = System.currentPageReference();

EmpInfo__c emp;

emp = new EmpInfo__c(ID__c ='Id', Name__c='name', Address__c='add', Phone__c='phone', Years_Of_Experience__c='exp', Designation__c='desg1', Skills__c='skill');


try

{

insert emp; // here is the problem... how should insert a new record???


}catch (DmlException e) {

System.debug(e.getMessage());

}

return null;

}


 

**************

 Same problem occurs for Update

  • February 20, 2008
  • Like
  • 0
I have a picklist which have some leads. I want to send an AJAX request to show the details of the list when the user just clicks on any of the leads in the picklist. How do I do that?
I have seen some examples on dataTable and actionSupport but not able to figure out how do i do that with picklist? Any help will be appreciated.
How can i get distinct elements from the database? Does SOQL not provide something like unique or distinct?
public DomainCreationData[] getHardCodedData()
{
DomainCreationData[] datas = new DomainCreationData[]{};
DomainCreationData data = new DomainCreationData();
TestExtranet__c[] extranets = [Select Name__c,Extranet_Name__c,URL__c from TestExtranet__c];
for(TestExtranet__c test : extranets)
{
data.setNonUniqueName(test.Name__c);
data.setDomainName(test.Extranet_Name__c);
data.setUrl(test.URL__c);
datas.add(data);
}
return datas;
}

This for loop does not give me the data. If there are four records saved in the database it always give me the 4th record 4 times. That means I am always retreiving the nth record n number of times. Please help.
public DomainCreationData[] getHardCodedData()
{
DomainCreationData[] datas = new DomainCreationData[]{};
DomainCreationData data = new DomainCreationData();
TestExtranet__c[] extranets = [Select Name__c,Extranet_Name__c,URL__c from TestExtranet__c];
for(Integer i = 0; i < extranets.length; i++)
{
TestExtranet__c test = extranets.get(i);
data.setNonUniqueName(test.Name__c);
data.setDomainName(test.Extranet_Name__c);
data.setUrl(test.URL__c);
datas.add(data);
}
return datas;
}

Error: Compile Error: Initial term of field expression must be a concrete SObject: LIST:SOBJECT:TestExtranet__c at line 30 column 28
The line number 30 is :      for(Integer i = 0; i < extranets.length; i++)
I have created a custom object(ExtranetSF) using the standard flow( Go to objects-->Create an object-->Create fields and page layout and stuff)
Then I am trying to access that custom object from my visualforce controller. The following piece of code gives me error.It says that "Field is not writeable".

My question is how do i get past this problem??? Any help

ExtranetSF__c co = new ExtranetSF__c();
co.Name = data.getNonUniqueName();
co.Extranet_Name = data.getDomainName();
co.URL=data.getUrl();
insert co;