+ Start a Discussion
shiv@SFDCshiv@SFDC 

How to give account access to community user for his accounts

I am having a partner account in my org, say PA1 now there is partner user associted with it. Now how can I show PA1 information to partner user.
I want to say how a partner user can see his account information on the community.
ManojjenaManojjena
Hi Shiv,
You need to write a trigger on user object ,when you will create user you need to share the Account which is related to the contact from which we you are creating user .

You have to create an account share record for account . You wil basically get MIX DML EXCEPTION as both setup and non set up object will create from same context .

Try with below code it will help for sure !
 
trigger AccountShare on User (After insert,After update ) {
   Map<Id,Id> ContactUserIdMap=new Map<Id,Id>();
   for(User usr: Trigger.new){
     if(usr.ContactId != null){
         ContactUserIdMap.put(usr.ContactId,usr.Id);
     } 
  }
   UserTriggerHandler.shareInsert(ContactUserIdMap);
}
//Handler class 
public class UserTriggerHandler{
    @future
    public static void shareInsert(Map<Id,Id> conusrIdMap ){
      Map<id,id>  conAccIdMap=new Map<id,id>();
       List<Contact>conList=[SELECT Id, AccountId FROM Contact WHERE Id IN :conusrIdMap.keySet() LIMIT 50000];
       for(Contact con : conList){
           conAccIdMap.put(con.Id,con.AccountId);
       }
       List<AccountShare> accShareList=new List<AccountShare>();
       for(String str : conusrIdMap.keySet()){
            AccountShare acc=new AccountShare();
                acc.UserOrGroupId =conusrIdMap.get(str);
                acc.AccountId=conAccIdMap.get(str);
                acc.AccountAccessLevel='Edit';
                acc.OpportunityAccessLevel='Read';
                accShareList.add(acc);
        }
        try{
            Insert accShareList;
        }catch(DMLException de){
            System.debug(de);
        } 
    }
}

Let me know if it helps !
Thanks 
Manoj

 
shiv@SFDCshiv@SFDC
Can I not to do this using sharing settings ?
ManojjenaManojjena
Hi Shiv,
I don't think we can achieve this by sharing rule .
Amit Chaudhary 8Amit Chaudhary 8
Hi Shiv,

Please check below post. I hope you can do same by configuration only.
Option1:- Please check below post
https://help.salesforce.com/HTViewHelpDoc?id=networks_setting_light_users.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=networks_setting_light_users.htm&language=en_US)
https://help.salesforce.com/apex/HTViewHelpDoc?id=customer_portal_granting_user_access.htm

Option 2:- Please create on custom profile and provide "Portal Super User" access to profile.

Please mark this as solution if this post will help you so that is some one has same issue this past can help others.

Thanks,
Amit Chaudhary