+ Start a Discussion
Nagaraju GorliNagaraju Gorli 

FLS Create security issues

//Whaen i insert the Attachment Code ,i write below code .But im getting FLS security issuess plz help me

        if(Schema.sObjectType.Attachment.fields.Ownerid.isCreateable())
            attachment.Ownerid = tsk.ownerid;
        if(Schema.sObjectType.Attachment.fields.ParentId .isCreateable())
            attachment.ParentId = tsk.Id; // the record the file is attached to
        if(Schema.sObjectType.Attachment.fields.ContentType.isCreateable())        
            attachment.ContentType=ContentType;
        if(Schema.sObjectType.attachment.fields.Name.isCreateable())
            attachment.name = fileName;
        if(attachment.body<>null){
            if (Schema.sObjectType.Attachment.fields.body.isCreateable()){
                insert attachment;   
            }                
        }
SandhyaSandhya (Salesforce Developers) 
Hi Nagaraju Gorli,

Please consider below points.


Sharing rules are distinct from object-level and field-level permissions. They can coexist. If sharing rules are defined in Salesforce, you can enforce them at the class level by declaring the class with the with sharing keyword. For more information, see Using the with sharing or without sharing Keywords. If you call the sObject describe result and field describe result access control methods, the verification of object and field-level permissions is performed in addition to the sharing rules that are in effect. Sometimes, the access level granted by a sharing rule could conflict with an object-level or field-level permission.

From below link.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm

For a similar discussion, please refer below the post.

http://salesforce.stackexchange.com/questions/132605/how-to-fix-an-fls-security-vulnerability
 
Hope this helps you!

If this helps you please mark it as solved.

Thanks and Regards
Sandhya