When trying to understand some new programming concepts or the specifics of a new language or API, the documentation is invaluable. Here's a couple of resources for you.
Here are some details about the specific code snippets you had questions about.
Check out the Exception documentation for
e.getMessage();
, String Methods documentation forindexOf()
, and ApexPages documentation.String msg=e.getMessage(); // get the error message integer pos;
// if its field validation, this will be added to the messages by default if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, '))) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg)); }
result=false;
-
pr.setRedirect(true);
The
null
here is assigning no"no value" (or a blank value) to all of those variables. I'm not entirely sure what that's doing. It could be resetting the values so that they can be used to insert another skid__c.public void newSkid() { if (updateSkids()) { Skid__c skid=new Skid__c(Name=newSkidName, Dimension__c=newSkidDimension, Number_of_Pieces__c=newSkidNumberofPieces, UOM__c=newskiduom, Weight__c=newskidweight, Bill_of_Lading__c=getBillofLading().id); insert skid;
newSkidName=null; newSkidDimension=null; newSkidNumberofPieces=null; newskidbilloflading=null; newskiduom=null; newskidweight=null; skids=null;
The comparison with
null!=
here is checking to see if thechosenskidId
has a value. It might be better understood asif(chosenskidId != null)
which is an equivalent statement.public void deleteSkid() { if (updateSkids()) { if (null!=chosenskidId) { Skid__c skid=new Skid__c(Id=chosenskidId); delete skid;
skids=null; chosenskidId=null; } }
}
The
null
statement again here is basically saying: If the resulting sObject (or variable)Id
from the function,getBillofLading()
, has a value andskids
is does not have a value, do the following statements between the brackets{
and}
.public List<Skid__c> getSkids() { if ( (null!=getBillofLading().id) && (skids == null) ) { skids=[SELECT Id, Name, Bill_of_Lading__c,
Dimension__c, Number_of_Pieces__c, UOM__c, Weight__c FROM Skid__c WHERE Id =: getBillofLading().id ORDER BY CreatedDate];See the inline comments for these functions. Also, check out the ApexPages documentation and the PageReference documentation.
public String getChooserender() { // if the current page has a 'p' QueryString Parameter if (ApexPages.currentPage().getParameters().get('p') != null) return 'pdf'; // return 'pdf' else return null; }
public PageReference deliverAsPDF() { // create a new PageReference to the Page named 'Billofladingtest05222013' PageReference pdf = Page.Billofladingtest05222013; // add the 'p' QueryString Parameter pdf.getParameters().put('p','p'); // return the PageReference return pdf; }