• lammy
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

I am having difficulty with a visualforce page recognizing an object variable on an extension. I have a feeling the problem is with my getter method, but I am at a loss for how to fix it. Attached is my controller and page...

 

Page:
<apex:page standardController="Account" extensions="RSOLeaseExtension" tabStyle="Lease__c">
<apex:sectionHeader title="New Lease Request" subtitle="Lease Form"/>
	<apex:pageMessages />
	 <apex:form >          
		<apex:pageBlock title="Lease Form" id="Lease">
			 <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}" />
                <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
            </apex:pageBlockButtons>	
            
			<apex:pageBlockSection title="Account Details">
					<apex:inputField value="{!ls.DBA_Name__c}"/>
					<apex:outputField value="{!ls.Merchant_Number__c}"/>					
					<apex:inputField required="true" value="{!ls.Request_Type__c}">
                  <apex:actionSupport event="onchange"  rerender="Lease" />				
                </apex:inputField> 					
					 
			</apex:pageBlockSection> 
      </apex:pageBlock>
			</apex:form>
</apex:page>

Controller:
public with sharing class RSOLeaseExtension {
	private final Account account;
    
    private Account acc = null;
    private Lease__c ls = new Lease__c(); 
    public String reType = getRequestType();
       
    public RSOLeaseExtension(ApexPages.StandardController controller) {
        this.account = (Account)controller.getRecord();
         
        if (this.account.Id != null && acc == null) {
            acc = [SELECT Id, 
            	Bank_Lookup__c,Bank_Lookup__r.Name,
                            OwnerId,Owner.Phone,Owner.Email,Merchant_MID__c,Name
                    FROM Account
                   WHERE Id = :this.account.Id];
        
     	ls.Merchant_Number__c = acc.Merchant_MID__c;
       	ls.DBA_Name__c = acc.Id;
        
        ls.Bank_Alliance_Name__c = acc.Bank_Lookup__r.Name;
        
        }  
    }
    
    public Lease__c getLease() {
    	return ls;
    } 
   
    public String getRequestType() {
        return ls.Request_Type__c;
    }  
    
    public PageReference save() {
        PageReference savePage = null;
        Savepoint sp = null;
        RecordType lsRec = [Select Id,Name from RecordType where Name like 'Lease%' and SobjectType = 'Lease__c'];
        try {
            sp = Database.setSavepoint();
            
            insert ls;

            savePage = new PageReference('/' + ls.Id);
            savePage.setRedirect(true);
            
        } catch (System.DmlException de) {
            ApexPages.addMessages(de);
            Database.rollback(sp);
        }
        return savePage;
    }
    public PageReference cancel() {
        PageReference cancelPage = null;
        
        if (account.Id != null) {
            cancelPage = new PageReference('/' + account.Id);
        } else {
            cancelPage = new PageReference('/001/o');
        }
        cancelPage.setRedirect(true);
        return cancelPage;
    }

}

 Thank you for any help!!!!

  • July 07, 2011
  • Like
  • 0

I am looking for some experience and insight on a page that I have been asked to create. The page will be used by delegated admins to manage queues (such as lead queues, case queues) in their hierarchical structure. I am not worried about the page details as much as access.

 

I know test classes give the option to set a user to run as and the dashboards are the same way. Is this possible to accomplish in a custom controller? It is preferable to do this rather that turn on the profile settings.

 

Thanks.

  • May 04, 2011
  • Like
  • 0

I have a C# app that is successfully returning and writing the zip file with the Profiles to a folder, but even thought I am setting the objects I would like to retrieve the permissions for, it is only returning the following:

 

<?xml version="1.0" encoding="UTF-8"?> <Profile xmlns="http://soap.sforce.com/2006/04/metadata">     <userLicense>Salesforce</userLicense> </Profile>

 

I should be seeing custom objects and the profile permissions related to these objects.

 

