-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
34Replies
Custom stylesheet for Force.com site
Hi!
I'm trying to set up a custom stylesheet for a Force.com site, and can't seem to get it working.
Here's what I tried:
I created a Force.com Site which contains 2 pages. I then created a Site Template (basically copied the default one and modified it) and applied it to the Site. Then I created a stylesheet as a Static Resource, via the developer console. I customized the Site Template to use the stylesheet I created via this code:
<apex:stylesheet value="{!URLFOR(!$Resource.GIStyleSheet)}"/>But when I load my site, the stylesheet doesn't seem to be coming through.
Any advice? Thanks!
-
- Esti Leiser
- March 16, 2017
- Like
- 0
- Continue reading or reply
Edit trigger to work after insert too
Here's the trigger:
trigger AddPrimaryContactToOpp on Opportunity (before update) { // THIS TRIGGER WILL OVERWRITE ANY CONTACT DEFINED IN THE CUSTOM FIELD OPPORTUNITY_CONTACT__C ON THE OPPORTUNITY OBJECT. // SET THIS FIELD TO READ ONLY OR CHANGE THE FUNCTIONALITY BELOW TO AVIOD DATA BEING OVERWRITTEN BY MISTAKE... for (Opportunity o : Trigger.new) { // CREATE ARRAY OF ALL CONTACT ROLES ON THIS OPPORTUNITY. THE REASON WHY WE DONT PICK THE PRIMARY CONTACT ROLE ONLY // IS BECAUSE THE PRIMARY FLAG IS NOT SET WHEN LEADS ARE CONVERTED TO OPPORTUNITIES. ONLY WHEN CREATING OPPORTUNITIES // MANUALLY FROM THE CONTACT OBJECT THE IS PRIMARY CHECKBOX IS CHECKED... OpportunityContactRole[] contactRoleArray = [select ContactID, isPrimary from OpportunityContactRole where OpportunityId = :o.id ORDER BY isPrimary DESC, createdDate]; system.debug('>>> contact role array is ' + JSON.serialize(contactRoleArray)); if (contactRoleArray.size() > 0) { // IF PRIMARY IS DEFINED THEN THIS WILL BE THE FIRST OBJECT. IF NOT THE FIRST ADDED CONTACT ROLE WILL BE ADDED... o.Contact__c = contactRoleArray[0].ContactID; } system.debug('>>> contact__c is ' + o.Contact__c); } }Adding before insert didn't work because the OCRs are not yet created. Adding after insert didn't work either - it gave an error.
Any ideas? Thanks!
PS: this code is not bulkified (I think), so I'd love to take care of that too!
-
- Esti Leiser
- December 24, 2014
- Like
- 0
- Continue reading or reply
how to access the accountname from the contact (in a trigger)
Hi! I'm working on a trigger, and hit an issue that I can't figure out.
I have a map of String,String, where the first string refers to a contact name, and the second one refers to the account name of that contact. I am populating the map inside a loop, where the variable I have to work with is c - referring to a contact.
How do I get the account name from the contact, to add it to the map?
Here's my code so far:
Map<String,String> accountsMap = new Map<String,String> (); for (Contact c : existingContacts){ accountsMap.put(c.FirstName + ' ' + c.LastName, c.AccountName); }
but c.AccountName does not seem to exist.
Any ideas? Thanks!
-
- Esti Leiser
- December 23, 2014
- Like
- 0
- Continue reading or reply
error trying to bulkify a trigger
I'm trying to bulkify a trigger, and am getting an error I don't understand.
Here's the trigger:
trigger AddWebLeadToTripCampaign on Lead (after insert) { List<CampaignMember> CMToInsert = new List<CampaignMember> (); CampaignMember[] cms = new CampaignMember[0]; for(Lead record:Trigger.new) try{ if(!String.isBlank(record.Trip_Name__c)) { String cname = record.Trip_Name__c+' '+record.Trip_Date__c; cname = cname.trim(); //System.debug('the value of cname is >>>>> ' + cname); for(Campaign CID : [select id, name from Campaign where name = :cname]){ cms.add(new CampaignMember(LeadId=record.Id,CampaignId=CID.id)); } } CMToInsert.add(cms); }catch (Exception e){ system.debug('The following exception has occurred: ' + e.getMessage()); } insert CMToInsert; }The error I'm getting is
Incompatible element type LIST<CampaignMember> for collection of SOBJECT:CampaignMember
Any idea what I'm doing wrong?
Thanks!
-
- Esti Leiser
- December 17, 2014
- Like
- 0
- Continue reading or reply
apex test not running? (Says 0/0 test methods passed)
I googled a bunch but couldn't find an answer, so I'm hoping you guys can help. I'm posting my trigger and class. The trigger acts when a lead is converted. What it does is populate a lookup field on the converted opportunity (contact__c) with the id of the converted contact.
Thanks in advance!
Trigger:
trigger AddPrimaryContactToConvertedOpp on Lead (After Update) { // THIS TRIGGER WILL OVERWRITE ANY CONTACT DEFINED IN THE CUSTOM FIELD CONTACT__C ON THE OPPORTUNITY OBJECT. // SET THIS FIELD TO READ ONLY OR CHANGE THE FUNCTIONALITY BELOW TO AVIOD DATA BEING OVERWRITTEN BY MISTAKE... // [1] - Build map of converted Oppo Id to converted contactId map <Id,Id> oIdToCIdMap = new map <Id,Id>(); for (Lead l : Trigger.new) if (l.IsConverted && l.convertedOpportunityId != null) oIdToCIdMap.put(l.convertedOpportunityId,l.convertedContactId); // [2] Update the converted Oppos List<Opportunity> oUpdList = new List<Opportunity> (); for (ID oId : oIdToCIdMap.keySet()) oUpdList.add(new Opportunity(id = oId, contact__c = oIdToCIdMap.get(oId))); update oUpdList; // could be Database.update(oUpdList,false) if you want partial successes }Test class:
@isTest public class TestAddPrimaryCToConvertedOppTrigger { static void testInsertLead(){ Lead L1 = new Lead(LastName='last',FirstName='first',company='company'); insert L1; Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(L1.id); test.startTest(); Database.LeadConvertResult lcr = Database.convertLead(lc); Contact C1 = [SELECT Id FROM Contact WHERE Id = :L1.ConvertedContactId]; Opportunity O1 = [SELECT Id FROM Opportunity WHERE Id = :L1.ConvertedOpportunityId]; system.AssertEquals(O1.Contact__c,C1.ID); test.stopTest(); } }
-
- Esti Leiser
- December 15, 2014
- Like
- 0
- Continue reading or reply
in apex trigger, limit 1 is not working
I am working on an apex trigger to add new leads to the appriate campaign, based on two of the lead fields: Trip Name and Trip Date. The campaign would be named Trip Name Trip Date, with a space between the name and the date.
Here's the trigger:
trigger AddWebLeadToTripCampaign on Lead (after insert) { CampaignMember[] cms = new CampaignMember[0]; for(Lead record:Trigger.new) try{ if(!String.isBlank(record.Trip_Name__c)) { String cname = record.Trip_Name__c+' '+record.Trip_Date__c; cname = cname.trim(); System.debug('the value of cname is >>>>> ' + cname); List <Campaign> CIDs = [select id, name from Campaign where name = :cname limit 1]; System.debug('the list of CIDs is >>>>> ' + CIDs); String CID = [SELECT ID FROM Campaign].ID; cms.add(new CampaignMember(LeadId=record.Id,CampaignId=CID)); } insert cms; }catch (Exception e){ system.debug('The following exception has occurred: ' + e.getMessage()); } }For some reason it doesn't seem to be working. In the debug log I get an error:
USER_DEBUG|[16]|DEBUG|The following exception has occurred: List has more than 1 row for assignment to SObject
But shouldn't the "limit 1" in the query fix that?
Thanks for your help!
-
- Esti Leiser
- June 19, 2014
- Like
- 0
- Continue reading or reply
Custom stylesheet for Force.com site
Hi!
I'm trying to set up a custom stylesheet for a Force.com site, and can't seem to get it working.
Here's what I tried:
I created a Force.com Site which contains 2 pages. I then created a Site Template (basically copied the default one and modified it) and applied it to the Site. Then I created a stylesheet as a Static Resource, via the developer console. I customized the Site Template to use the stylesheet I created via this code:
<apex:stylesheet value="{!URLFOR(!$Resource.GIStyleSheet)}"/>But when I load my site, the stylesheet doesn't seem to be coming through.
Any advice? Thanks!
- Esti Leiser
- March 16, 2017
- Like
- 0
- Continue reading or reply
Pass IDs of selected records in list view into a flow
However, I now want to do this but starting from a list view, where I would select (check) a bunch of records and then click a custom button to start the flow, and have the record IDs of all the checked records pass into the flow as a list of variables (I think it would be an sObject variable?)
Is this possible?
Thanks
- Benzy
- February 20, 2015
- Like
- 3
- Continue reading or reply
Edit trigger to work after insert too
Here's the trigger:
trigger AddPrimaryContactToOpp on Opportunity (before update) { // THIS TRIGGER WILL OVERWRITE ANY CONTACT DEFINED IN THE CUSTOM FIELD OPPORTUNITY_CONTACT__C ON THE OPPORTUNITY OBJECT. // SET THIS FIELD TO READ ONLY OR CHANGE THE FUNCTIONALITY BELOW TO AVIOD DATA BEING OVERWRITTEN BY MISTAKE... for (Opportunity o : Trigger.new) { // CREATE ARRAY OF ALL CONTACT ROLES ON THIS OPPORTUNITY. THE REASON WHY WE DONT PICK THE PRIMARY CONTACT ROLE ONLY // IS BECAUSE THE PRIMARY FLAG IS NOT SET WHEN LEADS ARE CONVERTED TO OPPORTUNITIES. ONLY WHEN CREATING OPPORTUNITIES // MANUALLY FROM THE CONTACT OBJECT THE IS PRIMARY CHECKBOX IS CHECKED... OpportunityContactRole[] contactRoleArray = [select ContactID, isPrimary from OpportunityContactRole where OpportunityId = :o.id ORDER BY isPrimary DESC, createdDate]; system.debug('>>> contact role array is ' + JSON.serialize(contactRoleArray)); if (contactRoleArray.size() > 0) { // IF PRIMARY IS DEFINED THEN THIS WILL BE THE FIRST OBJECT. IF NOT THE FIRST ADDED CONTACT ROLE WILL BE ADDED... o.Contact__c = contactRoleArray[0].ContactID; } system.debug('>>> contact__c is ' + o.Contact__c); } }Adding before insert didn't work because the OCRs are not yet created. Adding after insert didn't work either - it gave an error.
Any ideas? Thanks!
PS: this code is not bulkified (I think), so I'd love to take care of that too!
- Esti Leiser
- December 24, 2014
- Like
- 0
- Continue reading or reply
how to access the accountname from the contact (in a trigger)
Hi! I'm working on a trigger, and hit an issue that I can't figure out.
I have a map of String,String, where the first string refers to a contact name, and the second one refers to the account name of that contact. I am populating the map inside a loop, where the variable I have to work with is c - referring to a contact.
How do I get the account name from the contact, to add it to the map?
Here's my code so far:
Map<String,String> accountsMap = new Map<String,String> (); for (Contact c : existingContacts){ accountsMap.put(c.FirstName + ' ' + c.LastName, c.AccountName); }
but c.AccountName does not seem to exist.
Any ideas? Thanks!
- Esti Leiser
- December 23, 2014
- Like
- 0
- Continue reading or reply
error trying to bulkify a trigger
I'm trying to bulkify a trigger, and am getting an error I don't understand.
Here's the trigger:
trigger AddWebLeadToTripCampaign on Lead (after insert) { List<CampaignMember> CMToInsert = new List<CampaignMember> (); CampaignMember[] cms = new CampaignMember[0]; for(Lead record:Trigger.new) try{ if(!String.isBlank(record.Trip_Name__c)) { String cname = record.Trip_Name__c+' '+record.Trip_Date__c; cname = cname.trim(); //System.debug('the value of cname is >>>>> ' + cname); for(Campaign CID : [select id, name from Campaign where name = :cname]){ cms.add(new CampaignMember(LeadId=record.Id,CampaignId=CID.id)); } } CMToInsert.add(cms); }catch (Exception e){ system.debug('The following exception has occurred: ' + e.getMessage()); } insert CMToInsert; }The error I'm getting is
Incompatible element type LIST<CampaignMember> for collection of SOBJECT:CampaignMember
Any idea what I'm doing wrong?
Thanks!
- Esti Leiser
- December 17, 2014
- Like
- 0
- Continue reading or reply
Help with Querying all Fields on an Object
I want to be able to query for all creatable fields on an object without having to hardcode each field into the SOQL query. I have a method that builds the SOQL query and it works great except for when the WHEN statement includes id in: a collection of records.
Here is the method:
/** *Returns a dynamic SOQL statement for the whole object, includes only creatable fields since we will be inserting a cloned result of this query */ public static string getCreatableFieldsSOQL(String objectName, String whereClause){ String selects = ''; if(whereClause == null || whereClause == ''){ return null; } //get a map of field names and field tokens Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap(); List<String> selectFields = new List<String>(); if(fMap!=null){ for(Schema.SObjectField ft : fMap.values()){ //loop through all field tokens (ft) Schema.DescribeFieldResult fd = ft.getDescribe(); //describe each field (fd) if (fd.isCreateable()){ //field is creatable selectFields.add(fd.getName()); } } }
Here is where I invoke the method:
String oppSOQL = CSUtils.getCreatableFieldsSOQL('Opportunity', 'id in' + clonedFromOppIDs); system.debug('[MF] oppSOQL: ' + oppSOQL); for(Opportunity opp : (List<Opportunity>)Database.query(oppSOQL)){ ClonedOppIDtoClonedOpp.put(opp.id, opp); }
"clonedFromOppIDs" is a set of Opportunity IDs. However, when I try to execute this code I get the error message: System.QueryException: unexpected token: '{' . This is the debug log (I removed most of the fields to make it easier to read):
16:56:07.493 (493363000)|USER_DEBUG|[28]|DEBUG|[MF] oppSOQL: SELECT ApprovedTerms__c,Rate_Type__c,WhatChanged__c FROM Opportunity WHERE id in{006Q000000BmT4XIAV} 16:56:07.493 (493388000)|SYSTEM_METHOD_EXIT|[28]|System.debug(ANY) 16:56:07.493 (493412000)|SYSTEM_METHOD_ENTRY|[30]|Database.query(String) 16:56:07.494 (494079000)|EXCEPTION_THROWN|[30]|System.QueryException: unexpected token: '{'
I've tried making the WHERE clause 'id in: ' + clonedFromOppIDs but I get the same error message. Does anyone know if there is anyway I can get around this? Or have other suggestions for how to systematically query all fields without typing each one it? Any help would be much appreciated, thank you!!
- mgodsey
- September 10, 2013
- Like
- 0
- Continue reading or reply