You need to sign in to do that
Don't have an account?

Split String
Is it possible to pick values between SELECT and FROM (String) and use the code in Apex?
Example: the user informe = SELECT casenumber,subject,Contact.Name,status FROM Case WHERE ClosedDate=TODAY
The Apex code uses only: casenumber, subject, Contact.Name, status to build a CSV::::
...
string titre= 'casenumber,subject,Contact.Name,status'+'\n';
...
for(Case a: (List<case>)database.query(caseTT) )
{
string contenu = a.casenumber + ',' + a.subject+ ',' +a.Contact.Name+ ',' + a.status +'\n';
contenuCSV = contenuCSV + contenu ;
}
....
Thank you!!!
Example: the user informe = SELECT casenumber,subject,Contact.Name,status FROM Case WHERE ClosedDate=TODAY
The Apex code uses only: casenumber, subject, Contact.Name, status to build a CSV::::
...
string titre= 'casenumber,subject,Contact.Name,status'+'\n';
...
for(Case a: (List<case>)database.query(caseTT) )
{
string contenu = a.casenumber + ',' + a.subject+ ',' +a.Contact.Name+ ',' + a.status +'\n';
contenuCSV = contenuCSV + contenu ;
}
....
Thank you!!!
maybe you can use the get() method for Case records. Something like:
List<Case> listCases = database.query(caseTT);
String[] listFields = calculateListFields(caseTT); //calculateListFields would be a method returning String[], where each element will be a field API name:
//casenumber, subject, contact.name....
String contenuCSV = '';
for(Integer i = 0; i<listCases.size(); i++){
String csvRow = null;
for(String s : listFields){ //Build a row of the csv file
if(csvRow == null){
csvRow = listCases[i].get(s);
}
else{
csvRow += ',' + listCases[i].get(s);
}
}
csvRow += '\n';
contenuCSV += csvRow;
}
Best regards,
Gonzalo.
You can split by using
substringAfter and substringBefore methods.
eg:
string query = 'SELECT casenumber,subject,Contact.Name,status FROM Case WHERE ClosedDate=TODAY';
string First =query.substringAfter('SELECT'); // SELECT is caps because its case- sensitive
First = First.substringBefore('WHERE'); // WHEREis caps because its case- sensitive
system.debug('~~~~~~~~'+First);
https://developer.salesforce.com/releases/release/Winter13/New+String+Methods
https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/substring-after
Mark this as solution if you got a answer.
Thanks.
I will try...
Any tips?
Thank you
You can use substringAfter and substringBefore methods as Praveen mentioned.
They are a lot easier to use and no need to maintain expressions.
Thanks
for(Case a: (List<case>)database.query(caseTT) )
{
string contenu = a. casenumber + ',' + a.subject+ ',' +a.Contact.Name+ ',' + a.s tatus +'\n';
contenuCSV = contenuCSV + contenu ;
}
Thank you!
If I understood question correctly, my answer is
String fieldValues = '';
SObjectType objectType = Schema.getGlobalDescribe().get(case);
DescribeSObjectResult objDesc = objectType.getDescribe();
Map<String, SObjectField> fields = objDesc.fields.getMap();
Set<String> fieldSet = fields.keySet();
for(String f : fieldSet)
{
fieldValues += f +',';
}
if(fieldValues.endsWith(','))
fieldValues= fieldValues.substring(0,fieldValues.length()-1);
// here field values will hole the all the field in Object Case.
Thanks
I tried, but there is a error:
Attempt to de-reference a null object
Error is in expression '{!planifier}' in component <apex:commandButton> in page
The object name should be in single quotes and if its a custom object you need add __c at the end.
Eg.
String contenuCSV = '';
SObjectType objectType = Schema.getGlobalDescribe().get('caseTT__c');
DescribeSObjectResult objDesc = objectType.getDescribe();
Map<String, SObjectField> fields = objDesc.fields.getMap();
Set<String> fieldSet = fields.keySet();
for(String f : fieldSet)
{
contenuCSV += f +',';
}
if(contenuCSV .endsWith(','))
contenuCSV = contenuCSV.substring(0,contenuCSV .length()-1);
Mark this as solution if you got a answer.
Thanks.
Praveen Murugesan
Attempt to de-reference a null object
Error is in expression '{!planifier}' in component <apex:commandButton> in page
CLASS APEX
PAGE VISUALFORCE
<apex:page controller="AAAExporterCSV3">
<apex:form >
<apex:PageBlock >
:::::::::: PARAMETER :::::::::: <br /><br />
Mail :<apex:inputText value="{!mailSouhaite}"/><br /><br />
Requête :<apex:inputText value="{!caseTT}"/><br /><br />
<apex:commandButton value="Valider" action="{!planifier}"/> <br/><br/>
<apex:commandButton value="Effacer"/> <br/><br/>
</apex:PageBlock>
</apex:form>
</apex:page>
Thank you
I think the error is coming from some other place,
I have checked through developer console with account object.
String contenuCSV = '';
SObjectType objectType = Schema.getGlobalDescribe().get('Account');
DescribeSObjectResult objDesc = objectType.getDescribe();
Map<String, SObjectField> fields = objDesc.fields.getMap();
Set<String> fieldSet = fields.keySet();
for(String f : fieldSet)
{
contenuCSV += f +',';
}
if(contenuCSV .endsWith(','))
contenuCSV = contenuCSV.substring(0,contenuCSV .length()-1);
system.debug('~~~~~~~~'+contenuCSV);
Its worked fine.
Thanks.
Praveen Murugesan
I'm trying to figure out!
Thank you
for (Case a: (<case> List) database.query (caseTT))
{
a.casenumber string contenu = + ',' + a.subject + ',' + a.Contact.Name + ',' + a.status + '\ n';
contenuCSV = contenuCSV + contenu;
}
something like:
for(ValueInformedInputTexVisualforcePage a: (List<ValueInformedInputTextVisualforcePage>)database.query(caseTT) )
{
string contenu = a.ValueInformedInputTexVisualforcePage + ',' + a.ValueInformedInputTexVisualforcePage + ',' +a.ValueInformedInputTexVisualforcePage+ ',' + a.ValueInformedInputTexVisualforcePage +'\n';
contenuCSV = contenuCSV + contenu ;
}
Thank you!
String contenuCSV = '';
SObjectType objectType = Schema.getGlobalDescribe().get('Account');
DescribeSObjectResult objDesc = objectType.getDescribe();
Map<String, SObjectField> fields = objDesc.fields.getMap();
Set<String> fieldSet = fields.keySet();
for(String f : fieldSet)
{
contenuCSV += f +',';
}
if(contenuCSV .endsWith(','))
contenuCSV = contenuCSV.substring(0,contenuCSV .length()-1);
Messaging.EmailFileAttachment csvPJ = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(contenuCSV);
string csvNom = 'cases_fermes.csv';
csvPJ.setFileName(csvNom);
csvPJ.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] adressMail = new list<string> {'ppraveenm@gmail.com'};
String subject = 'CSV';
email.setSubject(subject);
email.setToAddresses( adressMail );
email.setPlainTextBody('mail .....');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvPJ});
Messaging.SendEmailResult [] envoyer = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
I have tested this code with developer console and i have received mail. if you see here mail address is manually entered.
So I think the issue is on public String mailSouhaite {get; set;}
public string caseTT {get; set;} pls check this.
I need a Visualforce page to get the request from the input text (caseTT).
Where will you inform your request to use within Apex code?
Thank you!!!
Could you pls mail me your code. both page and controller.
my mail id is ppraveenm@gmail.com
Thank you...