function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MN_sfdcMN_sfdc 

How to solve FLS create and FLS create issue for checkmarx

Hi All,
I have to resolve FLS Create and FLS Update issue for upsert, issue generated by checkmarx scan.
Following is a code sample:
public PageReference PushAttach() {
        uniAttach.ParentId = PrePushAttachtId;
        upsert uniAttach;     //here need to use iscreatable() and isUpdatable()
       for(POWrap s : POWrapList){ if(s.PO.Id == PrePushAttachtId) { s.Attach = uniAttach; s.Attach.body = Null; break; }}
       uniAttach = new Attachment();
        return Null;
}

How to use iscreatable() and isupdatable() for upsert.
Thanks
ayu sharma devayu sharma dev
Hello MNA

I would suggest you using Database.upsert() instead of using Upsert

Please follow the documentation here( https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_upsertresult.htm?search_text=database )

Another example is given here( https://salesforce.stackexchange.com/questions/189138/database-upsert-how-to-find-which-records-have-inserted-updated-based-on-exter )

If you have any doubts please let me know. 
If it solves your issue then mark this as the best solution so others can use it too.

Thanks and Regards
Ayush Sharma
MN_sfdcMN_sfdc
Hi Ayu Sharma,
Thanks for a quick response, my exact requirement is to validate the fields as per field-level security while inserting or updating data in a field like:
if(Schema.sObjectType.Attachment.isCreateable() && Schema.sObjectType.Attachment.isUpdateable()) { 
       upsert uniAttach;
}
But it's not working for me.