The reason I need to use the C# app is because in the Force.com IDE, only unmanaged objects can be retrieved, and then viewed in the Profile metadata. In the C# application, all objects, whether managed or unmanaged are returned. I've tested this out using the CustomObject and have returned all custom objects in a zip file.

 

So here is a portion my code. Please let me know if there are any questions. Would like to get this figured out. I'm not that Familiar with Java, but if you have some Java code as an example, that would also be very helpful.

 

       

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.IO;
using System.IO.Compression;
using System.Text;
using System.Windows.Forms;
using SalesforceMetaDataApplication.WebReference;
using SalesforceMetaDataApplication.SFMetadata;
using SForceOfficeToolkitLib4;


namespace SalesforceMetaDataApplication
{
    public partial class MetaInfo : Form
    {

        public const double API_VERSION = 23.0;

        private SalesforceMetaDataApplication.WebReference.SforceService sf { get; set; }
        private SalesforceMetaDataApplication.WebReference.LoginResult lr { get; set; }
        private GetUserInfoResult userInfo { get; set; }

        private MetadataService metaService { get; set; }
        private List<FileProperties> lstFp { get; set; }
        private RetrieveResult result { get; set; }

        private Dictionary<String, SalesforceMetaDataApplication.WebReference.Profile> dictProfile 
            = new Dictionary<String, SalesforceMetaDataApplication.WebReference.Profile>();
        private Dictionary<String, SalesforceMetaDataApplication.WebReference.User> dictUser
            = new Dictionary<String, SalesforceMetaDataApplication.WebReference.User>();

        private List<String> lstSObjects = new List<String>();
        private List<CustomField> lstFields = new List<CustomField>();

        // Initialize the class with parameters from SFLogin. Get the Profiles, Users, and all SObjects in the org.
        public MetaInfo(SforceService sfService, MetadataService ms, LoginResult lResult, GetUserInfoResult uInfo)
        {
            InitializeComponent();
            
            sf = new SalesforceMetaDataApplication.WebReference.SforceService();
            lr = new SalesforceMetaDataApplication.WebReference.LoginResult();
            metaService = new MetadataService();
            userInfo = new GetUserInfoResult();

            this.sf = sfService;
            this.lr = lResult;
            this.userInfo = uInfo;

            this.metaService = ms;

            getProfile();
            getUser();
            retrieveSObjects();
        }

        // Retrieve all SObjects
        private void retrieveSObjects()
        {
            try 
            {
                DescribeGlobalResult dgr = sf.describeGlobal();

                DescribeGlobalSObjectResult[] dgsr = dgr.sobjects;
                foreach (DescribeGlobalSObjectResult d in dgr.sobjects)
                {
                    lstSObjects.Add(d.name);
                }
            } 
            catch (Exception e)
            {
                MessageBox.Show("Could not retrieve the Sobjects from Salesforce. " + e.Message);
            }
        }

        // Package Types
        private void profileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            String strFolder = "Profile";
            String pckgType = "Profile";

            List<ProfileObjectPermissions> lstProfObjPerm = new List<ProfileObjectPermissions>();
            List<PackageTypeMembers> lstPtm = new List<PackageTypeMembers>();
            foreach(String s in lstSObjects) 
            {
                SFMetadata.ProfileObjectPermissions profObjPerm = new SFMetadata.ProfileObjectPermissions();
                profObjPerm.@object = s;
                lstProfObjPerm.Add(profObjPerm);
                
                SFMetadata.PackageTypeMembers objPckTypMembers = new SFMetadata.PackageTypeMembers();
                List<String> lstMembers = new List<String>();
                lstMembers.Add(s);
                objPckTypMembers.members = lstMembers.ToArray();
                lstPtm.Add(objPckTypMembers);

            }

            Package pck = new Package();
            pck.types = lstPtm.ToArray();

            SFMetadata.Profile objProfile = new SFMetadata.Profile();

            objProfile.objectPermissions = lstProfObjPerm.ToArray();

