0

Trying to disable the Customize Application permission so that end users aren't able to customize the platform. The problem is that a visualforce page calls some apex code to export data to XML (business critial/before me) stops working when the permission is disabled. How can I modify the VF or APEX to make it work without the Customize Application permission?

Visualforce Page:

<apex:page controller="ETOExport" contentType="application/xml/#ETO__{!casenum}__{!TODAY()}.xml" cache="false" > 
    <apex:outputText value="{!xmlstr}"/>
</apex:page>

Apex Code:

public class ETOExport {
    public ApexPages.StandardController ctrl;
    public Id caseid{ get; set; }
    public string xmlstr{ get; set; }
    public String casenum{ get; set; }
    List<Case> cse = new List<Case>();
    
    public ETOExport() {        
        xmlstr=CreateXML();
    }

    public string CreateXML(){
        Id id = apexpages.currentpage().getparameters().get('id');
        casenum = [Select CaseNumber FROM Case WHERE ID=:id].CaseNumber;
        cse = [SELECT CaseNumber, Id, Statement_of_Work_1__c, 
                  (SELECT Quoted_Part_Number__c, Quoted_Part_Description__c, Product_Name_Text__c, Sale_Price_Each__c, Additional_Lead_Time_weeks__c, Weight__c, Install_Hours__c, Minimum_Quantity__c, Paint_Required__c
                   FROM ETOs__r)
               FROM Case
               WHERE Id=:id];
        Dom.Document doc = new DoM.Document();
        xmlstreamwriter x = new xmlstreamwriter();
        x.writeStartDocument('UTF-8', '1.0');
        x.writeStartElement(null, 'Case', null);
        for (Case c : cse) {
            //if (c.ETOs__r.size()>0){
                x.writeStartElement(null, 'CaseNo', null);
                x.writeCharacters(c.CaseNumber);
                x.writeEndElement();
                x.writeStartElement(null, 'SOW', null);
                x.writeCharacters(c.Statement_of_Work_1__c != null ? c.Statement_of_Work_1__c : '');
                x.writeEndElement();
                for (ETO__c eto: c.ETOs__r) {
                    x.writeStartElement(null, 'ETO', null);
                        x.writeStartElement(null, 'PartNo', null);
                            x.writeCharacters(eto.Quoted_Part_Number__c);
                        x.writeEndElement();
                        x.writeStartElement(null, 'Description', null);
                            x.writeCharacters(eto.Quoted_Part_Description__c);
                        x.writeEndElement();
                        x.writeStartElement(null, 'Product', null);
                            x.writeCharacters(eto.Product_Name_Text__c);
                        x.writeEndElement();
                        x.writeStartElement(null, 'UnitPrice', null);
                            x.writeCharacters((eto.Sale_Price_Each__c != null ? String.valueOf(eto.Sale_Price_Each__c) : '0'));
                        x.writeEndElement();
                        x.writeStartElement(null, 'AddlLeadTimeWks', null);
                          
  x.writeCharacters((eto.Additional_Lead_Time_weeks__c != null ? String.valueOf(eto.Additional_Lead_Time_weeks__c) : '0'));
                        x.writeEndElement();
                        x.writeStartElement(null, 'Weight', null);
                            x.writeCharacters((eto.Weight__c != null ? String.valueOf(eto.Weight__c) : '0'));
                        x.writeEndElement();
                        x.writeStartElement(null, 'IHR', null);
                            x.writeCharacters((eto.Install_Hours__c != null ? String.valueOf(eto.Install_Hours__c) : '0'));
                        x.writeEndElement();
                        x.writeStartElement(null, 'MinQty', null);
                            x.writeCharacters((eto.Minimum_Quantity__c != null ? String.valueOf(eto.Minimum_Quantity__c) : '0'));
                        x.writeEndElement();
                        x.writeStartElement(null, 'ColorReq', null);
                            x.writeCharacters((eto.Paint_Required__c == true ? '1' : '0'));
                        x.writeEndElement();
                    x.writeEndElement();
                }
            //}
        }
        x.writeEndElement();
        x.writeEndDocument();
        String xmlstr = x.getXmlString();
        x.close();
        doc.load(xmlstr);
        system.debug(xmlstr);
        //string xmldata = doc.toXmlString();
        //system.debug(xmldata);
        return xmlstr;
    }
}
1
  • Please edit your post to include more details about "stops working". Do you get an error message? Have you checked the debug log? Oct 3, 2022 at 18:00

1 Answer 1

0

It's not the Visualforce page or Apex, it's the profile permissions. Go to Setup > Visualforce Pages, find the page that's not working, click on Security, then add the proper profiles to the list of Enabled Profiles. Just to be safe, I'd go to the ETOExport class as well, and enable that class for the appropriate profiles. The reason why it works with Customize Application is because that permission designates users as System Administrators, and therefore they can run all Visualforce pages.

1
  • The permission was granted to the Apex class but wasn't for the Visual Force Page. After enabling the VF page and disabling the Customize Application permission, I was able to successfully download the file. Thank you so much for your help!
    – ramza8
    Oct 3, 2022 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .