• Ansliesdad
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies
I've created a custom detail page button on the Case object that calls a VF page.  The VF page renders a page that displays two sections:  Master Case and Merge Cases.  Under Master Case, it displays the case from which the button was pushed.  Under Merge Cases, it displays all cases of a certain type (i.e. Type = X) and that are associated with the same Account and the same Contact (i.e. All cases that have John Smith as the Contact and Salesforce as the Company and X as the Type).  Also, under Merge Cases, each case is displayed with a checkbox in the left column like in a list view so the user can select them.  It also displays a button called "Merge Cases".  This is where I'm stuck.

What I want to happen is when a user checks a box for one or more cases under Merge Cases and then clicks the Merge Cases button, I want to update the Master Case with the data from the Merge Cases.  Most of the fields I'd like to update are text fields (so concatenate the text values) but there are a few picklists.  Also, I don't want to delete the Merge Cases but I do want to set their status field to a different value, say "Duplicate".

I'm pretty new to coding so I would appreciate any help or if anyone can point me in the right direction from here.  I've included my VF page and Controller code below.  Thanks for any help.

Here is my VF Page:
<apex:page standardController="Case" extensions="SCM_Controller">

    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Merge Cases" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Master Case" columns="1">
                <!-- In our table we are displaying the cCase records -->
                <apex:pageBlockTable value="{!Case}" var="c" id="table">
                    <!-- This is how we access the case values within our cCase container/wrapper -->
                    <apex:column value="{!c.CaseNumber}" />
                    <apex:column value="{!c.AccountId}" />
                    <apex:column value="{!c.ContactId}" />
                    <apex:column value="{!c.type}" />
                    <apex:column value="{!c.reason}" />
                    <apex:column value="{!c.origin}" />
                    <apex:column value="{!c.description}" />
                    <apex:column value="{!c.Care_Management_Required__c}" />
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            <apex:pageblockSection title="Merge Cases" columns="1">
                <!-- In our table we are displaying the cCase records -->
                <apex:pageBlockTable value="{!cases}" var="c" id="table">
                    <apex:column >
                        <!-- This is our selected Boolean property in our wrapper class -->
                        <apex:inputCheckbox value="{!c.selected}"/>
                    </apex:column>
                    <!-- This is how we access the case values within our cCase container/wrapper -->
                    <apex:column value="{!c.cas.CaseNumber}" />
                    <apex:column value="{!c.cas.AccountId}" />
                    <apex:column value="{!c.cas.ContactId}" />
                    <apex:column value="{!c.cas.type}" />
                    <apex:column value="{!c.cas.reason}" />
                    <apex:column value="{!c.cas.origin}" />
                    <apex:column value="{!c.cas.description}" />
                    <apex:column value="{!c.cas.Care_Management_Required__c}" />
                </apex:pageBlockTable>
            </apex:pageblockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
And here is my controller:
public with sharing class SCM_Controller
{
    
    private ApexPages.StandardController controller;
   
    public Case tempCase {get; set;}

    public SCM_Controller(ApexPages.StandardController controller)
    {
    
        this.controller = controller;
        this.tempCase = (Case)controller.getRecord();
        
    }

    //add wrapper with checkbox so user can select cases to be merged
    //collection of the class/wrapper objects cCase
    public List<cCase> caseList {get; set;}
 
    //This method uses a simple SOQL query to return a List of Cases
    public List<cCase> getCases()
    {
        if(caseList == null)
        {
            caseList = new List<cCase>();
            System.debug(this.tempCase);
            for(Case c: [select Id, CaseNumber, AccountId, ContactId, type, reason, origin, description, care_management_required__c from Case where ContactId =:this.tempCase.ContactId and CaseNumber!=:this.tempCase.CaseNumber and type='Medical Incident'])
            {
                // As each case is processed we create a new cCase object and add it to the caseList
                caseList.add(new cCase(c));
            }
        }
        return caseList;
    }
 
    public PageReference processSelected()
    {
 
        //create a new list of Cases to be populated only with Cases if they are selected
        List<Case> selectedCases = new List<Case>();
 
        //cycle through list of cCases and check to see if the selected property is set to true, if it is, add the Case to the selectedCases list
        for(cCase cCas: getCases())
        {
            if(cCas.selected == true)
            {
                selectedCases.add(cCas.cas);
            }
        }
 
        //Now we have our list of selected cases and can perform any type of logic we want
        System.debug('These are the selected Cases...');
        for(Case cas: selectedCases)
        {
            system.debug(cas);
        }
        caseList=null; //we need this line if we performed a write operation because getCases gets a fresh list now
        return null;
    }


    //This is our wrapper/container class
    public class cCase
    {
        public Case cas {get; set;}
        public Boolean selected {get; set;}
 
        //This is the contructor method
        public cCase(Case c)
        {
            cas = c;
            selected = false;
        }
    }
}
Thanks again for any help!
Hi everyone,

