• Damon Shaw
  • NEWBIE
  • 195 Points
  • Member since 2016

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 40
    Replies
We have "Location" field on Opportunity with picklist values and we have "Opp_Location__c" field on the account, this trigger displays the values of "Location" field into "Opp_Location__c" field, how to modify the trigger so i can map the same values and not display it more than once? for ex i have picklist value "Hospital" and if the account has 10 opps with same hospital location then i want to display it only one time 


trigger RollupLocation on Opportunity (after insert, after update) { 
  Map<ID, Account > parentOpps = new Map<ID, Account>(); 
  Set<Id> listIds = new Set<Id>();

  for (Opportunity childObj : Trigger.new) {
    listIds.add(childObj.AccountId);
  }

  parentOpps = new Map<Id, Account>([SELECT id, Opp_Location__c ,
                                        (SELECT ID, Location_Type__c  FROM Opportunities) 
                                    FROM Account WHERE ID IN :listIds]);

  List<Account> lstAccount = new List<Account>();

  for(Account acct:parentOpps.values())
  {  
      List<String> strType = new List<String>();
      for(Opportunity opty:acct.Opportunities)
      {
          strType.add(opty.Location_Type__c);
      }
      acct.Opp_Location__c = String.join(strType,',');

  }

  update parentOpps.values();
}
I followed the instructions here: https://support.zendesk.com/hc/en-us/articles/203660056-Salesforce-Creating-custom-links-in-Salesforce-Zendesk-Ticket#creating-a-trigger

This trigger works except that row 7 assumes that at least 1 record is found. If not it throws an error 'List has no rows for assignment to SObject' if there is not a record available for assignment. 

I found this answer: https://help.salesforce.com/articleView?id=000159853&type=1

And have tried to incorporate it but I keep getting errors. Can anyone give some guidance on how to rewrite this? 

User-added image
Hello Awesome Developers.....

I have the following trigger that should be updating an Apttus Quote Record based on Line Items that are added.  

Ultimately what I am trying to achieve is when a new Apttus config file is created (gets created when a cart is finalized) and is marked finalized for its status, look for the line Items associated with that Apttus config record, and if any of those items has a particualr product code through the product selected to be used and its quantity is greater that 3 then add those records to a list and then for that list update the master Quote record to have a checkbox checked true which will then require an approval to be done.  

Looks like through my debug statements I can see that the records and lists are being treated fine up until line 45 as the master quote record does not get updated.  

Any help on this would be greatly appreciated, and if you need any mor einformation, please ask,

Thanks again,

Shawn

Trigger Code:
 
trigger ColocationCrossConnectApproval on Apttus_Config2__ProductConfiguration__c (before insert, before update) {

    List<Apttus_Config2__LineItem__c> colocationList = new List<Apttus_Config2__LineItem__c>();
    	system.debug('colocationList Size Initial -'+colocationList.size());
    List<Apttus_Config2__LineItem__c> crossConnectList = new List<Apttus_Config2__LineItem__c>();
    	system.debug('crossConnectList Size Initial -'+crossConnectList.size());
    List<Apttus_Config2__ProductConfiguration__c> configRecords = new List<Apttus_Config2__ProductConfiguration__c>();
    	system.debug('configRecords Size Initial -'+configRecords.size());
    
    For(Apttus_Config2__ProductConfiguration__c config : Trigger.new){
        
        If(config.Apttus_Config2__Status__c == 'Finalized'){
                configRecords.add(config);
            	system.debug('configRecords Size After -'+configRecords.size());
        } // End of Status = Finalized If Statement
     } // End of Trigger.New For Loop
    
    If(configRecords.size()>0){
  
    	For(Apttus_Config2__ProductConfiguration__c configToWork : configRecords){
        
            List<Apttus_Config2__LineItem__c> colocationItems = [SELECT ID, Name, Apttus_Config2__OptionId__c,Apttus_Config2__OptionId__r.ProductCode,
                                                                 Apttus_Config2__ConfigurationId__c,Apttus_Config2__Quantity__c,
                                                                 Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.ColocationApprovalRequired__c,
                                                                 Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.CrossConnectApprovalRequired__c 
                                                                 FROM Apttus_Config2__LineItem__c 
                                                                 WHERE Apttus_Config2__ConfigurationId__c IN : configRecords];
            system.debug('colocationItems Size -' + colocationItems.size());
            
            For(Apttus_Config2__LineItem__c coLoItems : colocationItems){
                
                If(coLoItems.Apttus_Config2__OptionId__r.ProductCode == 'SAN-001' && coLoItems.Apttus_Config2__Quantity__c > 3){
                    colocationList.add(coLoItems);
                    	system.debug('colocationList Size After -'+colocationList.size());
                } // End Of Colocation If Statement To Add CoLocation Line Items to colocationList
                
                else If(coLoItems.Apttus_Config2__OptionId__r.ProductCode == 'SAN-002' && coLoItems.Apttus_Config2__Quantity__c > 3) {
                    crossConnectList.add(coLoItems);
                    	system.debug('crossConnectList Size After -'+crossConnectList.size());
                } // End of Else If Statement to add Cross Connect Lines to crossConnectList   
            } // End of Line For Loop   
    	} // End of configToWork For Loop
    } // End Of Bulkify If Statement
    
    If(colocationList.size()>0){
        For(Apttus_Config2__LineItem__c finalcoLoList : colocationList){
            finalcoLoList.Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.ColocationApprovalRequired__c = True;
            Database.update(finalcoLoList);
        } // End of finalcoLoList For Loop
    } // End of colocationList size If Statement
    
    If(crossConnectList.size()>0){
        For(Apttus_Config2__LineItem__c finalcrossList : crossConnectList){
            finalcrossList.Apttus_Config2__ConfigurationId__r.Apttus_QPConfig__Proposald__r.CrossConnectApprovalRequired__c = True;
            Database.update(finalcrossList);
        } // End of finalcrossList For Loop
    } // End of crossconnectList size If Statement    
} // End Of Trigger

 
Hi,
     I have a standard Product page with few fields but here we talk about two fields: 
     1.Formula field with hyperlink to open vfpage on same tab.
     2.Text field to hold Product name

     Now, when I click on formula's hyperlink, a vf page should open and through that vfpage I should search for particular product and select one.
     When I select product from vfpage, the text field in standard page should be filled with the product name.

     What is the ideal way to do this without having JS in formula field's hyperlink ?

