0

I've a object, custom button and two check box field on it.

The custom button which is updating the check box field to true.

from custom button java script code i'm calling apex class, after execution of apex class it should update the check box field on same object.

This is perfect working for system admin user,

but when i tried for non admin user it will not updating the checkbox to true but apex class is correct executing in this case

The check box field is read only from field accessibility for all profile.

why it is not updating for non admin user?

Code is.

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
 {!REQUIRESCRIPT("/soap/ajax/19.0/apex.js")} 

if("{!Patient_Services__c.Service_Invoiced__c}"== "0" || 
"{!Patient_Services__c.Service_Invoiced__c}"== "1" && "       {!$Profile.Name}"=="System Administrator") 
{
    if("{!Patient_Services__c.Ready_for_Billing__c}" == "0" && "{!Patient_Services__c.Who_to_Invoice__c}" == '' ) 
        { 
        alert('Please Select the Who To Invoice'); 
        } 
    else 
        if("{!Patient_Services__c.Ready_for_Billing__c}" == "0" && "{!Patient_Services__c.Who_to_Invoice__c}" != "null" ) 
        {

                if("{!Patient_Services__c.Added_to_Opty__c}"== "0" && ("{!Patient_Services__c.Who_to_Invoice__c}"=="Medicare Account" || "{!Patient_Services__c.Who_to_Invoice__c}"=="DVA Account")) 
                {

                    var r = confirm("Opportunity will now be created;\nDo you want to proceed?"); 
                    if(r == true) 
                    {
                        //alert("Opportunity now Created"); 
                        var a= sforce.apex.execute("CreateOpty","CreateOptywithps",{Id :"{!Patient_Services__c.Id}"}); 
                        // alert(a); 

                    if(a>0)
                        alert("Opportunity created Successfully for Medicare/DVA Account..!\nFor Opportunity Product Please see bottom of page");

                    else if(1)
                    alert("Opportunity not Created for Medicare/DVA Account.\nCheck Rate Card is Available or Billing Error log. Please Contact your System Administrator")

                    var b;
                    if("{!Patient_Services__c.Dispensing_Footwear_F049__c}"=="1")
                            {
                            b = sforce.apex.execute("CreateOptyforDispenfoot","CreateOptywithps",{Id :"{!Patient_Services__c.Id}"}); 

                        //  alert(b);
                            if(b>0)
                            alert("Opportunity created Successfully for Dispensing Footwear F049..!\nFor Opportunity Product Please see bottom of page");
                            else if(1)
                            alert("Opportunity not Created for Dispensing Footwear F049.\nCheck Rate Card is Available or Billing Error log.\nPlease Contact your System Administrator")
                            }

                    if(a>0 || b>0)
                            {
                            var c = new sforce.SObject("Patient_Services__c"); 
                            c.id = "{!Patient_Services__c.Id}"; 
                            c.Ready_for_Billing__c= "1"; 
                            result = sforce.connection.update([c]); 
                            window.location.reload(); 
                            }

                }
                }}

apex class is

global class CreateOpty{

 WebService static Integer CreateOptywithps(String Id)
{    .........
 }}
  • When you wrote your testmethods for this, did you include a runas section? If so, can you inlcude the testMethod in the question, along with the relevant code you've currently written? – Nick Cook Jul 21 '16 at 12:50
  • code to update the check box field is in java script not in apex class, so No test class for it – Amol Jul 21 '16 at 12:59
  • can you share your code. – Haytham Jul 21 '16 at 13:01
  • @Amol but you said that "from custom button java script code i'm calling apex class, after execution of apex class it should update the check box field on same object." So you have an apex class. What happens in your test method when you call this class using a runAs block? – Nick Cook Jul 21 '16 at 13:04
  • @ Nick. i've written test class for apex class and called that apex class manually like' test.startTest(); Integer p = CreateOpty.CreateOptywithps(ps.id); test.stopTest();' – Amol Jul 21 '16 at 13:09
-1

The edit access to the record is determined by the sharing access granted to the user unless you declare the apex class as without sharing..Please check field level security for those user

  • without sharing gives access to records, not FLS, FLS is not applied on apex context. – Haytham Jul 21 '16 at 13:00
  • Please check my class declation also. and in field level security nothing access is given. In field accessibility it is make as Read only. – Amol Jul 21 '16 at 13:17
  • @sagar @ Haytham. i'm not getting this concept can you clarify me – Amol Jul 21 '16 at 13:24
  • FIrst thing is, my field update code which is written in javascript button code not in apex class, thus without sharing class is how beneficial here – Amol Jul 21 '16 at 13:38
  • @Amol in a class, you have code that selects a column that the user doesn't have access to, but you can't select a RECORD that the user doesn't have access to. you asked him to check field level security, where he should actually check Sharing Settings. – Haytham Jul 23 '16 at 22:45

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.