Requirement1 --- A profile with Normal user should be able to edit only his records but not the other Users Records.
Requirement2 --- Irrespective of the User Assigned To field should be editable by Everyone
My Validation Rule is
(OwnerId != $User.Id && $Profile.Name='Normal User') && NOT( ISCHANGED( OwnerId ) )
My VF Page and class
<apex:PageBlock title="Letters" mode="inlineEdit" id="theIn" >
<apex:pageBlockButtons location="top" rendered="{!IF(TasklstI.size>0,true,false)}" >
<apex:commandButton value="Save" action="{!saveTaskI}" rerender="theMsg"/>
<apex:commandButton value="Cancel" action="{!cancelTask}" immediate="true"/>
</apex:pageBlockButtons>
<apex:outputPanel rendered="{!IF(TasklstI.size>0,true,false) && Csedt==true}" >
<apex:pageblockTable value="{!TasklstI}" var="tsk" id="table">
<apex:column headerValue="Verification Status"> <apex:Outputfield value="{!tsk.Verification_Status__c}"/></apex:column>
<apex:column headerValue="Verified"><apex:Outputfield value="{!tsk.Task_Verified__c}"/></apex:column>
<apex:column headerValue="Assigned To">
<apex:commandLink value="{!tsk.owner.name}" action="{!editOwner}" reRender="table" rendered="{!tsk.Id<>tempTask.Id}">
<apex:param assignTo="{!ownerEditId}" name="" value="{!tsk.Id}" />
</apex:commandLink>
<apex:inputfield value="{!tsk.ownerId}" rendered="{!tsk.Id=tempTask.Id}" />
</apex:column>
<apex:inlineEditSupport event="ondblClick" />
</apex:pageblockTable>
</apex:PageBlock>
Public pagereference saveTaskI(){
try{
Upsert tasklstI;
pagereference pp = new pagereference('/apex/taskDetails');
pp.setredirect(true);
pp.getparameters().put('id',apexPages.currentpage().getparameters().get('id'));
return pp;
}catch(exception ex){
if(ex.getmessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION')){
String[] errorMsg = ex.getMessage().split('FIELD_CUSTOM_VALIDATION_EXCEPTION,');
String[] errorMsgOnly = errorMsg[1].split(':');
apexPages.addMessage(new apexPages.Message(ApexPages.Severity.ERROR,+errorMsgOnly[0].trim()));
}else{
apexPages.addMessage(new apexPages.Message(ApexPages.Severity.ERROR,'An unexpected error occurred. Please contact the support group with the error message'+ex.getmessage()));
}
return null;
}
}
My Problem here is if I'm having multiple Owners With different profiles.Say Suppose
Ist Record -- User 1 -- Normal User Profile
2nd Record -- User 2 -- System Admin profile
When I logged in as a normal user and try to edit the first record and save it, that has access to getting the Error message as
System.DmlException: Upsert failed. First exception on row 1. Task can't be edited by the owner
The root cause of this error is since here I'm upserting the total Task List 'Tasklisti' where the Normal user is not having the access to the user2 record with the system admin profile, the validation rule is triggering out. How should I overcoe this. Ideas please