Thanks in Advance.
//  Code :

trigger AddDesctoAccount on Account (Before Update) {
 
    Id userId= userinfo.getUserId();
    User UserDetails = [select Id,Username from User where Id= :userId ];
    String uName= UserDetails.Username;
   List<Account> actToUpdate = new List<Account>();
    for(Account acc: Trigger.new){
        actToUpdate.add(acc);
    }
    
    for(Account act: actToUpdate){
        act.Description=uName;
    }
    
    database.update(actToUpdate,false);
    
}




Output:

Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger AddDesctoAccount caused an unexpected exception, contact your administrator: AddDesctoAccount: execution of BeforeUpdate caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.AddDesctoAccount: line 15, column 1



Please Help me with the code.


Thank You,
Prasad
1. I have used Salesforce Napili template to create a new Community. 
2. I have created a new page in this template where I am exposing a new Lightning Component I created. 
3. The lightning component accepts email and phone as two attributes. 
4. These attributes should be passed to the lightning component embedded in the community as URL parameters. I am not able to do this today. 
 
I would like to pass pass parameters to the lightning component inside community using URL parameter like: 
http://<<communityURL>>/<<communityName>>?&email=rama@test.org&phone=999-999-9999 
 
The email and phone parameters from the community URL should be passed to the component included in the community. 
 
I know a way of doing this through lightning applications. I have seen this link: 
http://salesforce.stackexchange.com/questions/106543/lightning-app-getting-url-parameter 
 
But, my usecase is different. I don't have a lightning application. I only have a lightning component embedded in a Salesforce Lightning Community.
 
Please suggest, if this can be done.
I have an address validation visualforce page which is opened from a link on a Case, the redirect to the VF page works fine and the page does what it should outside of the Service Console.

However in the Service Console when the user clicks the save button and the page calls sforce.one.navigateToSObject('{!theCase.Id}'); it opens the case in a new tab, leaving the VF page open. The new tab opens the case it shoud but I don't want it to open in a new tab I want it to redirect the existing tab.

I've tried using sforce.one.back(); and this does the same, as does right clicking on the page and selecting back.

Is there a way to have the VF page redirect in it's current tab or a way of closing the current tab when opening a new one like we can when using in the std service console with sforce.console.closeTab(result.id);

here's a really basic view of the page
<apex:page controller="AddressVerificationController">

    <script type="text/javascript" >
        function closeTab() {
            sforce.one.navigateToSObject('{!theCase.Id}');
        }
    </script>
    
    <apex:form >
        <apex:pageBlock >
            <apex:commandLink action="{!save}" value="Save" type="button" oncomplete="closeTab()"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

