• Yasa Kusuma 3
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies
I created a static resource, a (.layout file), and I need to grab it from inside an Apex class

Here is my code so far

Http h = new Http(); 
        HttpRequest request = new HttpRequest(); 
        String fileContent = '';
        
        String layoutName = 'DealcAssetManagementLayout';
        
        List<StaticResource> resourceList= [SELECT Name, NamespacePrefix, SystemModStamp FROM StaticResource WHERE Name = :layoutName];
        
        // Checking if the result is returned or not
        if(resourceList.size() == 1)
        {
            
            // Getting namespace
            String namespace = resourceList[0].NamespacePrefix;
                        
            // Resource URL
            layoutName = 'https://c.na16.visual.force.com/resource/' + resourceList[0].SystemModStamp.getTime() + '/' + (namespace != null && namespace != '' ? namespace + '__' : '') + layoutName;        
        
            //System.debug(layoutName);
            
            request.setEndpoint(layoutName);
            request.setMethod('GET'); 
            request.setHeader('Cookie','sid='+UserInfo.getSessionId()+';'); 
            request.setTimeout(60000); 
            HttpResponse response = h.send(request);             
            
            //System.debug(response.getStatusCode());
            
            if(response.getStatusCode() == 302)
            {
                String loc = response.getHeader('Location'); // get location of the redirect
                
                System.debug(loc);
                
                request.setEndpoint(loc);
                request.setMethod('GET'); 
                request.setHeader('Cookie','sid='+UserInfo.getSessionId()+';'); 
                request.setTimeout(60000); 
                response = h.send(request);   
            }

            System.debug(response.getStatusCode());
            
             if(response.getStatusCode() == 302)
            {
                String loc = response.getHeader('Location'); // get location of the redirect
                
                System.debug(loc);
                
                request.setEndpoint(loc);
                request.setMethod('GET'); 
                request.setHeader('Cookie','sid='+UserInfo.getSessionId()+';'); 
                request.setTimeout(60000); 
                response = h.send(request);   
            }

            System.debug(response.getStatusCode());
            
            if(response.getStatusCode() == 200)
            {           
                fileContent = response.getBody();            
            }

The problem is I keep getting redirected (302) - what am I doing wrong here...any ideas?

Thanks in advance!
For example, I have 'Test__c-Test Layout' - I would like to create a copy 'Test__c-Copy Test Layout' using internal Salesforce code. Is this possible?
 
I am attempting to grab a page layout from an installed package, then update the current page layout with internal (apex) code.

Like what this gentleman is doing http://andyinthecloud.com/2013/12/24/updating-layouts-in-apex/  - the difference is he's just reading a layout then updating it. I want to read a layout from a managed package then blasting away the old one. I know there is a way to do this with external code and metadata APIs, but we are looking to do it completely with internal code.

Thanks in advance.
 
We have a packaged solution - and page layouts do not update automatically, which makes sense - but we are looking for options to force an update. One theory is to create code that an admin can run that creates a new page layout, imports the xml from the packaged solution, and assigns it to a user profile. Sounds a tad far fetched, but let me put it out there, maybe someone has a better idea?   
I created a static resource, a (.layout file), and I need to grab it from inside an Apex class

Here is my code so far

Http h = new Http(); 
        HttpRequest request = new HttpRequest(); 
        String fileContent = '';
        
        String layoutName = 'DealcAssetManagementLayout';
        
        List<StaticResource> resourceList= [SELECT Name, NamespacePrefix, SystemModStamp FROM StaticResource WHERE Name = :layoutName];
        
        // Checking if the result is returned or not
        if(resourceList.size() == 1)
        {
            
            // Getting namespace
            String namespace = resourceList[0].NamespacePrefix;
                        
            // Resource URL
            layoutName = 'https://c.na16.visual.force.com/resource/' + resourceList[0].SystemModStamp.getTime() + '/' + (namespace != null && namespace != '' ? namespace + '__' : '') + layoutName;        
        
            //System.debug(layoutName);
            
            request.setEndpoint(layoutName);
            request.setMethod('GET'); 
            request.setHeader('Cookie','sid='+UserInfo.getSessionId()+';'); 
            request.setTimeout(60000); 
            HttpResponse response = h.send(request);             
            
            //System.debug(response.getStatusCode());
            
            if(response.getStatusCode() == 302)
            {
                String loc = response.getHeader('Location'); // get location of the redirect
                
                System.debug(loc);
                
                request.setEndpoint(loc);
                request.setMethod('GET'); 
                request.setHeader('Cookie','sid='+UserInfo.getSessionId()+';'); 
                request.setTimeout(60000); 
                response = h.send(request);   
            }

            System.debug(response.getStatusCode());
            
             if(response.getStatusCode() == 302)
            {
                String loc = response.getHeader('Location'); // get location of the redirect
                
                System.debug(loc);
                
                request.setEndpoint(loc);
                request.setMethod('GET'); 
                request.setHeader('Cookie','sid='+UserInfo.getSessionId()+';'); 
                request.setTimeout(60000); 
                response = h.send(request);   
            }

            System.debug(response.getStatusCode());
            
            if(response.getStatusCode() == 200)
            {           
                fileContent = response.getBody();            
            }

The problem is I keep getting redirected (302) - what am I doing wrong here...any ideas?

Thanks in advance!
For example, I have 'Test__c-Test Layout' - I would like to create a copy 'Test__c-Copy Test Layout' using internal Salesforce code. Is this possible?
 
We have a packaged solution - and page layouts do not update automatically, which makes sense - but we are looking for options to force an update. One theory is to create code that an admin can run that creates a new page layout, imports the xml from the packaged solution, and assigns it to a user profile. Sounds a tad far fetched, but let me put it out there, maybe someone has a better idea?   
Hi all.  Quick question: is there any way to access the content of a static resource from Apex code?

I know how to access the resource inside VF markup (URLFOR, $Resource); what I'm trying to do here is get at the contents of an XML or text file resource from within an Apex method.

I couldn't find an API for doing this.  The only thing I could think of was to do an HTTP callout, but that seems to give me a 404 no matter what I do; I gather there is a proxy back there that has a different view of the world than my browser does.

Is there a better way to go about this?

Thanks very much,
-p

  • August 29, 2008
  • Like
  • 0