I'm a beginner at writing triggers/code and would like to see if anyone can help me finish the trigger below.  When a Contract is created on a given Account, I would like to automatically add that account's Contacts to the related Contract as a Customer Contact Role.  SF provide me some basic code to get started but I'm having a hard time understanding how to customize it for our org.  The trigger is below:

1  /* Adds an Account's related Contacts as Contract Roles to the same Account's related Contracts */
2  
3  trigger AccountContactsToContractRoles on Contract (after insert)
4  {
5      Set<Id>accountIds = new Set<Id>();
6      //To-Do:  Collect account Ids
7      
8      Map<Id, Account> accounts = new Map<Id, Account>([SELECT ID, (SELECT ContactId FROM AccountContactRoles) FROM Account WHERE ID IN :accountIds]);
9      
10      List<ContractContactRole> ccrs = new List<ContractContactRole>();
11      for (Contract c: Trigger.new)
12      {
13          for(AccountContactRole acr : accounts.get(o.AccountId).AccountContactRoles)
14          {
15              ccrs.add(new ContractContactRole(ContractId = o.Id, ContactId = acr.ContactId));
16          }
17      }
18      
19      insert ccrs;
20  }

Thanks to anyone who can help.
I've created a custom detail page button on the Case object that calls a VF page.  The VF page renders a page that displays two sections:  Master Case and Merge Cases.  Under Master Case, it displays the case from which the button was pushed.  Under Merge Cases, it displays all cases of a certain type (i.e. Type = X) and that are associated with the same Account and the same Contact (i.e. All cases that have John Smith as the Contact and Salesforce as the Company and X as the Type).  Also, under Merge Cases, each case is displayed with a checkbox in the left column like in a list view so the user can select them.  It also displays a button called "Merge Cases".  This is where I'm stuck.

What I want to happen is when a user checks a box for one or more cases under Merge Cases and then clicks the Merge Cases button, I want to update the Master Case with the data from the Merge Cases.  Most of the fields I'd like to update are text fields (so concatenate the text values) but there are a few picklists.  Also, I don't want to delete the Merge Cases but I do want to set their status field to a different value, say "Duplicate".

I'm pretty new to coding so I would appreciate any help or if anyone can point me in the right direction from here.  I've included my VF page and Controller code below.  Thanks for any help.

Here is my VF Page:
<apex:page standardController="Case" extensions="SCM_Controller">

    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Merge Cases" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Master Case" columns="1">
                <!-- In our table we are displaying the cCase records -->
                <apex:pageBlockTable value="{!Case}" var="c" id="table">
                    <!-- This is how we access the case values within our cCase container/wrapper -->
                    <apex:column value="{!c.CaseNumber}" />
                    <apex:column value="{!c.AccountId}" />
                    <apex:column value="{!c.ContactId}" />
                    <apex:column value="{!c.type}" />
                    <apex:column value="{!c.reason}" />
                    <apex:column value="{!c.origin}" />
                    <apex:column value="{!c.description}" />
                    <apex:column value="{!c.Care_Management_Required__c}" />
                </apex:pageBlockTable>
            </apex:pageBlockSection>
            <apex:pageblockSection title="Merge Cases" columns="1">
                <!-- In our table we are displaying the cCase records -->
                <apex:pageBlockTable value="{!cases}" var="c" id="table">
                    <apex:column >
                        <!-- This is our selected Boolean property in our wrapper class -->
                        <apex:inputCheckbox value="{!c.selected}"/>
                    </apex:column>
                    <!-- This is how we access the case values within our cCase container/wrapper -->
                    <apex:column value="{!c.cas.CaseNumber}" />
                    <apex:column value="{!c.cas.AccountId}" />
                    <apex:column value="{!c.cas.ContactId}" />
                    <apex:column value="{!c.cas.type}" />
                    <apex:column value="{!c.cas.reason}" />
                    <apex:column value="{!c.cas.origin}" />
                    <apex:column value="{!c.cas.description}" />
                    <apex:column value="{!c.cas.Care_Management_Required__c}" />
                </apex:pageBlockTable>
            </apex:pageblockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