and the controller
public with sharing class AddressVerificationController {

    public Case theCase { get; set; }
    
    public AddressVerificationController() {
        this.theCase = [SELECT Id, Address__c FROM Case WHERE Id = :ApexPages.currentpage().getparameters().get('id')];
    }

    public PageReference save(){

        update theCase;        
        return null;
    }
}

 
I tried to use NetworkUserID to retrieve NetworkUserHistoryRecent data but it's returning nothing. I want to get all the information of certain user activities in Community. Is there a way to do that?
I have a Standard Set Controller for a Visualforce Page. The code for the "SaveandReturn" works for saving the main record (the FAIR_Listing__c) but it does not work for saving any of the Lookup Records' fields (Charlie_5_Lookup__r.Agent_Photos_Mandatory_Day_4__c). What is the code to save a Lookup Record in a Standard Set Controller.
public class Pipeline {

    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(                  
                    [Select Name, 
                     Id, OwnerId, 
                     Status__c,
                     Bankruptcy_Lookup__r.Id,  
                     Charlie_5_Lookup__r.Agent_Photos_Mandatory_Day_4__c, 
                     Charlie_5_Lookup__r.Id,
                     From FAIR_Listing__c WHERE Status__c = 'Active' or Status__c = 'Hold Short Sale' or Status__c = 'Hold Standard Sale']));
            }
            return setCon;
        }
        set;
    }
    
    public List<FAIR_Listing__c> getRecords() {
        return (List<FAIR_Listing__c>) setCon.getRecords();
    }
    
	public void saveandReturn() {
	setcon.save();
	}
}
For a repeating table on a Visualforce page:
 
<apex:page Controller="Pipeline">
    <apex:form >
        <apex:pageBlock >
    <html>
        <head>
            <style>
                
            </style>
        </head>
        <body>                       
            <apex:repeat value="{!records}" var="record">
                <table border = "1" cellpadding = "0" cellspacing = "0">
                    <tr>
                        <th width="100px">Name</th>
                        <th width="200px">Status</th>
                        <th width="100px">Agent Photos</th>
                    </tr>
                    <tr>
                        <td><apex:outputField value="{! record.Name }"/></td>
                        <td><apex:inputField value="{! record.Status__c }"/></td>
                        <td><apex:inputField value="{! record.Charlie_5_Lookup__r.Agent_Photos_Mandatory_Day_4__c }"/></td>
                    </tr>
                </table>
                <br/>
            </apex:repeat>
        </body>
    </html>
      <apex:pageBlockButtons >
            <apex:commandButton action="{!saveAndReturn}" value="Save"/>
      </apex:pageBlockButtons>
     </apex:pageBlock>
    </apex:form>
    </apex:page>

 
We have "Location" field on Opportunity with picklist values and we have "Opp_Location__c" field on the account, this trigger displays the values of "Location" field into "Opp_Location__c" field, how to modify the trigger so i can map the same values and not display it more than once? for ex i have picklist value "Hospital" and if the account has 10 opps with same hospital location then i want to display it only one time 


trigger RollupLocation on Opportunity (after insert, after update) { 
  Map<ID, Account > parentOpps = new Map<ID, Account>(); 
  Set<Id> listIds = new Set<Id>();

  for (Opportunity childObj : Trigger.new) {
    listIds.add(childObj.AccountId);
  }

  parentOpps = new Map<Id, Account>([SELECT id, Opp_Location__c ,
                                        (SELECT ID, Location_Type__c  FROM Opportunities) 
                                    FROM Account WHERE ID IN :listIds]);

  List<Account> lstAccount = new List<Account>();

  for(Account acct:parentOpps.values())
  {  
      List<String> strType = new List<String>();
      for(Opportunity opty:acct.Opportunities)
      {
          strType.add(opty.Location_Type__c);
      }
      acct.Opp_Location__c = String.join(strType,',');

  }

  update parentOpps.values();
}
Bear with me as this is my first post on the dev community but looking for some help writing a relatively simple trigger (my first).

I have a related list on the case object called 'dispatch__c'. When a dispatch is updated to a status of 'Closed' I'm simply trying to post a case comment (or Chatter post) back to the related case. The case comment would simply read "Dispatc DISP-0123 was updated to 'Closed'". Is this possible and can someone point me in the right direction?
I am facing issue with Custom Visualforce Grid During Save .
When i click Save Changes Button I am getting below error 

**System.ListException: DML statement found null SObject at position 3
Error is in expression '{!Save1}' in component <apex:commandButton> in page r_gridpage: Class.R_GridClass.Save1: line 24, column 1
Class.R_GridClass.Save1: line 24, column 1** 


