You need to sign in to do that
Don't have an account?
marys pinda
Use the value of a string as a type
Hi,
Is it possible to use the value of a string as a type?
How do I do this?
Thank you
Example:
String aaa = 'Case';
for(aaa a: (List<aaa>)database.query(stringQuery))
=
for(Case a: (List<Case>)database.query(stringQuery))
Is it possible to use the value of a string as a type?
How do I do this?
Thank you
Example:
String aaa = 'Case';
for(aaa a: (List<aaa>)database.query(stringQuery))
=
for(Case a: (List<Case>)database.query(stringQuery))
We can use the value of string as below:
String aaa = 'Case';
string query = 'Select Id from '+ aaa +' limit 10';
for(Sobject a: database.query(query))
{
System.debug('==='+a);
}
It is not possible to use value of string without typecasting .
Something like:
String aaa = 'Case';
database.query(aaa);
Thank you
Thank you!
CONTROLLER:
global class AAAACSV implements System.Schedulable {
public String mailSouhaite {get; set;}
public string caseTT {get; set;}
global void execute(SchedulableContext sc) {
planifier();
}
public void planifier(){
String query = caseTT;
String premier=query.substringAfter('select');
premier= premier.substringBefore('from');
string titre= premier+'\n';
string contenuCSV = titre;
String aaa = 'Case';
for(aaa a: (List<aaa>)database.query(caseTT))
{
string contenu = a.casenumber + ',' + a.subject+ ',' +a.Contact.Name+ ',' + a.status +'\n';
contenuCSV = contenuCSV + contenu ;
}
Messaging.EmailFileAttachment csvPJ = new Messaging.EmailFileAttachment();
blob csvBlob = Blob.valueOf(contenuCSV);
nomFichierCSV = 'cases_fermes_'+Date.today().format()+'.csv';
csvPJ.setFileName(nomFichierCSV);
csvPJ.setBody(csvBlob);
Messaging.SingleEmailMessage email =new Messaging.SingleEmailMessage();
String[] adressMail = new list<string> {mailSouhaite};
String subject = 'Rapport Cases Fermés CSV - '+Date.today().format();
email.setSubject(subject);
email.setToAddresses(adressMail);
email.setPlainTextBody('mail...............');
email.setFileAttachments(new Messaging.EmailFileAttachment[]{csvPJ});
Messaging.SendEmailResult [] envoyer = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
}
PAGE:
<apex:page controller="AAAACSV">
<style type="text/css">
.classeRequete { width: 600px; }
.classeMail { width: 400px; }
</style>
<apex:form >
<apex:PageBlock >
:::::::::: PARAMETRAGE :::::::::: <br /><br />
Mail..........: <apex:inputText styleClass="classeMail" value="{!mailSouhaite}"/><br /><br />
Requête : <apex:inputText styleClass="classeRequete" value="{!caseTT}"/><br /><br />
<apex:commandButton value="Valider" action="{!planifier}"/> <br/><br/>
<apex:commandButton value="Effacer"/> <br/><br/>
</apex:PageBlock>
</apex:form>
</apex:page>
I'm new at this language and it's very difficult.
Thank you
Another tip?