function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhijeet Kumar 1Abhijeet Kumar 1 

Generating XML from APEX

Hi req as follows:-
Custom Setting :  Vacancy_Media_Mapping
 Custom setting having four fields :- VacancyMedianode, Type, Area and Logo:
                                                  1st record:- client logo, LOGO, CientLOgo, client logo url      
                                                   2nd record :- job video, VIDEO, jobdescription, job video url
                                                   3rd record :- Client video, MOREINFORMATION ,cient vidoe url

And we have three check boxes in the object field as follows:-
                                               1.Client Logo flag
                                                2. Client video flag
                                               3.job video flag

Req: whenever user make the Client Logo flag as true then xml from the custom setting client logo url must be present in the xml file.
Please help to arrange the necessary condition
Code as below:
Map :- Map<String,  Vacancy_Media_Mapping__c> vacancyMediaMapping = Vacancy_Media_Mapping__c.getAll();
       List<String> vacancyMedia = new List<String>();
        for(String vmName : vacancyMediaMapping.keySet()){
            vacancyMedia.add(vmName);
        }

XML generation :-
if(vacancyMediaMapping.size()>0){
                            for(integer i=0;i<vacancyMediaMapping.size();i++){
                                if(objJob.Client_Logo_flag__c=true){
                                   xmlW.writeStartElement(null,'Path',null);
                                   xmlW.writeCharacters(vacancyMediaMapping.get(vacancyMedia[i]).Path__c);
                                   xmlW.writeEndElement();
                                }
Currently it is giving me all the three url, from above code i want to fetch only client logo url,..
Deepali KulshresthaDeepali Kulshrestha
Hi Abhijeet,

As we all know that XML is one of the best methods to send or receive files over the internet. And to provide us support for parsing and creating XML files. In one of my previous blogs, I have taught you how to parse XML files in apex.

Please refer to the following links as they may be helpful in solving your problem:

- https://developer.salesforce.com/forums/?id=906F000000093KBIAY
- https://webkul.com/blog/how-to-generate-xml-file-in-apex/


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
Abhijeet Kumar 1Abhijeet Kumar 1
Thanks I got  the solution!!