-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
8Questions
-
20Replies
Trigger to update custom field in Events
trigger EventUpdate on Event (before insert, before update) {
for (Event a = Trigger.new){
List<Event,Id> Event = new List<Id>([SELECT Id from Event where Id IN : trigger.newList.keySet() ]);
if (event.Description != null){
a.customfield__c = event.Description;
} else {
a.customfield_copy__c = null;
}
}
}
-
- Amanda Ream
- October 15, 2015
- Like
- 0
- Continue reading or reply
Create a trigger for new user
trigger AutoUserCreate on User (after update) {
List<User> UserList = new List<User>();
for( Support_Request__c sr : Trigger.new) {
if (sr.status__c == 'in progress'){
User newUser = new User ();
string newUser.FirstName = Support_Request__c.First_Name__c;
string newUser.LastName = Support_Request__c.Last_Name__c;
insert UserList;
}
}
}
-
- Amanda Ream
- January 22, 2015
- Like
- 0
- Continue reading or reply
Is there anyway to mass change profile assignments?
-
- Amanda Ream
- December 22, 2014
- Like
- 0
- Continue reading or reply
Trigger to Create a Roll-up Summary Field on a Hierarchial Lookup Relationship.
If so, I found some sample code on this site (http://blog.jeffdouglas.com/2009/07/30/roll-up-summary-fields-with-lookup-relationships-part-1/) that demostrates how to do this between two separate objects but I am having a little trobule translating. This is pretty complex compared to the triggers I have been able to write before so my second question pertains to a section of the code I don't understand. What exactly is the bolded part of the code doing? I have read about for loops and if statements but this is more complex than anything I have ever seen. Any help is much appreciated :)
trigger InventoryItemRollup on Inventory_Item__c (after delete, after insert, after update) {
Set<id> shipmentIds = new Set<id>();
List<shipment__c> shipmentsToUpdate = new List<shipment__c>();
for (Inventory_Item__c item : Trigger.new)
shipmentIds.add(item.Shipment__c);
if (Trigger.isUpdate || Trigger.isDelete) {
for (Inventory_Item__c item : Trigger.old)
shipmentIds.add(item.Shipment__c);
}
// get a map of the shipments with the number of items
Map<id,Shipment__c> shipmentMap = new Map<id,Shipment__c>([select id, items__c from Shipment__c where id IN :shipmentIds]);
// query the shipments and the related inventory items and add the size of the inventory items to the shipment's items__c
for (Shipment__c ship : [select Id, Name, items__c,(select id from Inventory_Items__r) from Shipment__c where Id IN :shipmentIds]) {
shipmentMap.get(ship.Id).items__c = ship.Inventory_Items__r.size();
// add the value/shipment in the map to a list so we can update it
shipmentsToUpdate.add(shipmentMap.get(ship.Id)); }
update shipmentsToUpdate;
}
-
- Amanda Ream
- October 24, 2014
- Like
- 0
- Continue reading or reply
Insert a Google Maps VisualForce Page into a Custom Object
<apex:page standardController="Equipment__c">
<apex:pageBlock >
<head>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var myOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.MAP,
mapTypeControl: true
}
var map;
var marker;
var geocoder = new google.maps.Geocoder();
var address = "{!Equipment__c.GeoLocationText__c}";
var infowindow = new google.maps.InfoWindow({
content: "<b>{!Equipment__c.Equipment_Address__c}</b>"
});
geocoder.geocode( { address: address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
//create map
map = new google.maps.Map(document.getElementById("map"), myOptions);
//center map
map.setCenter(results[0].geometry.location);
map.panBy(0,200);
//create marker
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: "{!Equipment__c.Equipment_Address__c}"
});
//add listeners
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
google.maps.event.addListener(map, 'zoom_changed', function() {
if (this.getZoom() < 8) this.setZoom(8);
});
}
} else {
$('#map').css({'height' : '15px'});
$('#map').html("Oops! {!Equipment__c.Equipment_Address__c}'s address could not be found, please make sure the address is correct.");
resizeIframe();
}
});
function resizeIframe() {
var me = window.name;
if (me) {
var iframes = parent.document.getElementsByName(me);
if (iframes && iframes.length == 1) {
height = document.body.offsetHeight;
iframes[0].style.height = height + "px";
}
}
}
});
</script>
<style>
#map {
font-family: Arial;
font-size:12px;
line-height:normal !important;
height:500px;
background:transparent;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</apex:pageBlock>
</apex:page>
-
- Amanda Ream
- July 25, 2014
- Like
- 0
- Continue reading or reply
Apex Trigger Change Set Failed because Sandbox Environment is on Summer 14' and Production is Still on Spring 14'
"All components failed Version Compatibility Check.
Every component in this change set requires the "31.0" or higher platform version. Please select an organization with a platform version of "31.0" or higher"
What do I do in this situation, wait until Production has been upgraded to Summer 14'?
-
- Amanda Ream
- June 19, 2014
- Like
- 0
- Continue reading or reply
Change set error In field: page - no ApexPage named
-
- Amanda Ream
- May 12, 2014
- Like
- 0
- Continue reading or reply
Trigger a Chatter Post when an Opportunity is won
I am an APEX newbie trying to create a trigger that posts when an Opp is won. I have no other requirements besides that the when an Opportunity is updated to the won stage, it posts a pedesigned message to a specific Chatter Group. I took the code from another post (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009AFJIA2) and tried to modify it to do just that but I am running into a problem in the IDE at the "for" line, with the error stating "Save error: Loop must iterate over collection type: Boolen". I tried to add an else statement to break and exit the loop but that gave me a bracket error. Am I totally off base here? Should I pulling a list first for the function to iterate over? Any help would be much appreciated! Thanks!
trigger ChatterPostWonOpp on Opportunity (after update) {
String status;
String OppAccName;
String OppOwnerName;
FeedItem post = new FeedItem();
for(Opportunity o : Trigger.isupdate) {
if(o.IsWon == true ) //This will be executed on new record insertion when Opp is won
for (Opportunity oppty : [SELECT Account.Name, Owner.Name FROM Opportunity])
{
OppAccName = oppty.Account.Name;
OppOwnerName = oppty.Owner.Name;
}
status = OppOwnerName + ' just won ' + OppAccName + ' for ' + o.Amount + '!';
post.ParentId = '0F9g00000008b7c';
post.Title = o.Name;
post.Body = status;
insert post;
}
}
-
- Amanda Ream
- April 09, 2014
- Like
- 0
- Continue reading or reply
Trigger to update custom field in Events
trigger EventUpdate on Event (before insert, before update) {
for (Event a = Trigger.new){
List<Event,Id> Event = new List<Id>([SELECT Id from Event where Id IN : trigger.newList.keySet() ]);
if (event.Description != null){
a.customfield__c = event.Description;
} else {
a.customfield_copy__c = null;
}
}
}
- Amanda Ream
- October 15, 2015
- Like
- 0
- Continue reading or reply
Create a trigger for new user
trigger AutoUserCreate on User (after update) {
List<User> UserList = new List<User>();
for( Support_Request__c sr : Trigger.new) {
if (sr.status__c == 'in progress'){
User newUser = new User ();
string newUser.FirstName = Support_Request__c.First_Name__c;
string newUser.LastName = Support_Request__c.Last_Name__c;
insert UserList;
}
}
}
- Amanda Ream
- January 22, 2015
- Like
- 0
- Continue reading or reply
Is there anyway to mass change profile assignments?
- Amanda Ream
- December 22, 2014
- Like
- 0
- Continue reading or reply
Trigger to Create a Roll-up Summary Field on a Hierarchial Lookup Relationship.
If so, I found some sample code on this site (http://blog.jeffdouglas.com/2009/07/30/roll-up-summary-fields-with-lookup-relationships-part-1/) that demostrates how to do this between two separate objects but I am having a little trobule translating. This is pretty complex compared to the triggers I have been able to write before so my second question pertains to a section of the code I don't understand. What exactly is the bolded part of the code doing? I have read about for loops and if statements but this is more complex than anything I have ever seen. Any help is much appreciated :)
trigger InventoryItemRollup on Inventory_Item__c (after delete, after insert, after update) {
Set<id> shipmentIds = new Set<id>();
List<shipment__c> shipmentsToUpdate = new List<shipment__c>();
for (Inventory_Item__c item : Trigger.new)
shipmentIds.add(item.Shipment__c);
if (Trigger.isUpdate || Trigger.isDelete) {
for (Inventory_Item__c item : Trigger.old)
shipmentIds.add(item.Shipment__c);
}
// get a map of the shipments with the number of items
Map<id,Shipment__c> shipmentMap = new Map<id,Shipment__c>([select id, items__c from Shipment__c where id IN :shipmentIds]);
// query the shipments and the related inventory items and add the size of the inventory items to the shipment's items__c
for (Shipment__c ship : [select Id, Name, items__c,(select id from Inventory_Items__r) from Shipment__c where Id IN :shipmentIds]) {
shipmentMap.get(ship.Id).items__c = ship.Inventory_Items__r.size();
// add the value/shipment in the map to a list so we can update it
shipmentsToUpdate.add(shipmentMap.get(ship.Id)); }
update shipmentsToUpdate;
}
- Amanda Ream
- October 24, 2014
- Like
- 0
- Continue reading or reply
Insert a Google Maps VisualForce Page into a Custom Object
<apex:page standardController="Equipment__c">
<apex:pageBlock >
<head>
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var myOptions = {
zoom: 8,
mapTypeId: google.maps.MapTypeId.MAP,
mapTypeControl: true
}
var map;
var marker;
var geocoder = new google.maps.Geocoder();
var address = "{!Equipment__c.GeoLocationText__c}";
var infowindow = new google.maps.InfoWindow({
content: "<b>{!Equipment__c.Equipment_Address__c}</b>"
});
geocoder.geocode( { address: address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK && results.length) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
//create map
map = new google.maps.Map(document.getElementById("map"), myOptions);
//center map
map.setCenter(results[0].geometry.location);
map.panBy(0,200);
//create marker
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map,
title: "{!Equipment__c.Equipment_Address__c}"
});
//add listeners
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
google.maps.event.addListener(map, 'zoom_changed', function() {
if (this.getZoom() < 8) this.setZoom(8);
});
}
} else {
$('#map').css({'height' : '15px'});
$('#map').html("Oops! {!Equipment__c.Equipment_Address__c}'s address could not be found, please make sure the address is correct.");
resizeIframe();
}
});
function resizeIframe() {
var me = window.name;
if (me) {
var iframes = parent.document.getElementsByName(me);
if (iframes && iframes.length == 1) {
height = document.body.offsetHeight;
iframes[0].style.height = height + "px";
}
}
}
});
</script>
<style>
#map {
font-family: Arial;
font-size:12px;
line-height:normal !important;
height:500px;
background:transparent;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</apex:pageBlock>
</apex:page>
- Amanda Ream
- July 25, 2014
- Like
- 0
- Continue reading or reply
Apex Trigger Change Set Failed because Sandbox Environment is on Summer 14' and Production is Still on Spring 14'
"All components failed Version Compatibility Check.
Every component in this change set requires the "31.0" or higher platform version. Please select an organization with a platform version of "31.0" or higher"
What do I do in this situation, wait until Production has been upgraded to Summer 14'?
- Amanda Ream
- June 19, 2014
- Like
- 0
- Continue reading or reply
Too many username matches error while deploying dashboards
I am trying to deploy few reports and dashboards to a fullcopy sandbox 'fc' from another fullcopy sandbox via changeset and I am getting the following error message for dashboards.
Too many username matches for abc@gmail.com. The possible matches are abc@gmail.com.fc, abc@gmail.com; edit the username to match only one.
What des this mean?
- Aneesha
- June 06, 2014
- Like
- 0
- Continue reading or reply
Change set error In field: page - no ApexPage named
- Amanda Ream
- May 12, 2014
- Like
- 0
- Continue reading or reply
Trigger a Chatter Post when an Opportunity is won
I am an APEX newbie trying to create a trigger that posts when an Opp is won. I have no other requirements besides that the when an Opportunity is updated to the won stage, it posts a pedesigned message to a specific Chatter Group. I took the code from another post (https://developer.salesforce.com/forums/ForumsMain?id=906F00000009AFJIA2) and tried to modify it to do just that but I am running into a problem in the IDE at the "for" line, with the error stating "Save error: Loop must iterate over collection type: Boolen". I tried to add an else statement to break and exit the loop but that gave me a bracket error. Am I totally off base here? Should I pulling a list first for the function to iterate over? Any help would be much appreciated! Thanks!
trigger ChatterPostWonOpp on Opportunity (after update) {
String status;
String OppAccName;
String OppOwnerName;
FeedItem post = new FeedItem();
for(Opportunity o : Trigger.isupdate) {
if(o.IsWon == true ) //This will be executed on new record insertion when Opp is won
for (Opportunity oppty : [SELECT Account.Name, Owner.Name FROM Opportunity])
{
OppAccName = oppty.Account.Name;
OppOwnerName = oppty.Owner.Name;
}
status = OppOwnerName + ' just won ' + OppAccName + ' for ' + o.Amount + '!';
post.ParentId = '0F9g00000008b7c';
post.Title = o.Name;
post.Body = status;
insert post;
}
}
- Amanda Ream
- April 09, 2014
- Like
- 0
- Continue reading or reply
Chatter Trigger - Opportunity Closed Won
Hi,
I am looking to send trigger a chatter alert in a group when an opportunity is changed to Closed Won. We are currently using email alerts (AND( ISCHANGED(StageName), Probability = 1, NOT(Owner.Id = "005d0000001TUC8")) but would like to move the interaction to chatter:
Below is my attempt but
1. When I try this I get the error - Compile Error: unexpected token: insert at line 26 column 8
2.As it is in the workflow - I would like to have one person's opportunitiy's (NOT(Owner.Id = 005d0000001TUC8) not trigger this workflow for privacy reasons
Could anyone help me clean this up? Thank you so much!
trigger ChatterWonOpportunity on Opportunity (after insert, after update) {
String status;
String OppAccName;
//Decimal OppAmount;
FeedItem post = new FeedItem();
for(Opportunity o : Trigger.new) {
if(Trigger.isInsert) {
if(o.IsWon == true && Trigger.oldMap.get(o.id).IsWon == false) {
for (Opportunity oppty : [SELECT Account.Name FROM Opportunity WHERE Id =:o.Id] ) {
OppAccName = oppty.Account.Name;
}
o.owner +' just won' + OppAccName + 'for' o.expectedrevenue + ‘!';
}
else {
return;
}
}
post.ParentId = //0F9K000000005LR
post.Title = o.Name;
post.Body = status;
}
}
insert post;
}
}
- Catie
- August 06, 2013
- Like
- 0
- Continue reading or reply