• Salesforce Solutions
  • NEWBIE
  • 35 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 8
    Replies

Greetings!

 

I have my page for upload files but i want to restrict the file type only for PDF or ZIP 

 

i have in code: 

 

<apex:inputFile accept=".zip,.pdf*" value="{!attach.body}" filename="{!attach.name}" required="True"/>

 

But on Iexplorer, Mozilla, Chrome and safari i can upload any type of files.

 

Thank you so much!

Here is a simple Visualforce page controller, declared "with sharing", that queries for all attachments.

 

public with sharing class zTest2Controller {
 
    public List<Attachment> atms{
        get {
            if (atms == null) {
                atms = [SELECT ID, Name, BodyLength, ContentType, CreatedById,
                 CreatedDate, IsDeleted, IsPrivate,LastModifiedById,LastModifiedDate,OwnerId,Owner.Name,
                 ParentId, Parent.Name FROM Attachment LIMIT 2000];
            }
            return atms;
         }
    private set;
    }
    
 }

 

Here is a page that uses this controller:

 

<apex:page controller="zTest2Controller">

    <apex:pageBlock >
        <apex:pageBlockTable value="{!atms}" var="atm">  
            <apex:column headerValue="ID">  
              {!atm.ID}  
            </apex:column>  
            <apex:column headerValue="Name">  
               <apex:outputLink value="/{!atm.ID}">{!atm.Name}</apex:outputLink>
                
            </apex:column>  
            <apex:column headerValue="Parent Name">  
            <apex:outputLink value="/{!atm.ParentID}">{!atm.Parent.Name}</apex:outputLink>
            </apex:column>  
            <apex:column headerValue="Owner Name">  
              {!atm.Owner.Name}  
            </apex:column>  
        </apex:pageBlockTable> 
        
        <apex:outputText >{!atms.size} records</apex:outputText>  
    </apex:pageBlock>
</apex:page>

 

 

When I access this page as a test user who cannot see all of the attachments, they are still all displayed.


In one case I created a Test Profile that does not allow a user to see Opportunities, and a user with this profile still gets the attachments on Opportunities (even though the user cannot access the Opportunities or the attachments).
In another case, the user is a Platform user, but still is returned attachments that are not exposed to Platform users.

Is this expected behavior???

The documentation implies in one place that the use of "with sharing" will prevent these kinds of data leaks:
http://www.salesforce.com/us/developer/docs/apexcode/Content/pages_security_tips_data_access_control.htm

But in another places it seems to say that "with sharing" only enforces sharing rules, not permission sets or user profiles:

 

"Enforcing sharing rules by using the with sharing keyword doesn’t enforce the user's permissions and field-level security. Apex code always has access to all fields and objects in an organization, ensuring that code won’t fail to run because of hidden fields or objects for a user."

 

 

 

 

Facing the issue "Too many SOQL queries: 101" at the highlighted line in the following code :

 