            // Call the methods to retrieve the profiles and zip file
            String[] profileFiles = listPackages(strFolder, pckgType);
            retrievePackages(profileFiles, pckgType, pck);

            MessageBox.Show("Extraction Complete.");
        }


        private String[] listPackages(String strFolder, String strType) {
            // can't use wildcards with reports, so need to fetch the list
            // of ReportFolders first, then fetch all the reports in
            // each folder.
            ListMetadataQuery q = new ListMetadataQuery();
            q.type = strFolder;

            FileProperties[] fp = metaService.listMetadata(new ListMetadataQuery[] { q }, API_VERSION);

            if (fp == null)
            {
                Console.WriteLine("No profile folders returned");
                return new String[0];
            }

            List<String> packageFiles = new List<String>();
            q.type = strType;
            foreach (FileProperties p in fp)
            {
                q.folder = p.fullName;
                // listMetadata can take more than one item at a time
                // left as an exercise for the reader to batch up these calls.
                FileProperties[] rps = metaService.listMetadata(new ListMetadataQuery[] { q }, API_VERSION);
                if (fp == null) continue;
                foreach (FileProperties rp in rps)
                {
                    Console.WriteLine("{0}", rp.fileName);
                    packageFiles.Add(rp.fullName);
                }
            }
            return packageFiles.ToArray();
        }

        // Overload methods to retrieve the different package types and write them to disk.
        // TODO: compress these methods into more reusable methods.
        private void retrievePackages(String[] packageFiles, String strMetaName, Package objPackage) 
        {
            // build up an unpackaged retrieve request for the list of reports.
            RetrieveRequest r = new RetrieveRequest();
            r.apiVersion = API_VERSION;
            //r.unpackaged = new Package();
            r.unpackaged = objPackage;

            PackageTypeMembers m = new PackageTypeMembers();
            m.name = strMetaName;
            m.members = packageFiles;
            r.unpackaged.types = new PackageTypeMembers[] { m };

            // start the retrieve request
            AsyncResult ar = metaService.retrieve(r);

            // wait for it to complete, sleeping as necassary.
            while (!ar.done)
            {
                System.Threading.Thread.Sleep(1000);
                ar = metaService.checkStatus(new String[] { ar.id })[0];
            }

            // did it work ?
            if (ar.state == AsyncRequestState.Error)
                Console.WriteLine("{0} {1}", ar.statusCode, ar.message);
            else
            {
                // now actually go get the results 
                RetrieveResult rr = metaService.checkRetrieveStatus(ar.id);
                if (rr.messages != null)
                    foreach (RetrieveMessage rm in rr.messages)
                        Console.WriteLine("{0} : {1}", rm.fileName, rm.problem);

                // write the zipFile out to a disk file.
                using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Temp\\" + strMetaName + ".zip", System.IO.FileMode.Create))
                    fs.Write(rr.zipFile, 0, rr.zipFile.Length);
            }
        }

        private void retrievePackages(String[] packageFiles, String strMetaName)
        {
            // build up an unpackaged retrieve request for the list of reports.
            RetrieveRequest r = new RetrieveRequest();
            r.apiVersion = API_VERSION;
            r.unpackaged = new Package();

            PackageTypeMembers m = new PackageTypeMembers();
            m.name = strMetaName;
            m.members = packageFiles;
            r.unpackaged.types = new PackageTypeMembers[] { m };

            // start the retrieve request
            AsyncResult ar = metaService.retrieve(r);

            // wait for it to complete, sleeping as necassary.
            while (!ar.done)
            {
                System.Threading.Thread.Sleep(1000);
                ar = metaService.checkStatus(new String[] { ar.id })[0];
            }

            // did it work ?
            if (ar.state == AsyncRequestState.Error)
                Console.WriteLine("{0} {1}", ar.statusCode, ar.message);
            else
            {
                // now actually go get the results 
                RetrieveResult rr = metaService.checkRetrieveStatus(ar.id);
                if (rr.messages != null)
                    foreach (RetrieveMessage rm in rr.messages)
                        Console.WriteLine("{0} : {1}", rm.fileName, rm.problem);

                // write the zipFile out to a disk file.
                using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Temp\\" + strMetaName + ".zip", System.IO.FileMode.Create))
                    fs.Write(rr.zipFile, 0, rr.zipFile.Length);
            }
        }
    }
}

 

