You need to sign in to do that
Don't have an account?
Anil Ingle
How to solve FLS Create and FLS Update Issues
Hello All,
I have run code scanner tool on my apex class and Visual force page. It give me FLS Create and FLS Update Issues.
I have solved these issues as per mention following URL
https://developer.salesforce.com/page/Testing_CRUD_and_FLS_Enforcement
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm
Again I have run code scanner tool on my apex class and Visual force page. It gives me again FLS Create and FLS Update Issue.
Let me know, if anything I miss
Following are the sample code
Boolean isContFirstNameUpsertable = Schema.sObjectType.Contact.fields.FirstName.isCreateable() &&
Schema.sObjectType.Contact.fields.FirstName.isUpdateable();
Boolean isContLastNameUpsertable = Schema.sObjectType.Contact.fields.LastName.isCreateable() &&
Schema.sObjectType.Contact.fields.LastName.isUpdateable();
List<Contact> lstContact = new List<Contact>();
if(isContFirstNameUpsertable && isContLastNameUpsertable) {
for(AgentWrapper aw : scope) {
Contact c = new Contact(
FirstName=aw.FirstName,
LastName=aw.LastName);
lstContact.add(c);
}
if(lstContact.size() > 0) {
upsert lstContact;
}
}
Thanks in Advance
I have run code scanner tool on my apex class and Visual force page. It give me FLS Create and FLS Update Issues.
I have solved these issues as per mention following URL
https://developer.salesforce.com/page/Testing_CRUD_and_FLS_Enforcement
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_perms_enforcing.htm
Again I have run code scanner tool on my apex class and Visual force page. It gives me again FLS Create and FLS Update Issue.
Let me know, if anything I miss
Following are the sample code
Boolean isContFirstNameUpsertable = Schema.sObjectType.Contact.fields.FirstName.isCreateable() &&
Schema.sObjectType.Contact.fields.FirstName.isUpdateable();
Boolean isContLastNameUpsertable = Schema.sObjectType.Contact.fields.LastName.isCreateable() &&
Schema.sObjectType.Contact.fields.LastName.isUpdateable();
List<Contact> lstContact = new List<Contact>();
if(isContFirstNameUpsertable && isContLastNameUpsertable) {
for(AgentWrapper aw : scope) {
Contact c = new Contact(
FirstName=aw.FirstName,
LastName=aw.LastName);
lstContact.add(c);
}
if(lstContact.size() > 0) {
upsert lstContact;
}
}
Thanks in Advance
List<Contact> lstContact = new List<Contact>();
for(AgentWrapper aw : scope) {
Contact c = new Contact(
FirstName=aw.FirstName,
LastName=aw.LastName);
lstContact.add(c);
}
if(lstContact.size() > 0 && Schema.sObjectType.Contact.fields.FirstName.isCreateable() && Schema.sObjectType.Contact.fields.FirstName.isUpdateable() && Schema.sObjectType.Contact.fields.LastName.isCreateable() && Schema.sObjectType.Contact.fields.LastName.isUpdateable() )
{
upsert lstContact;
}
Thanks for the reply.
I have updated my code as per your suggession. But still Code Scanner gives me FLS Create and FLS Update Issue.
Following are the sample code
global with sharing class AgentImportJob implements
Database.Batchable<AgentWrapper>, Database.AllowsCallouts, Database.Stateful, Schedulable {
global Iterable<AgentWrapper> start(Database.BatchableContext BC) {
.....
}
global void execute(Database.BatchableContext BC, List<AgentWrapper> scope) {
List<Contact> lstContact = new List<Contact>();
for(AgentWrapper aw : scope) {
Contact c = new Contact(
FirstName=aw.FirstName,
LastName=aw.LastName);
lstContact.add(c);
}
if(lstContact.size() > 0 && !Test.isRunningTest() && Schema.sObjectType.Contact.fields.FirstName.isCreateable() && Schema.sObjectType.Contact.fields.FirstName.isUpdateable() && Schema.sObjectType.Contact.fields.LastName.isCreateable() && Schema.sObjectType.Contact.fields.LastName.isUpdateable() )
{
upsert lstContact;
}
}
global void finish(Database.BatchableContext BC) {
....
}
}
can u show me that source scanner report or drop a mail to kbsantoshreddy@gmail.com
I have send Scan Code file report. Please check and let me know your opinion.
Thanks