I have handled the case creation process using a vf page and explored it as a vf tab. Now i want to have a validation that should throw an error message that if the current user is in vf tab view , it should allow to edit the record but if the user is in the detail page view , it should not.

Kindly help me out!!! I have tried validation rule as well as trigger. Nothing much happened !!

Validation Rule :

AND(NOT($User.BypassVR__c),IF($Profile.Name = "Core-Service Profile Community",True,False),
ISCHANGED(Kilometer__c),ISCHANGED(CIRNumber__c),ISCHANGED( CatalogFuncCode__c),
ISCHANGED(VehicleMaintenance__c),ISCHANGED(CustomerWants__c ),ISCHANGED(MaintHistAvail__c ),
ISCHANGED(RetainedVehicle__c),ISCHANGED( RetainedVehDate__c),ISCHANGED(SubType__c),ISCHANGED(IS_Internal__c)), PRIORVALUE(Tech_IsDraft__c) <> false )

Trigger :

public with sharing class ecareCTR {

public static void caselistval(List<case> lCase) {
 Set<Id> lCaseId =  new Set<Id>();
 for(Case c:lcase)
List<Case> lEcareCase = new List<Case> ();
List<Case> ecList = new List<Case>();
try {
ecList = [SELECT id,CaseNumber from Case WHERE id IN:lCaseId];
if(!ecList.isEmpty()) {
 for(Case cas :  ecList) {
    cas.Tech_IsDraft__c = false;


  catch (Exception e) {
      system.debug('eeee' + e);

Above trigger is called from before update method

  • 1
    Try looking at the url. For example, if you are on a standard detail page, the url would be something like https://XXX.salesforce.com/RECORD_ID, while if you are in a custom VF page the url will be like https://XXX.salesforce.com/apex/PAGE_NAME. – smukov Sep 20 '16 at 5:58
  • Are you using standardcontroller or custom controller here? – Tushar Sharma Oct 19 '16 at 6:51

You can do one thing. Create a static variable and set it to true. Now refer this variable in your trigger and if its true then show error message that you can't update the record.

And from your VF page set this variable to false. So it will not give you any exception.

  • Ok tushar i ll create a static variable in trigger and set it to true if the user is trying to update. But how to use the same variable in the vf page ot make it false – Sathish Sep 20 '16 at 6:38
  • @Sathish from your extension set this to false – Tushar Sharma Sep 20 '16 at 6:42
  • Could you tell the syntax to declare variable in the vf page, to make it as false. – Sathish Oct 19 '16 at 5:01
  • @Sathish VF page means before making DML from apex set it(Static Boolean variable) to false. – Tushar Sharma Oct 19 '16 at 5:04
  • Sahrma This what I am declaring in {!tempvariable}=false vf page. And in my class public static boolean runOnce(){ fts=true; if(fts){ fts=false; return true; }else{ return fts; } } – Sathish Oct 19 '16 at 5:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.