Skip to content

Instantly share code, notes, and snippets.

View ganmahmud's full-sized avatar
🎯
Focusing

Gan Mahmud ganmahmud

🎯
Focusing
View GitHub Profile
[
{
"gender": "male",
"name": {
"title": "mr",
"first": "aiden",
"last": "lucas"
},
"location": {
"street": "1446 oak lawn ave",
@ganmahmud
ganmahmud / CtoP.php
Last active November 21, 2018 06:55
<?php
add_action('admin_menu', 'test_plugin_setup_menu');
function test_plugin_setup_menu(){
add_menu_page( 'Shoppers Mag CSV Import Page', 'Shoppers Mag CSV Import', 'manage_options', 'csv-import', 'test_init', "dashicons-image-rotate-right",2 );
}
function test_init(){
test_handle_post();
@ganmahmud
ganmahmud / AccountAddressTrigger.apxt
Last active November 21, 2018 06:38
Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.
trigger AccountAddressTrigger on Account (before insert, before update) {
for(Account a : Trigger.new){
If (a.Match_Billing_Address__c == true && a.BillingPostalCode!=Null) {
a.ShippingPostalCode = a.BillingPostalCode;
System.debug('ShippingPostalCode: '+a.ShippingPostalCode);
System.debug('BillingPostalCode: '+a.BillingPostalCode);
}
}
}
@ganmahmud
ganmahmud / StringArrayTest.cls
Last active November 21, 2018 06:49
Create an Apex class with a method that returns an array (or list) of strings.
public class StringArrayTest {
public static String[] generateStringArray(Integer numOfStrings) {
// Create a generateStringArray object
String[] stringArr = new List<String>();
for(Integer i=0;i<numOfStrings;i++) {
stringArr.add('Test '+i);
}
return stringArr;
}
@ganmahmud
ganmahmud / AccountHandler.cls
Last active November 21, 2018 06:49
Create a method for inserting accounts.
public class AccountHandler {
public static Account insertNewAccount(String accountName){
try{
Account acct = new Account(Name=accountName);
insert acct;
return acct;
}
catch (DmlException e){
System.debug('A DML exception has ocurred: ' + e.getMessage());
return (NULL);
@ganmahmud
ganmahmud / ContactSearch.cls
Last active April 16, 2022 19:46
Create an Apex class that returns contacts based on incoming parameters.
public class ContactSearch {
public static Contact[] searchForContacts(String lastName, String postCode){
Contact[] cts = [SELECT Contact.ID,Contact.Name FROM Contact
WHERE LastName = :lastName AND MailingPostalCode= :postCode];
return cts;
}
}
@ganmahmud
ganmahmud / ContactAndLeadSearch.cls
Last active November 21, 2018 06:48
Create an Apex class that returns both contacts and leads based on a parameter.
public class ContactAndLeadSearch {
public static List<List<SObject>> searchContactsAndLeads(String lastName){
List<List<SObject>> searchList = [FIND :lastName IN ALL FIELDS
RETURNING Lead(Name), Contact(FirstName,LastName)];
Lead[] searchLead = (Lead[])searchList[0];
Contact[] searchContacts = (Contact[])searchList[1];
System.debug('Found the following leads.');
for (Lead a : searchLead) {
System.debug(a.Name);
}
@ganmahmud
ganmahmud / AddRelatedRecord.tgr
Last active November 23, 2018 09:48
The trigger adds a default opportunity for every account that doesn’t already have an opportunity
trigger AddRelatedRecord on Account(after insert, after update) {
List<Opportunity> oppList = new List<Opportunity>();
// Get the related opportunities for the accounts in this trigger
Map<Id,Account> acctsWithOpps = new Map<Id,Account>(
[SELECT Id,(SELECT Id FROM Opportunities) FROM Account WHERE Id IN :Trigger.New]);
// Add an opportunity for each account if it doesn't already have one.
// Iterate through each account.
for(Account a : Trigger.New) {
@ganmahmud
ganmahmud / AddRelatedRecord_Optimized.tgr
Last active November 23, 2018 09:48
The trigger adds a default opportunity for every account that doesn’t already have an opportunity ( Bulk Query Optimized )
trigger AddRelatedRecord on Account(after insert, after update) {
List<Opportunity> oppList = new List<Opportunity>();
// Add an opportunity for each account if it doesn't already have one.
// Iterate over accounts that are in this trigger but that don't have opportunities.
for (Account a : [SELECT Id,Name FROM Account
WHERE Id IN :Trigger.New AND
Id NOT IN (SELECT AccountId FROM Opportunity)]) {
// Add a default opportunity for this account
oppList.add(new Opportunity(Name=a.Name + ' Opportunity',