function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hareeshnhareeshn 

Geting problem in Unshare a record using apex vfpage

Hi Bello is my code
----------------------------------------------
vf page
----------------------------------------------

<apex:page standardController="Job__c"  extensions="Unsharerecordcon" >
  <apex:form >
      <apex:pageBlock >
                <apex:selectList size="1"  value="{!jobstunshare}" multiselect="false">
                    <apex:actionSupport event="onchange" reRender="opt2" />
                    <apex:selectOptions value="{!Record}"></apex:selectOptions>
                </apex:selectList>
               
                <apex:selectList size="1" value="{!selectedVa2}" multiselect="false">
                  <apex:actionsupport event="onchange" reRender="opt2,opt3"/>
                  <apex:selectoptions value="{!User}" ></apex:selectoptions>
                </apex:selectList>
               
               
                  <apex:commandLink action="{!manualShareRead}" value="UnShare" id="opt2" onclick="alert('helo')">
                </apex:commandLink> 
             
            
                          
        </apex:pageBlock>
       
  </apex:form>
</apex:page>
--------------------------------------------------------------------------------------------------------------------
apex page
------------------------------------------------------------------------------------------------------------------
public  class Unsharerecordcon

{

         List<user> con2= new List<user>(); 
         public List<job__C> joblist { get;set;}
         public String selectedVa2{get;set;}
         Job__Share jobShr {set;get;}
         public string jobstunshare { get;set;}
         public List<job__share> jobshareset {get;set;}
         public Set<SelectOption> setobj { get;set;}
          public Set<SelectOption> setobjuser { get;set;}
         public List<job__C> joblistun { get;set;}
        
          public Unsharerecordcon()
          {

          }
         
          public Unsharerecordcon(ApexPages.StandardController controller)
          {

          }

          public set<SelectOption> getUser()
          {
         
              List<SelectOption> optionuser = new List<SelectOption>();
             
              for(job__share jshareuser:[select id,userorgroupid  from job__share])
              {
              for(user unuser:[select id,name from user where id =:jshareuser.userorgroupid])
              {
             
              setobjuser =new Set<SelectOption>();
                optionuser.add(new SelectOption(unuser.id,unuser.name));
                setobjuser.addAll(optionuser);
              }
              }
              return setobjuser;
             
         
         
          }
         
           public Set<SelectOption> getRecord()
        
             {
                      List<SelectOption> option = new List<SelectOption>();
                     
                      for(job__share jshare:[ select id,parentid,userorgroupid From  job__share])
                      {
                         
                          for(job__c unjb: [Select id,name From  job__c  where id =:jshare.parentid])
                         {
                                    setobj =new Set<SelectOption>();
                                   option.add(new SelectOption(unjb.id,unjb.name));
                                   setobj.addAll(option);
                         system.debug('option value is '+setobj);
                        
                         }
                     }
                    
                    return setobj;     
          }
        
        
          public PageReference  manualShareRead()
   
            {
                 system.debug('manualunShare');
                joblistun = [select id from job__C where id=:jobstunshare];
                system.debug('jobstunshare value'+jobstunshare);
                con2 = [select id from user where name=:selectedVa2];
                system.debug('selectedVa2 value'+selectedVa2);
                jobShr  = new Job__Share(); 
                jobShr.ParentId = joblistun[0].id;
                jobShr.UserOrGroupId = con2[0].id;
               
               
                delete jobShr;
              
            // Database.SaveResult sr = Database.delete(jobShr,false);
                PageReference nextpage = new PageReference('/apex/CustomTeam');
                 nextpage.setRedirect(true);
                
               
            return nextpage ;
      
         }

  
}
-------------------------------------------
am going in rightway to achive unshare a record using apex and vf ?

Thanks
Ashish_SFDCAshish_SFDC
Hi Hareesh, 


What exactly you mean by unshare a record - there is no unsharing of records in Salesforce. 

If you are getting errors in the above code - paste the exact error and debug logs so that we can look into it. 


Regards,
Ashish