public with sharing class AccountTriggerHandler {
     
    private boolean m_isExecuting = false;
    private integer BatchSize = 0;
    public static boolean isDeletedByTrigger = false;
    public set<Id> recordTypeSet = new set<Id>();
    public AccountTriggerHandler(boolean isExecuting, integer size){
        m_isExecuting = isExecuting;
        BatchSize = size;
        for(RecordType rt : [Select Id, DeveloperName From RecordType Where DeveloperName Like '%Ukraine%' And SobjectType='Account']){
            recordTypeSet.add(rt.Id);
        }
    }
    
    public void OnAfterInsert(List<Account> newObjects){
         createNewContacts(newObjects);
    }

    private void createNewContacts(list<Account> accountList){
        /*set<Id> recordTypeSet = new set<Id>();
        for(RecordType rt : [Select Id, DeveloperName From RecordType Where DeveloperName Like '%Ukraine%' And SobjectType='Account']){
            recordTypeSet.add(rt.Id);
        }*/
        list<Contact> contactsToBeInserted = new list<Contact>();
        for (Account acc : accountList){
            if(recordTypeSet.contains(acc.RecordTypeId))
              contactsToBeInserted.add(new Contact (AccountId=acc.Id, LastName= acc.Name, Position__c = 'Virtual',Country__c=acc.Base__Country__c,City__c = acc.City__c));
        }
        if(contactsToBeInserted.size()>0)
           insert contactsToBeInserted;
    }
    
    public void OnAfterUpdate(map<Id, Account> newObjects, map<Id, Account> oldObjects){        
         updateContacts(newObjects, oldObjects);
    }
    
    private void updateContacts(map<Id, Account> accountNew, map<Id, Account> accountOld){
        
        /*List<RecordType> rectype = new list<RecordType>();
        set<Id> recordTypeSet = new set<Id>();
        rectype = [Select Id, DeveloperName From RecordType Where DeveloperName Like '%Ukraine%' And SobjectType='Account'];
        for(RecordType rt : rectype ){
            recordTypeSet.add(rt.Id);
        }*/
        
        set<Id> accountsWithNameChanges = new set<Id>();
        for (Id key : accountNew.keySet()){
            if(recordTypeSet.contains(accountNew.get(key).RecordTypeId)){
               if(accountOld.get(key).Name <> accountNew.get(key).Name){
                  accountsWithNameChanges.add(key);
               }
            }
        }
        
        list<Contact> contactsToBeUpdated = new list<Contact>();
        for(Contact con : [Select id, LastName,AccountId
                           From Contact 
                           Where AccountId IN :accountsWithNameChanges 
                            And Position__c = 'Virtual']){
            con.LastName = accountNew.get(con.AccountId).Name;
            contactsToBeUpdated.add(con);
        }
        if(contactsToBeUpdated.size() > 0)
            update contactsToBeUpdated;
    }
    
    public void OnBeforeDelete(map<Id, Account> oldObjects){
        deleteVirtualContacts(oldObjects);
    }
    
    private void deleteVirtualContacts(map<Id, Account> accountOld){
        isDeletedByTrigger = true;
        list<Contact> contactsToBeDeleted = [Select Id From Contact Where AccountId IN :accountOld.keySet() and Position__c = 'Virtual'];
        if(contactsToBeDeleted.size()>0)
            delete contactsToBeDeleted;         
    }
}

 

Please advice how to solve this issue.

 

Hi all,

 

How to Restrict pages(pages are cms force app pages) particular user when user long into site. we have 10 pages and 2 user, 1st user login to site, 1st user visible only 5 pages and 2nd user visible only 4 page. Is it possible.

 

Thanks

I want to add a custom button to a FeedItem of type "ContentPost" before insert, to capture the file by cliking that button. is it possible?

please suggest if any other way to do this...

please help....

Hi

 

            I was facing a telephonic round of an interview and the interviewer had asked me this question.. I tried to ask people working for over 2 years on salesforce and a team Lead as well but couldn't find the answer.. So here I am.. where I've always got the help, when looked for.. So here Is the Question

 

Int: can we  use use Multiple extensions?

Me: Yes, we can.

Int: we have three extensions ext1, ext2, ext3.. and all of them have the method Method1.. and I call this method  in a VFPage whose method will be called..

Me: The one which is on he left most side.

Int: I want to call the Method of Ext2/Ext3.. How will I do so?

Me: Numb!! Job Gone!! Me yet Jobless..  :(

 

 

Greetings!

 

I have my page for upload files but i want to restrict the file type only for PDF or ZIP 

 

i have in code: 

 

<apex:inputFile accept=".zip,.pdf*" value="{!attach.body}" filename="{!attach.name}" required="True"/>

 

But on Iexplorer, Mozilla, Chrome and safari i can upload any type of files.

 

Thank you so much!

Hi,

 

Today I encountered a problem that I can't explain:

 

I got a record 'recA' shared with a user 'userU' through manual sharing (read-only)

 

When I request the UserRecordAccess object in a 'without sharing' class, all works fine:

[SELECT RecordId, HasEditAccess FROM UserRecordAccess WHERE UserId = :userUid AND RecordId = :recAid LIMIT 1]

=> {RecordId=a0kM0000000jWMxIAM, Id=000000000000000AAA, HasEditAccess=false}

 

 But when I execute the same code in a 'with sharing' class, i get 

 

{RecordId=a0kM0000000jWMxIAM, Id=000000000000000AAA, HasEditAccess=true}  //HasEditAccess should be false}

 

 

It seems like a bug, because when I do this query:

 

[SELECT RecordId FROM UserRecordAccess WHERE UserId = :userUid AND RecordId = :recAid AND HasEditAccess = true LIMIT 1]

 I get not results...

 

 

Please let me know if you have already encountered some problems with the UserRecordAccess object.

 

I'm in API 26

 

Thanks

 

 

Does anyone know how I can check in APEX IF Chatter is enabled for the current Org?

 

I need to check either in a Visualforce page or in an Apex Class and display chatter if it is, and not display it if it is not enabled.

 

thanks

  • March 10, 2011
  • Like
  • 0