Skip to content

Instantly share code, notes, and snippets.

@scotthung
scotthung / ns_workorder_reopen
Last active April 9, 2016 21:34
Reopen NetSuite Work Order with SuiteScript
var o = nlapiLoadRecord("workorder", 2433031);
for (var i = 1; i <= o.getLineItemCount("item"); i++)
o.setLineItemValue("item", "isclosed", i, "F");
var stat = nlapiSubmitRecord(o);
o = nlapiLoadRecord("workorder", 2433031);
var x = 1;
@scotthung
scotthung / JSONParserSrc1
Last active August 29, 2015 14:13
JSON Parser Source Code
JSONParser parser = JSON.createParser(res.getBody());
System.JSONToken token;
string text;
parser.nextToken(); // Eat first START_OBJECT {
parser.nextToken(); // Eat token = FIELD_NAME; text = postalcodes
parser.nextToken(); // Eat first START_ARRAY [
parser.nextToken(); // Eat the first object's START_OBJECT {
@scotthung
scotthung / gist:cb726e7d76e6c09f525b
Last active August 29, 2015 14:13
Geonames zip code lookup Controller
public with sharing class zipcodeGeonames {
// Constructor
public zipCodeGeonames() {
zipValue = '';
inputCountry = '';
zips = new List<zipInfo>();
}
public class zipCodeException extends Exception {}
@scotthung
scotthung / gist:0798d07debe05cb64298
Last active August 29, 2015 14:13
Geonames zip code lookup VF page
<apex:page controller="zipcodeGeonames">
<apex:form >
<apex:pageBlock >
<apex:actionRegion id="lookupRegion" >
<apex:outputLabel value="Enter 5 digit zip code " for="inputzip" />
<apex:inputText value="{!zipValue}" id="inputzip" />
<apex:outputLabel value="Enter Country " for="inputCountry" />
<apex:inputText value="{!inputCountry}" id="inputCountry" />
<!-- The rerender attribute causes addressList to be re-rendered when the button is clicked -->
@scotthung
scotthung / JSON Return
Last active August 29, 2015 14:12
Parsing JSON data stream with JSONParser library
{"postalcodes":[
{"adminName2":"Olsztyn","postalcode":"10-509","countryCode":"PL","lng":20.4833333,"placeName":"Olsztyn","lat":53.7833333,"adminName1":"Warmińsko-Mazurskie"},
{"adminName2":"Putnam","adminCode2":"079","postalcode":"10509","adminCode1":"NY","countryCode":"US","lng":-73.599179,"placeName":"Brewster","lat":41.409704,"adminName1":"New York"},
{"postalcode":"10509","countryCode":"DO","lng":-70.24743589230769,"placeName":"Carmen Amelia ","lat":18.721794876923077},
{"postalcode":"10509","countryCode":"DO","lng":-70.24743589230769,"placeName":"La Agustinita ","lat":18.721794876923077},
{"adminName2":"La Magdalena Contreras","adminName3":"Ciudad de Mexico","adminCode2":"9008","postalcode":"10509","adminCode1":"DIF","countryCode":"MX","lng":-98.99779722222222,"placeName":"Residencial San Carlos","lat":19.20726277777778,"adminName1":"Distrito Federal"}
]}
@scotthung
scotthung / standardListController
Created December 11, 2014 07:35
Standard list controller to display cases
public class casePollList {
public ApexPages.StandardSetController setCon {
get {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Subject, CaseNumber FROM Case WHERE owner.name='Open Cases']));
return setCon;
}
set;
}
// Initialize setCon and return a list of records
public List<Case> getCases() {
@scotthung
scotthung / actionPoller refresh
Created December 11, 2014 07:32
Visualforce page to list cases and actionPoller for refresh
<apex:page controller="casePollList" >
<div style="width:300px;">
<apex:form >
<apex:pageBlock id="myBlock" >
<apex:actionPoller interval="10" rerender="myBlock" />
<apex:pageBlockTable value="{!cases}" var="c" id="myTable">
<apex:column value="{!c.CaseNumber}"/>
<apex:column value="{!c.Subject}"/>
</apex:pageBlockTable>
</apex:pageBlock>
@scotthung
scotthung / enhancedListView
Last active August 29, 2015 14:11
VisualForce enhancedList component
<apex:page standardController="Case" >
<div style="width:300px;">
<apex:enhancedList height="250" listid="00B600000074y38"/>
</div>
<script type="text/javascript">
isListLoaded();
function isListLoaded(){
setTimeout("location.reload(true);",10000);
}
@scotthung
scotthung / accountApexZipCode
Last active August 29, 2015 14:07
Apex code the account trigger uses to make a callout to look up zip codes.
// Use a name besides "Account" otherwise you'll get compilation problems due to symbol collision
public with sharing class AccountClass {
private static boolean isTrigger = false; // Pitfall #4: Used to prevent infinite loops
public class accountException extends Exception {}
/* format from ziptasticapi.com:
{"country":"US","state":"CA","city":"SAN JOSE"}
*/
// Format returned by ziptastic API
@scotthung
scotthung / accountTriggerZipCode
Created October 8, 2014 05:34
Account trigger example code
trigger accountTrig on Account (after insert) {
// When a new account is created, fill in the city and state based on zip code
if (trigger.isAfter && trigger.isInsert) {
AccountClass.onAfterInsert( trigger.new );
}
}