Snippets Collections
from dataclasses import dataclass
 
@dataclass
class Book_list:
	name: str
	perunit_cost: float
	quantity_available: int = 0
		
	# function to calculate total cost	
	def total_cost(self) -> float:
		return self.perunit_cost * self.quantity_available
	
book = Book_list("Introduction to programming.", 300, 3)
x = book.total_cost()
 
# print the total cost
# of the book
print(x)
 
# print book details
print(book)
 
# 900
Book_list(name='Python programming.',
		perunit_cost=200,
		quantity_available=3)
{
    "swagger": "2.0",
    "basePath": "/",
    "info": {
        "version": "1.0",
        "title": "External Service for demo bank",
        "description": "### External Service for demo bank",
        "x-vcap-service-name": "DemoBankRestServices"
    },
    "securityDefinitions": {
        "basicAuth": {
            "type": "basic"
        }
    },
    "security": [{
        "basicAuth": []
    }],
    "tags": [{
        "name": "DemoBankRestServices"
    }],
    "paths": {
        "/accounts/{accountName}": {
            "get": {
                "operationId": "getAccount",
                "summary": "Retrieves an account",
                "description": "Retrieves the account with specific name",
                "consumes": ["text/plain"],
                "produces": ["application/json"],
                "parameters": [{
                    "name": "accountName",
                    "in": "path",
                    "required": true,
                    "type": "string",
                    "description": "Name of the account"
                }],
                "responses": {
                    "200": {
                        "description": "The response when system finds an account with given name",
                        "schema": {
                            "$ref": "#/definitions/accountDetails"
                        }
                    },
                    "400": {
                        "description": "Error response if the account name parameter is less than minimum characters",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    },
                    "404": {
                        "description": "Error response if the account is not supported by service or account is not found",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            },
            "delete": {
                "operationId": "DeleteAccount",
                "summary": "Deletes an account",
                "description": "Deletes the account with specific name",
                "consumes": ["text/plain"],
                "produces": ["application/json"],
                "parameters": [{
                    "name": "accountName",
                    "in": "path",
                    "required": true,
                    "type": "string",
                    "description": "Name of the account"
                }],
                "responses": {
                    "204": {
                        "description": "The response when system finds an account with given name",
                        "schema": {
                            "type": "string"
                        }
                    },
                    "400": {
                        "description": "Error response if the account name parameter is less than minimum characters",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    },
                    "404": {
                        "description": "Error response if the account is not supported by service or account is not found",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            },
            "post": {
                "operationId": "addAccount",
                "summary": "Add an account",
                "description": "Add an account to the database",
                "consumes": ["text/plain"],
                "produces": ["application/json"],
                "parameters": [{
                    "name": "accountName",
                    "in": "path",
                    "required": true,
                    "type": "string",
                    "description": "Name of the account"
                }, {
                    "name": "accountType",
                    "in": "query",
                    "required": true,
                    "type": "string",
                    "description": "The type of account"
                }],
                "responses": {
                    "201": {
                        "description": "The response when the account does not already exist and we can create one",
                        "schema": {
                            "$ref": "#/definitions/accountDetails"
                        }
                    },
                    "409": {
                        "description": "The response when the account already exists and we cannot create one",
                        "schema": {
                            "$ref": "#/definitions/accountDetails"
                        }
                    },
                    "400": {
                        "description": "Error response if the account name parameter is less than minimum characters",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    },
                    "404": {
                        "description": "Error response if the account is not supported by service or account is not found",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            },
            "put": {
                "operationId": "updateAccount",
                "summary": "Updates an account",
                "description": "Updates the account with specified name",
                "consumes": ["text/plain"],
                "produces": ["application/json"],
                "parameters": [{
                    "name": "accountName",
                    "in": "path",
                    "required": true,
                    "type": "string",
                    "description": "Name of the account"
                }, {
                    "name": "accountType",
                    "in": "query",
                    "required": true,
                    "type": "string",
                    "description": "The type of account"
                }],
                "responses": {
                    "200": {
                        "description": "The response when system finds an account with given name",
                        "schema": {
                            "$ref": "#/definitions/accountDetails"
                        }
                    },
                    "400": {
                        "description": "Error response if the account name parameter is less than minimum characters",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    },
                    "404": {
                        "description": "Error response if the account is not supported by service or account is not found",
                        "schema": {
                            "$ref": "#/definitions/errorModel"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "accountDetails": {
            "required": ["id", "name", "type", "availableBal"],
            "properties": {
                "id": {
                    "type": "string",
                    "description": "id"
                },
                "name": {
                    "type": "string",
                    "description": "name"
                },
                "type": {
                    "type": "string",
                    "description": "type"
                },
                "availableBal": {
                    "type": "string",
                    "description": "availableBal"
                }
            }
        },
        "errorModel": {
            "required": ["errorCode", "errorMessage"],
            "properties": {
                "errorCode": {
                    "type": "string",
                    "description": "A service-specific error code."
                },
                "errorMessage": {
                    "type": "string",
                    "description": "A service-specific error code."
                }
            }
        }
    }
}
pip install pylint
pyreverse -o png <path_to_src>
{
    "messageId": "PfNxko2cChY94KsiU9cvUL",
    "eventId": "client.updated",    
    "eventSchemaVersion": 1.0,
    "eventInstanceOriginationDateTime": "2022-03-07T00:37:23Z",
    "eventData": {
        "siteId": 123,
        "saleId": 96,
        "purchasingClientId": "100001049",
        "payments": [
            {
                "paymentId": 103,
                "paymentMethodId": 14,
                "paymentMethodName": "Cash",
                "paymentAmountPaid": 300,
                "paymentLastFour": null,
                "paymentNotes": null
            }
        ],
        "saleDateTime": "2018-05-03T16:52:23Z",
        "soldById": 10,
        "soldByName": "Jane Doe",
        "locationId": 1,
        "totalAmountPaid": 150,
        "items": [
            {
                "itemId": 78,
                "type": "Service",
                "name": "10 Punch Pass",
                "amountPaid": 150,
                "amountDiscounted": 0,
                "quantity": 1,
                "recipientClientId": "100000009",
                "paymentReferenceId": 44
            },
            {
                "itemId": 79,
                "type": "Service",
                "name": "10 Kick Pass",
                "amountPaid": 150,
                "amountDiscounted": 0,
                "quantity": 1,
                "recipientClientId": "100000009",
                "paymentReferenceId": 44
            }
        ]
    }
}
public class Sale {
public String messageId;
public String eventId;
public Decimal eventSchemaVersion;
public String eventInstanceOriginationDateTime;
public SaleEventData eventData;
}


public class SaleEventData {
public Integer siteId;
public Integer saleId;
public String purchasingClientId;
public List<PaymentDetails> payments;
public String saleDateTime;
public String soldById;
public String soldByName;
public Integer locationId;
public Integer totalAmountPaid;
public List<SaleItemDetails> items;
}

public class PaymentDetails {
public Integer paymentId;
public Integer paymentMethodId;
public String paymentMethodName;
public String paymentAmountPaid;
public Integer paymentLastFour;
public String paymentNotes;
}

public class SaleItemDetails {
public Integer itemId;
public String type;
public String name;
public Integer amountPaid;
public Integer amountDiscounted;
public Integer quantity;
public String recipientClientId;
public Integer paymentReferenceId;
}

Sale mbSale = (Sale)JSON.deserialize(jsonInput, Sale.class);
/* JSON EXAMPLE
{
    "messageId": "PfNxko2cChY94KsiU9cvUL",
    "eventId": "client.updated",    
    "eventSchemaVersion": 1.0,
    "eventInstanceOriginationDateTime": "2022-03-07T00:37:23Z",
    "eventData": {
        "siteId": 123,
        "saleId": 96,
        "purchasingClientId": "100001049",
        "payments": [
            {
                "paymentId": 103,
                "paymentMethodId": 14,
                "paymentMethodName": "Cash",
                "paymentAmountPaid": 300,
                "paymentLastFour": null,
                "paymentNotes": null
            }
        ],
        "saleDateTime": "2018-05-03T16:52:23Z",
        "soldById": 10,
        "soldByName": "Jane Doe",
        "locationId": 1,
        "totalAmountPaid": 150,
        "items": [
            {
                "itemId": 78,
                "type": "Service",
                "name": "10 Punch Pass",
                "amountPaid": 150,
                "amountDiscounted": 0,
                "quantity": 1,
                "recipientClientId": "100000009",
                "paymentReferenceId": 44
            },
            {
                "itemId": 79,
                "type": "Service",
                "name": "10 Kick Pass",
                "amountPaid": 150,
                "amountDiscounted": 0,
                "quantity": 1,
                "recipientClientId": "100000009",
                "paymentReferenceId": 44
            }
        ]
    }
}*/


public class Sale {
public String messageId;
public String eventId;
public Decimal eventSchemaVersion;
public String eventInstanceOriginationDateTime;
public SaleEventData eventData;
}


public class SaleEventData {
public Integer siteId;
public Integer saleId;
public String purchasingClientId;
public List<PaymentDetails> payments;
public String saleDateTime;
public String soldById;
public String soldByName;
public Integer locationId;
public Integer totalAmountPaid;
public List<SaleItemDetails> items;
}

public class PaymentDetails {
public Integer paymentId;
public Integer paymentMethodId;
public String paymentMethodName;
public String paymentAmountPaid;
public Integer paymentLastFour;
public String paymentNotes;
}

public class SaleItemDetails {
public Integer itemId;
public String type;
public String name;
public Integer amountPaid;
public Integer amountDiscounted;
public Integer quantity;
public String recipientClientId;
public Integer paymentReferenceId;
}

Sale mbSale = (Sale)JSON.deserialize(jsonInput, Sale.class);
/* JSON EXAMPLE
{
    "messageId": "PfNxko2cChY94KsiU9cvUL",
    "eventId": "client.updated",    
    "eventSchemaVersion": 1.0,
    "eventInstanceOriginationDateTime": "2022-03-07T00:37:23Z",
    "eventData": {
        "siteId": 123,
        "saleId": 96,
        "purchasingClientId": "100001049",
        "payments": [
            {
                "paymentId": 103,
                "paymentMethodId": 14,
                "paymentMethodName": "Cash",
                "paymentAmountPaid": 300,
                "paymentLastFour": null,
                "paymentNotes": null
            }
        ],
        "saleDateTime": "2018-05-03T16:52:23Z",
        "soldById": 10,
        "soldByName": "Jane Doe",
        "locationId": 1,
        "totalAmountPaid": 150,
        "items": [
            {
                "itemId": 78,
                "type": "Service",
                "name": "10 Punch Pass",
                "amountPaid": 150,
                "amountDiscounted": 0,
                "quantity": 1,
                "recipientClientId": "100000009",
                "paymentReferenceId": 44
            },
            {
                "itemId": 79,
                "type": "Service",
                "name": "10 Kick Pass",
                "amountPaid": 150,
                "amountDiscounted": 0,
                "quantity": 1,
                "recipientClientId": "100000009",
                "paymentReferenceId": 44
            }
        ]
    }
}*/


public class Sale {
public String messageId;
public String eventId;
public Decimal eventSchemaVersion;
public String eventInstanceOriginationDateTime;
public SaleEventData eventData;
}


public class SaleEventData {
public Integer siteId;
public Integer saleId;
public String purchasingClientId;
public List<PaymentDetails> payments;
public String saleDateTime;
public String soldById;
public String soldByName;
public Integer locationId;
public Integer totalAmountPaid;
public List<SaleItemDetails> items;
}

public class PaymentDetails {
public Integer paymentId;
public Integer paymentMethodId;
public String paymentMethodName;
public String paymentAmountPaid;
public Integer paymentLastFour;
public String paymentNotes;
}

public class SaleItemDetails {
public Integer itemId;
public String type;
public String name;
public Integer amountPaid;
public Integer amountDiscounted;
public Integer quantity;
public String recipientClientId;
public Integer paymentReferenceId;
}

Sale mbSale = (Sale)JSON.deserialize(jsonInput, Sale.class);
Select id, name, Parent__r.name, Parent__r.id from Child__c

Select id, name, Parent__r.name,(SELECT id, name, amount__c FROM Children__r) from Parent__c
public Boolean mapContains(Map<id,Object> searchObj, String searchKey, String searchVal){
	for (ID idKey : searchObj.keyset()) {
		System.debug(searchObj.get(idKey).get(searchKey));
		if( searchObj.get(idKey).get(searchKey) == searchVal) {
			System.debug('Match Found'+ searchObj.get(idKey));
			return true;
		}else{
			System.debug('No Match');

		}
	}
	return false;
}
// Remove class from body tag
function alpha_body_class($classes){
   unset($classes[array_search('class-one', $classes)]);
   unset($classes[array_search('class-two', $classes)]);
   unset($classes[array_search('class-three', $classes)]);
   return $classes;
}
add_filter('body_class', 'alpha_body_class');
Map<String,String> theOne = new Map<String,String>();
Map<String,String> theTwo = new Map<String,String>();

theOne.put('task', 'Active');
theOne.put('task2', 'Inactive');
theOne.put('task3', 'Inactive');
theOne.put('task4', 'Inactive');

theTwo.put('task', 'Active');
theTwo.put('task2', 'Inactive');
theTwo.put('task3', 'Inactive');
theTwo.put('task4', 'Inactive');

void toggleActive(String taskName, Map<String,String> taskMap){
    taskMap.put(taskName, 'Active'); 
    for(String key : taskMap.keySet()){
        if(key != taskName){
       	 taskMap.put(key, 'Inactive');
        }
    }
}

toggleActive('task3', theTwo);

System.debug(theOne);
System.debug(theTwo);
Human fred = new Human();

fred.setName('Fred');
fred.setAge(18);

fred.Run();
fred.Jump();
fred.Climb();
public class Human {
    public String Name;
    public Integer Age;
    
    public Human(){
      this.Age = 0;
    }
        
    public void setName(String Name){
        this.Name = Name;
    } 
    
    public void setAge(String Name){
        this.Age = Age;
    } 
    
    public void Run(){
        System.debug('Run');
    } 
    
    public void Jump(){
        System.debug('Jump');
    } 
    
    public void Climb(){
        System.debug('Climb');
    } 
}
enum State {
  Visited,
  Unvisited,
  Visiting    
}
class Node {
    State state;
    public Node() {
        // say something about the state
    }
}
star

Mon Sep 05 2022 14:42:44 GMT+0000 (UTC)

#python #oop #class #dataclass
star

Sat Jul 02 2022 13:11:23 GMT+0000 (UTC)

#python #mro #oop #class
star

Sat May 14 2022 10:26:29 GMT+0000 (UTC)

#class #remove #body
star

Thu Sep 16 2021 17:38:28 GMT+0000 (UTC) https://www.zenintech.org/blog/creating-your-first-apex-class

#apex #salesforce #static #keywords #class
star

Wed Apr 01 2020 07:05:44 GMT+0000 (UTC) https://stackoverflow.com/questions/60963806/how-can-i-implement-a-class-when-one-of-its-properties-is-an-enum-variable

#java #java #enumvariable #class

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension