Skip to content

Instantly share code, notes, and snippets.

View sfdcfanboy's full-sized avatar

sfdcFanBoy sfdcfanboy

View GitHub Profile
HTTPRequest feedRequest = new HTTP Request();
feedRequest.setEndpoint('callout:SalesforceNC/services/data/v32.0');
feedRequest.setMethod('GET');
HTTP http = new HTTP();
HTTPResponse feedResponse = http.send(feedRequest);
System.debug(feedResponse.getBody());
HttpRequest req = new HttpRequest();
req.setEndpoint('https://my_endpoint.example.com/some_path');
req.setMethod('GET');
// Because we didn't set the endpoint as a named credential,
// our code has to specify:
// - The required username and password to access the endpoint
// - The header and header information
String username = 'myname';
//product1
Product2 p = new Product2();
p.Name = 'Test Product';
p.Description = 'Test desc';
p.IsActive = true;
insert p;
//standard price book entry for Product p
PricebookEntry pbe1 = new PricebookEntry();
pbe1.Pricebook2Id = Test.getStandardPricebookId();
global with sharing class OppsWithMatches{
global List<Opportunity> Opps{get;set;}
global String accountId{get;set;}
global account account{
get {
Account = [Select Id, name from Account where id =: accountId];
return account; }
set;
}
public class ApprovalProcessor {
webservice void submitAndProcessApprovalRequest() {
// Create an approval request for the account
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(a.id);
@sfdcfanboy
sfdcfanboy / CopyTypeToAccountType
Created July 19, 2017 08:57
Run in developer console anonymous code
List<Account> accList = [SELECT id,type,customer_type__c FROM account WHERE type!=null LIMIT 200];
for(account a:accList){
a.customer_type__c = a.type;
}
update accList;
trigger OppTrigger on Opportunity (after insert, before update) {
Map<String, Id> typeMap = New Map<ID,RecordType>();
for(RecordType rt: [Select ID, DeveloperName From RecordType Where sObjectType = 'Opportunity']) {
typeMap.put(rt.DeveloperName, rt.id);
}
for (Opportunity opp : trigger.new) {
// And the Agreement Category on the record = TEST
if (opp.Stage__c == 'Negotiation/Review') {
// Query the accounts to lock
Account[] accts = [SELECT Id from Account WHERE Name LIKE 'Acme%'];
// Lock the accounts
Approval.LockResult[] lrList = Approval.lock(accts, false);
// Iterate through each returned result
for(Approval.LockResult lr : lrList) {
if (lr.isSuccess()) {
// Operation was successful, so get the ID of the record that was processed
System.debug('Successfully locked account with ID: ' + lr.getId());
<apex:component access="global" controller="OppsWithMatches">
<apex:attribute name="accountIdValue" type="String" description="This is the Id of the account" assignTo="{!accountId}" access="global" />
<table class="table">
<thead>
<tr>
<th>Opportunity Name</th>
<th>Opportunity Description</th>
<th>Opportunity Amount</th>
<messaging:emailTemplate subject="Opportunities to verify" recipientType="Contact" relatedToType="Account">
<messaging:htmlEmailBody >
Good Morning! Here are the opporunities that needs verification. <br/><br/>
<c:OpportunitiesToVerify accountIdValue="{!relatedTo.Id}" />
ref: {!relatedTo.id}
</messaging:htmlEmailBody>