Class to insert records into custom object?
public with sharing class studentinsert{
public Pagereference doInsert(){
student__c std=new student__c();
std.name=nameval;
std.email__c=emailval;
insert std;
pagereference ref =new pagereference('/apex/studentinserttest');
ref.setredirect(true);
return ref;
}
public String nameval{get;set;}
public String emailval{get;set;}
}
With Sharing:Enforces sharing rules that apply to current user.If absent,code is run under system context.
Pagereference:A reference to the visualforce page
Note:If we have parent and child classes; by default WITH SHARING is apply to two classes,so to avoid that salesforce introduce WITHOUT SHARING.
Without Sharing:Ensures that the sharing rules of the current user are not enforced.
public with sharing class studentinsert{
public Pagereference doInsert(){
student__c std=new student__c();
std.name=nameval;
std.email__c=emailval;
insert std;
pagereference ref =new pagereference('/apex/studentinserttest');
ref.setredirect(true);
return ref;
}
public String nameval{get;set;}
public String emailval{get;set;}
}
With Sharing:Enforces sharing rules that apply to current user.If absent,code is run under system context.
Pagereference:A reference to the visualforce page
Note:If we have parent and child classes; by default WITH SHARING is apply to two classes,so to avoid that salesforce introduce WITHOUT SHARING.
Without Sharing:Ensures that the sharing rules of the current user are not enforced.
Good Scenarios for Basic level developer
ReplyDelete