And here is my controller:
public with sharing class SCM_Controller
{
    
    private ApexPages.StandardController controller;
   
    public Case tempCase {get; set;}

    public SCM_Controller(ApexPages.StandardController controller)
    {
    
        this.controller = controller;
        this.tempCase = (Case)controller.getRecord();
        
    }

    //add wrapper with checkbox so user can select cases to be merged
    //collection of the class/wrapper objects cCase
    public List<cCase> caseList {get; set;}
 
    //This method uses a simple SOQL query to return a List of Cases
    public List<cCase> getCases()
    {
        if(caseList == null)
        {
            caseList = new List<cCase>();
            System.debug(this.tempCase);
            for(Case c: [select Id, CaseNumber, AccountId, ContactId, type, reason, origin, description, care_management_required__c from Case where ContactId =:this.tempCase.ContactId and CaseNumber!=:this.tempCase.CaseNumber and type='Medical Incident'])
            {
                // As each case is processed we create a new cCase object and add it to the caseList
                caseList.add(new cCase(c));
            }
        }
        return caseList;
    }
 
    public PageReference processSelected()
    {
 
        //create a new list of Cases to be populated only with Cases if they are selected
        List<Case> selectedCases = new List<Case>();
 
        //cycle through list of cCases and check to see if the selected property is set to true, if it is, add the Case to the selectedCases list
        for(cCase cCas: getCases())
        {
            if(cCas.selected == true)
            {
                selectedCases.add(cCas.cas);
            }
        }
 
        //Now we have our list of selected cases and can perform any type of logic we want
        System.debug('These are the selected Cases...');
        for(Case cas: selectedCases)
        {
            system.debug(cas);
        }
        caseList=null; //we need this line if we performed a write operation because getCases gets a fresh list now
        return null;
    }


    //This is our wrapper/container class
    public class cCase
    {
        public Case cas {get; set;}
        public Boolean selected {get; set;}
 
        //This is the contructor method
        public cCase(Case c)
        {
            cas = c;
            selected = false;
        }
    }
}
Thanks again for any help!
Hi everyone,

I'm a beginner at writing triggers/code and would like to see if anyone can help me finish the trigger below.  When a Contract is created on a given Account, I would like to automatically add that account's Contacts to the related Contract as a Customer Contact Role.  SF provide me some basic code to get started but I'm having a hard time understanding how to customize it for our org.  The trigger is below:

1  /* Adds an Account's related Contacts as Contract Roles to the same Account's related Contracts */
2  
3  trigger AccountContactsToContractRoles on Contract (after insert)
4  {
5      Set<Id>accountIds = new Set<Id>();
6      //To-Do:  Collect account Ids
7      
8      Map<Id, Account> accounts = new Map<Id, Account>([SELECT ID, (SELECT ContactId FROM AccountContactRoles) FROM Account WHERE ID IN :accountIds]);
9      
10      List<ContractContactRole> ccrs = new List<ContractContactRole>();
11      for (Contract c: Trigger.new)
12      {
13          for(AccountContactRole acr : accounts.get(o.AccountId).AccountContactRoles)
14          {
15              ccrs.add(new ContractContactRole(ContractId = o.Id, ContactId = acr.ContactId));
16          }
17      }
18      
19      insert ccrs;
20  }

Thanks to anyone who can help.

- Products Pricebooks

- Record Types

- Workflow

- Validation

 

Working 3 projects & need help ASAP.  Be local (US) & willing to sign NDA. 

If replying include your name, phone # & email address.  Looking for independents only! 

the green house is a fast growing business in the Environment Industry that needs a qualified Salesforce person to help build out our business processes in our new Salesforce environment. 

 

The business is 5 years old so is not a start-up. We manage around 3000 properties in the UK for big clients such as Starbucks, H&M, The Body Shop and Caffe Nero. We handle over 500,000 scheduled recycling collections per annum and are quickly adding to our range of services with things like energy management and renewable infrastructures.

 

We have begun moving from our current CRM environment (SugarCRM) and need someone to work with us on a full-time basis to carry out the basic administration, customisations and basic development work. Any major projects we undertake would still be contracted out with the person we employ managing the project.

 

This is an exciting opportunity to be involved with a great company in a fantastic industry.

 

We are based in Northampton, UK

 

If you are interested and want to know more please do get in touch