You need to sign in to do that
Don't have an account?
hareeshn
am able share a record to user using apex how to unshare a record using apex
am able share a record to user using apex how to unshare a record using apex
here is my code:
vf page
------------------------------------------------------
<apex:page standardController="Job__c" extensions="Jobformation1usercon">
<apex:form >
<apex:selectList size="1" value="{!jobst }" multiselect="false">
<apex:selectOptions value="{!Job}"> </apex:selectOptions>
<apex:actionSupport event="onchange" reRender="table,opt1" />
</apex:selectList>
<apex:selectList size="1" value="{!selectedVal}" multiselect="false">
<apex:actionSupport event="onchange" reRender="table,opt1" />
<apex:selectOptions value="{!Value}">
</apex:selectOptions>
</apex:selectList>
<apex:outputText id="opt12" value="{!selectedVal}"></apex:outputText>
<apex:commandLink action="{!manualShareRead}" value="Share" id="opt1">
</apex:commandLink>
</apex:form>
</apex:page>
----------------------------------------------------------------------
apex page
----------------------------------------------------------------------------------------
public class Jobformation1usercon
{
List<user> con1= new List<user>();
public job__c j {get;set;}
Public List<string> usertselect{get;set;}
public string jobst { get;set;}
public string val{ get;set;}
public user gp {get;set;}
public boolean nojb{get;set;}
public String selectedVal{get;set;}
public List<job__C> joblist = new List<job__C>();
public Jobformation1usercon(ApexPages.StandardController controller)
{
}
public List<SelectOption> getJob()
{
List<SelectOption> option = new List<SelectOption>();
for(job__c j: [Select id,name From job__c])
{
option.add(new SelectOption(j.name,j.name));
system.debug('option value is '+option);
}
return option;
}
public List<SelectOption> getValue()
{
List<SelectOption> option = new List<SelectOption>();
for(user gp: [Select id,name From user ])
{
option.add(new SelectOption(gp.name,gp.name));
system.debug('option value is '+option);
}
return option;
}
public PageReference manualShareRead()
{
joblist = [select id from job__C where name=:jobst];
con1 = [select id from user where name=:selectedVal];
system.debug('PGList value is'+con1);
system.debug('PGList value is'+joblist);
Job__Share jobShr = new Job__Share();
jobShr.ParentId = joblist[0].id;
jobShr.UserOrGroupId = con1[0].id;
jobShr.AccessLevel = 'Read';
jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
Database.SaveResult sr = Database.insert(jobShr,false);
system.debug('sr value is'+sr);
if(sr.isSuccess())
{
system.debug('sr.isSuccess() value:'+sr.isSuccess());
system.debug('if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+joblist[0].id);
return nextpage;
}
else {
system.debug('inner else sr.isSuccess() block');
Database.Error err = sr.getErrors()[0];
if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION &&
err.getMessage().contains('AccessLevel')){
system.debug(' iner if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+joblist[0].id);
return nextpage;
}
else
{
system.debug('outer else sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+joblist[0].id);
return nextpage;
}
}
}
}
-------------------------------
here job__c is object name is one text field am shring a reord to one user here user is one object .
if i want to un share want i need to do please help on this
thanks
hareesh
here is my code:
vf page
------------------------------------------------------
<apex:page standardController="Job__c" extensions="Jobformation1usercon">
<apex:form >
<apex:selectList size="1" value="{!jobst }" multiselect="false">
<apex:selectOptions value="{!Job}"> </apex:selectOptions>
<apex:actionSupport event="onchange" reRender="table,opt1" />
</apex:selectList>
<apex:selectList size="1" value="{!selectedVal}" multiselect="false">
<apex:actionSupport event="onchange" reRender="table,opt1" />
<apex:selectOptions value="{!Value}">
</apex:selectOptions>
</apex:selectList>
<apex:outputText id="opt12" value="{!selectedVal}"></apex:outputText>
<apex:commandLink action="{!manualShareRead}" value="Share" id="opt1">
</apex:commandLink>
</apex:form>
</apex:page>
----------------------------------------------------------------------
apex page
----------------------------------------------------------------------------------------
public class Jobformation1usercon
{
List<user> con1= new List<user>();
public job__c j {get;set;}
Public List<string> usertselect{get;set;}
public string jobst { get;set;}
public string val{ get;set;}
public user gp {get;set;}
public boolean nojb{get;set;}
public String selectedVal{get;set;}
public List<job__C> joblist = new List<job__C>();
public Jobformation1usercon(ApexPages.StandardController controller)
{
}
public List<SelectOption> getJob()
{
List<SelectOption> option = new List<SelectOption>();
for(job__c j: [Select id,name From job__c])
{
option.add(new SelectOption(j.name,j.name));
system.debug('option value is '+option);
}
return option;
}
public List<SelectOption> getValue()
{
List<SelectOption> option = new List<SelectOption>();
for(user gp: [Select id,name From user ])
{
option.add(new SelectOption(gp.name,gp.name));
system.debug('option value is '+option);
}
return option;
}
public PageReference manualShareRead()
{
joblist = [select id from job__C where name=:jobst];
con1 = [select id from user where name=:selectedVal];
system.debug('PGList value is'+con1);
system.debug('PGList value is'+joblist);
Job__Share jobShr = new Job__Share();
jobShr.ParentId = joblist[0].id;
jobShr.UserOrGroupId = con1[0].id;
jobShr.AccessLevel = 'Read';
jobShr.RowCause = Schema.Job__Share.RowCause.Manual;
Database.SaveResult sr = Database.insert(jobShr,false);
system.debug('sr value is'+sr);
if(sr.isSuccess())
{
system.debug('sr.isSuccess() value:'+sr.isSuccess());
system.debug('if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+joblist[0].id);
return nextpage;
}
else {
system.debug('inner else sr.isSuccess() block');
Database.Error err = sr.getErrors()[0];
if(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION &&
err.getMessage().contains('AccessLevel')){
system.debug(' iner if sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+joblist[0].id);
return nextpage;
}
else
{
system.debug('outer else sr.isSuccess() block');
PageReference nextpage = new PageReference('/apex/CustomTeam?id='+joblist[0].id);
return nextpage;
}
}
}
}
-------------------------------
here job__c is object name is one text field am shring a reord to one user here user is one object .
if i want to un share want i need to do please help on this
thanks
hareesh
Glad you were able to solve the issue that you have posted earlier :)
Also, to "unshare" you can delete the job__share record for the corresponding job__c record by either querying or fetching the id from VF page.
Hope this helps.
thanks for reply
can you please explore more about how to achive unshare functionallty i got some thing ........