Below is my visualforce and Apex codes 

Visualforce Code
----------------

<apex:page standardController="Student__c" extensions="R_GridClass">  
    <apex:form id="formId">
        <apex:pageBlock >
        <apex:pageBlockButtons >
        <apex:commandButton value="Delete Selected Item" action="{!DeleteSelected}"/> 
        <apex:commandButton value="Add Student" action="{!AddSelected}"/> 
        <apex:commandButton value="Save Changes" action="{!Save1}"/>
        <apex:commandButton value="Update Selected Row" action="{!UpdateSelected}"/> 
        </apex:pageBlockButtons>
        <apex:pageBlockTable value="{!studentList}" var="st">
            <apex:column headerValue="Selection">
            <apex:inputCheckbox value="{!st.Selected}"/>
            </apex:column>
                <apex:column headerValue="Name">
                    <apex:inputField value="{!st.std.First_Name__c}" />
                </apex:column>
                <apex:column headerValue="Mobile">
                    <apex:inputField value="{!st.std.Mobile__c}" />
                </apex:column>
                <apex:column headerValue="Email">
                    <apex:inputField value="{!st.std.Email__c}" />
                </apex:column>
                <apex:column headerValue="Occupation">
                    <apex:inputField value="{!st.std.Occupation__c}" />
                </apex:column>
                <apex:column headerValue="DOJ">
                    <apex:inputField value="{!st.std.Date_of_Joining__c}" />
                </apex:column>
            </apex:pageBlockTable>
          <apex:pageBlockButtons >
         <!--<apex:commandButton value="Add New Student" action="{!addNew}"/><br/>-->
         <!--<apex:commandButton value="Save Records" action="{!Save}"/> --->
    </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Apex Code
----------------

public class R_GridClass {
Public List<WrapStudent> studentList {get;set;}
    public R_GridClass(ApexPages.StandardController ctrlr)
    {
      studentList = new List<WrapStudent>();
        for (Student__c stud :[SELECT Id, Name, OwnerId, First_Name__c, Last_Name__c, Mobile__c, Email__c, Date_of_Joining__c, Occupation__c FROM Student__c])
        {
           studentList.add(new WrapStudent(stud)); 
        }
    }
    