I am having difficulty with a visualforce page recognizing an object variable on an extension. I have a feeling the problem is with my getter method, but I am at a loss for how to fix it. Attached is my controller and page...

 

Page:
<apex:page standardController="Account" extensions="RSOLeaseExtension" tabStyle="Lease__c">
<apex:sectionHeader title="New Lease Request" subtitle="Lease Form"/>
	<apex:pageMessages />
	 <apex:form >          
		<apex:pageBlock title="Lease Form" id="Lease">
			 <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}" />
                <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
            </apex:pageBlockButtons>	
            
			<apex:pageBlockSection title="Account Details">
					<apex:inputField value="{!ls.DBA_Name__c}"/>
					<apex:outputField value="{!ls.Merchant_Number__c}"/>					
					<apex:inputField required="true" value="{!ls.Request_Type__c}">
                  <apex:actionSupport event="onchange"  rerender="Lease" />				
                </apex:inputField> 					
					 
			</apex:pageBlockSection> 
      </apex:pageBlock>
			</apex:form>
</apex:page>

Controller:
public with sharing class RSOLeaseExtension {
	private final Account account;
    
    private Account acc = null;
    private Lease__c ls = new Lease__c(); 
    public String reType = getRequestType();
       
    public RSOLeaseExtension(ApexPages.StandardController controller) {
        this.account = (Account)controller.getRecord();
         
        if (this.account.Id != null && acc == null) {
            acc = [SELECT Id, 
            	Bank_Lookup__c,Bank_Lookup__r.Name,
                            OwnerId,Owner.Phone,Owner.Email,Merchant_MID__c,Name
                    FROM Account
                   WHERE Id = :this.account.Id];
        
     	ls.Merchant_Number__c = acc.Merchant_MID__c;
       	ls.DBA_Name__c = acc.Id;
        
        ls.Bank_Alliance_Name__c = acc.Bank_Lookup__r.Name;
        
        }  
    }
    
    public Lease__c getLease() {
    	return ls;
    } 
   
    public String getRequestType() {
        return ls.Request_Type__c;
    }  
    
    public PageReference save() {
        PageReference savePage = null;
        Savepoint sp = null;
        RecordType lsRec = [Select Id,Name from RecordType where Name like 'Lease%' and SobjectType = 'Lease__c'];
        try {
            sp = Database.setSavepoint();
            
            insert ls;

            savePage = new PageReference('/' + ls.Id);
            savePage.setRedirect(true);
            
        } catch (System.DmlException de) {
            ApexPages.addMessages(de);
            Database.rollback(sp);
        }
        return savePage;
    }
    public PageReference cancel() {
        PageReference cancelPage = null;
        
        if (account.Id != null) {
            cancelPage = new PageReference('/' + account.Id);
        } else {
            cancelPage = new PageReference('/001/o');
        }
        cancelPage.setRedirect(true);
        return cancelPage;
    }

}

 Thank you for any help!!!!

  • July 07, 2011
  • Like
  • 0

I am looking for some experience and insight on a page that I have been asked to create. The page will be used by delegated admins to manage queues (such as lead queues, case queues) in their hierarchical structure. I am not worried about the page details as much as access.

 

I know test classes give the option to set a user to run as and the dashboards are the same way. Is this possible to accomplish in a custom controller? It is preferable to do this rather that turn on the profile settings.

 

Thanks.

  • May 04, 2011
  • Like
  • 0