    public void AddSelected()
{
   studentList.add(new WrapStudent() );
}  
 public PageReference Save1()
{
List<Student__c> slist = new List<Student__c>();
for (Integer i = 0;i<studentList.size();i++)
{
 slist.add(studentList[i].std );
}
upsert slist;
 System.debug('Size of Selected List is -'+studentList.size());   
   PageReference tempPage = ApexPages.currentPage();            
   tempPage.setRedirect(true);
    return tempPage ;
}  
public PageReference DeleteSelected()
{
    List<Student__c> listToDelete = new List<Student__c>();
    for (WrapStudent wd : studentList)
    {
        if(wd.selected == true)
        {
            listToDelete.add(wd.std);
        }
    }
    if (listToDelete.size()>0)
    {
        
    Delete listToDelete;
        }
   PageReference tempPage = ApexPages.currentPage();            
   tempPage.setRedirect(true);
    return tempPage ;
    
     /*PageReference myVFPage = new PageReference('/'+'a007F000004tfiq');
         return myVFPage;*/

    
    public PageReference UpdateSelected()
{
    List<Student__c> listToUpdate = new List<Student__c>();
    for (WrapStudent wd : studentList)
    {
        if(wd.selected == true)
        {
            listToUpdate.add(wd.std);
        }
    }
    update listToUpdate;
   PageReference tempPage = ApexPages.currentPage();            
   tempPage.setRedirect(true);
    return tempPage ;
    
     /*PageReference myVFPage = new PageReference('/'+'a007F000004tfiq');
         return myVFPage;*/
}  
    
   
    
public class WrapStudent 
{
    
    Public Student__c std {get;set;}
    Public Boolean selected {get;set;} 
    Public WrapStudent (Student__c s)
    {
       std = s;
       selected = false; 
        
    }
    
    Public WrapStudent ()
    {
       
        
    }
}
}



Please help me on the above issue
 
Hi
I have a child object classed OpportunityItem__c that the parent is Opportunity, and in the OpportunityItem__ I have a relationship field that get the Id from an Object called Goal__c.

In the OpportunityItem__c I have a trigger, in these trigger I have to get the Opportunity Id and get the Goal Id too.

My code is like this:

for(OpportunityItem__c item : trigger.new)
{
opportunityId = item.OpportunityId; //(relationship field Name in OpportunityItem__c)
year = item.CloseDate__c;
}
  list<Goal__c> goalsList = [SELECT Id, Year__c FROM Goal__c WHERE Year__c =: year];
  list<Opportunity> opportunities = [SELECT Id, Name FROM Opportunity WHERE Id=: opportunityId ];

Until here ok.
But When I test, both list get a exception of SOQL Limit 101.
I want some manner to get the data of Goal and Opportunity that have relationship with the current item that fire a trigger.

Someone knows how I do that?

Best Regards
Rafael
I need to verify whether a batch (actually inbound email handler) has been run each day and if the batch is not run for a particular day, I need to send an email notification.

Is there any config way, I can set some flag before the anticipated time of batch run and reset the flag in batch.
After batch run anticipated time, I want to verify flag and if flag is not reset (which means batch did not run), I need to send an email
Is it possible to set the flag using workflow? Is it possible to verify flag and send email using workflow?
So, basically I'm trying to see if workflow can be run like a scheduled batch job for this simple task?
 

I'm new to Visualforce and could use some guidance to know whether this is even possible, and if so in which direction I should start exploring.

I'm trying to make  "Previous cases" page that'll be used within the case view, that shows a list of all previous cases associated with the same contactID.  I think I've got a good handle on how to show those cases using a Standard List Controller, but the result is totally non-interactive.

Is there a way to generate a list where a user can click on an entry to open that object in a new tab?  I'm hoping there's another controller out there which I've just missed so far.

Thanks for your help!

Is there a way to do this?

Here's a breakdown of what has been requested of my batch code:

We are working on a large integration with our Salesforce and various other divisions/mainframes. The goal is to completely eliminate the mainframes as they are acting as "middle men" between the other divisions and us not to mention they were built 25+ years ago and are outdated at this point. One division will be pushing us data to our Mule in the form of a .txt file and then Mule will insert the lines in that file as a text field into a Staging object. My batch then picks new records up from Staging and parses the record details into fields in a Master object. I use Database.Upsert() with an external ID to move those details into Master. 

With the current example we have gotten from the division we are integrating into our SF org, there are some lines of data that have the same external ID (these would be concidered updates to the record). The below image shows an example (there are 3 external IDs here).

Record line example

As expected when I pass my list of Master data to be upserted, I get the dreaded "Duplicate external id specified: 59XXXXXXXX01" error when the batch gets to these records and they do not upsert at all. I've been told that this scenerio should not exist outside of my test data I was sent, and that when we go live I will not receive multiple external ids in a day; but of course, we want to code to handle this situation just in case. 

Is there a work around for this scenario where I can force the first record to upsert and then come back and process the second record? We will have change history tracking set up for the Master object and it is required that we have history of every update for each Master record. Inserting or updating all records that we are sent is mandatory.

I was thinking that I could change my Upsert to accept a single record and process the records in the batch individually, but would that defeat the purpose of a batch class and cause DML governor limits to be hit for large transactions like I suspect? Should I use Database.Insert() and Database.Update() separately instead of Database.Upsert()? I'm trying my hardest to keep my DML operations to bare minimum (with Database.Upsert() I am performing 4 DML operations.)

Any advice on how to create a workaround would be extremely helpful and greatly appreciated. 





 
Hi,
     I have a standard Product page with few fields but here we talk about two fields: 
     1.Formula field with hyperlink to open vfpage on same tab.
     2.Text field to hold Product name

     Now, when I click on formula's hyperlink, a vf page should open and through that vfpage I should search for particular product and select one.
     When I select product from vfpage, the text field in standard page should be filled with the product name.

     What is the ideal way to do this without having JS in formula field's hyperlink ?

Thanks in Advance.
list<KnowledgeArticleVersion> hrlist = new list<KnowledgeArticleVersion>();
String articleId = '';
hrlist=[SELECT ArticleType,Id,KnowledgeArticleId,Language,PublishStatus FROM KnowledgeArticleVersion WHERE ArticleType = 'How_To_HR__kav' AND Language = 'en_US' AND PublishStatus = 'Online'limit 100];

for(KnowledgeArticleVersion hr:hrlist)
{
    articleId = hr.KnowledgeArticleId;
    KbManagement.PublishingService.archiveOnlineArticle(articleId, null); 
    articleId = '';
}


I'm writing above code to mass Archive articles.Bu its throwing below error

System.HandledException: You can't perform this action. Be sure the action is valid for the current state of the article, and that you have permission to perform it.