• neckr
  • NEWBIE
  • 50 Points
  • Member since 2011

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 59
    Replies

Does anyone know if there is a limit to the number of field sets per custom object?

 

I have 250 field sets on 4 custom objects, however with the new capability of creating field sets with fields from child objects I want to roll all the field sets (1000) to once custom object from its 4 child objects for easier changes.

 

Before I make this effort, I want to check if I will hit any limits, I couldn't find anything on field set limitations in docs.

 

Does anyone know?

 

Thanks,

  • June 13, 2011
  • Like
  • 0

I created custom text fields to use as labels to get around the 40 character field constraint.  I want to display this associated fields as labels using field sets.  I created two field sets, one with the fields and one with the inputtext fields as labels.

 

My initial thought was two use to repeat functions but it loops around the 2nd field set too many times. Any thoughts on how I can achieve my objective?

 

 

 <apex:form >  
       <apex:pageBlock title="Without Field Set Use">  
       <apex:pageBlockSection title="Dynamic Object">  
           
          <apex:repeat value="{!$ObjectType.Field_Holder_1__c.FieldSets.ST00192_Labels}" var="fieldlabelAPIName">
        <apex:repeat value="{!$ObjectType.Field_Holder_1__c.FieldSets.ST00192}" var="fieldAPIName">
         
             <apex:pageblockSectionItem >
                 <apex:outputfield value="{!sObjectToBind[fieldlabelAPIName]}"/> 
                 <apex:inputField value="{!sObjectToBind[fieldAPIName]}"/>
             </apex:pageblockSectionItem>
           </apex:repeat>
                 </apex:repeat> 
       </apex:pageBlockSection>  
       </apex:pageBlock>  
   </apex:form>  

 

 

  • June 13, 2011
  • Like
  • 0

Hi,

 

I am trying to display input fields using field sets in VF.  My field labels were too long to put in Field Label attribute so I put my label text in the field description attribute.  Is there a way to access the field description attribute and use as my label in field set input fields?

 

Thanks in advance.

  • June 08, 2011
  • Like
  • 0

Hi, does anyone have an example or sample code of how I can create a list of Cities grouped by Province/State and Country within Visual Force.

 

I have my data in Service_Area__c object with populated records that have Country__c, Province_State__c and City__c  fields the object Name is a unique combination of Country Code, Province Code and City combined. For example CAD_ON_TORONTO.

 

I would like the vf page to look like:

 

Country X

      Province/State A

           City 1

           City 2

           etc

 

       Province/State B

             City 1

             City 2

             etc

 

Country Y

      Province/State A

           City 1

           City 2

           etc

 

       Province B

             City 1

             City 2

             etc

 

 

  thanks

  • June 04, 2011
  • Like
  • 0

Hi,


My objective is to add 3 Trade_Reference_Reports__c Object records for every unique Category__c field in Con_Service_Task_Request__c Object. In other words add 3 Trade References for every Service Task Requested within a Category that  does not already have 3 trade references.


My trigger runs fine when I add 1 Con_Service_Task_Request__c record at a time for a category that does not yet have any trade references, however when I add more than 1 Con_Service_Task_Request__c from the same category that does not yet have Trade References, its creates 3 trade references for each record under that category instead of the intended 1.


I am a bit stuck on how do handle this scenerio and was hoping someone can suggest some ideas?


I copied my Trigger code and method that allows my to process multiple records at once.



trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{

if (FireTrigger.getRun()) {


Con_Service_Task_Request__c[] STS = Trigger.new.deepClone();


Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();
Set<String> uniqueCategories = new Set<String>();
Map<ID, Con_Service_Task_Request__c> mapST = new Map<ID, Con_Service_Task_Request__c>();



List <Trade_Reference_Report__c> listTRV1 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact1 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV2 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact2 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV3 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact3 = new List<Contact>();


for(Con_Service_Task_Request__c ST : STS){
        
         accID.add(ST.Account__c);
         mapST_Account.put(ST.id , ST.Account__c);
         
         Contact Principalcontact=[SELECT ID FROM Contact WHERE AccountId = : ST.Account__c AND Contact_Type__c = 'Acct Principal Contact' limit 1];
         mapPrincipalAcctCont.put(ST.id, Principalcontact.ID); 
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID, TRV_Work_Category__c FROM Trade_Reference_Report__c 
         WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c];
             
	 if(ExistingTRVs == NULL)  {
                ExistingTRVs = New List<Trade_Reference_Report__c>();
                }
             
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
         
         mapST.put(ST.id, ST);
         
         for(Trade_Reference_Report__c WC : ExistingTRVs){
         uniqueCategories.add(WC.TRV_Work_Category__c);
        }
    }
    


for (Con_Service_Task_Request__c ST : Trigger.new) {



//CHECK TO SEE IF TRADE REFERENCE FOR PARTICULAR CATEGORY EXISTS, IF SO ASSIGN ID'S TO ST, //IF NOT CREATE 3 NEW TRV RECORDS - WHEN ADDING MULTIPLE Con_Service_Task_Request__c //RECORDS AT THE SAME TIME, IT CREATES 3 TRV RECORDS FOR ALL Con_Service_Task_Request__c RECORDS
// INSTEAD OF JUST THE FIRST ONE. UNSURE OF EASIEST WAY TO HANDLE THIS SCENERIO.

if ((uniqueCategories.Contains(ST.Category__c))&&(mapExistingTRVs.get(ST.id).size() > 0) && !(ST.Service__r.Trade_Reference_Reports__c ))
{

mapST.get(ST.id).Trade_Reference_Report_1__c = mapExistingTRVs.get(ST.id).get(0).ID;

mapST.get(ST.id).Trade_Reference_Report_2__c = mapExistingTRVs.get(ST.id).get(1).ID;

mapST.get(ST.id).Trade_Reference_Report_3__c = mapExistingTRVs.get(ST.id).get(2).ID;

}

if ((!uniqueCategories.Contains(ST.Category__c)) && !(ST.Service__r.Trade_Reference_Reports__c ))
{ 
{ 
 Contact TRVCompanyContact1 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 1');
 listTRVCompanyContact1.add(TRVCompanyContact1);
 
 Contact TRVCompanyContact2 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 2');
 listTRVCompanyContact2.add(TRVCompanyContact2);

Contact TRVCompanyContact3 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 3');
 listTRVCompanyContact3.add(TRVCompanyContact3);
       
}

}

insert listTRVCompanyContact1;
insert listTRVCompanyContact2;
insert listTRVCompanyContact3;


for (Integer i=0; i<Trigger.new.size(); i++) { 


if(listTRVCompanyContact1.size()> 0){ 
Trade_Reference_Report__c TRV1 = new Trade_Reference_Report__c(Account__c = STS[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact1[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(STS[i].id), TRV_Work_Category__c = STS[i].Category__c, TRV_Number__c = 1 );    
listTRV1.add(TRV1);
}

if(listTRVCompanyContact2.size()> 0){ 
Trade_Reference_Report__c TRV2 = new Trade_Reference_Report__c(Account__c = STS[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact2[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(STS[i].id), TRV_Work_Category__c = STS[i].Category__c, TRV_Number__c = 2 );    
listTRV2.add(TRV2);
}

if(listTRVCompanyContact3.size()> 0){ 
Trade_Reference_Report__c TRV3 = new Trade_Reference_Report__c(Account__c = STS[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact3[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(STS[i].id), TRV_Work_Category__c = STS[i].Category__c, TRV_Number__c = 3 );    
listTRV3.add(TRV3);
}

} 



insert listTRV1;
insert listTRV2;
insert listTRV3;


for (Integer i=0; i<STS.size(); i++) { 

Con_Service_Task_Request__c ST = STS[i];

if(listTRV1.size()> 0){ 

ST.Trade_Reference_Report_1__c = listTRV1[i].id;

}

if(listTRV2.size()> 0){ 

ST.Trade_Reference_Report_2__c = listTRV2[i].id;

}


if(listTRV3.size()> 0){ 

ST.Trade_Reference_Report_3__c = listTRV3[i].id;

}


update mapST.values();

}



}




public PageReference processSelected() {

    List<Service_Categories__c> selectedServiceTasks = new List<Service_Categories__c>();
    
    for(aServiceTask aST : getServiceTasks() ) {
        if(aST.selected == true) {
        selectedServiceTasks.add(aST.ST);
        }
     }
     System.debug('These are the selected Service Tasks...');
     List<Con_Service_Task_Request__c >Strs = new List<Con_Service_Task_Request__c >();
     for(Service_Categories__c ST : selectedServiceTasks) {
           
     servicecode = ST.Service_Name__c + ' - ' + countrycode + ' - ' + provincestatecode + ' - ' + city;
     
     Product2 service = [SELECT id FROM Product2 WHERE ProductCode = : servicecode limit 1]; 
     
     Con_Service_Task_Request__c newSTR = new Con_Service_Task_Request__c(Account__c = acctID, Service__c = service.id, Service_Code__c = servicecode, Service_Name__c = ST.Service_Name__c, Service_Area__c = servicearea, Country__c = country, 
     Province_State__c = provincestate, City__c = city,  Postal_Zip_Code__c = postalzip, Category__c = category,  Service_Task_Request_Status__c = 'Not Verified'); //Service__c = serviceid, 
     
     Strs.add(newSTR);
      system.debug(ST);
      
     }
     try {
     upsert Strs;
     } 
     catch (DmlException e) {
        
        
     }
     return null;
     }





  • June 03, 2011
  • Like
  • 0

I realize that trigger.new is read only so I created a map to update the fields in my trigger but still getting a read-only error. I cut out most of my code and left the relevant parts.  My code compiles but gives and error when running.

 

Any suggestions?

 

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{

if (FireTrigger.getRun()) {


Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();
Map<ID, Con_Service_Task_Request__c> mapST = new Map<ID, Con_Service_Task_Request__c>();



List <Trade_Reference_Report__c> listTRV1 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact1 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV2 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact2 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV3 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact3 = new List<Contact>();


for(Con_Service_Task_Request__c ST : trigger.new){
         
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID FROM Trade_Reference_Report__c 
         WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c limit 3]; 
             if(ExistingTRVs == NULL)  {
                ExistingTRVs = New List<Trade_Reference_Report__c>();
                }
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
         mapST.put(ST.id, ST);
    }
    


for (Con_Service_Task_Request__c ST : Trigger.new) {



//CHECK TO SEE IF TRADE REFERENCE FOR PARTICULAR CATEGORY EXISTS, IF SO ASSIGN ID'S TO ST, IF NOT CREATE 3
//NEW TRV RECORDS
if (mapExistingTRVs.get(ST.id).size() > 0 )
{

mapST.get(ST.id).Trade_Reference_Report_1__c = mapExistingTRVs.get(ST.id).get(0).ID;

mapST.get(ST.id).Trade_Reference_Report_2__c = mapExistingTRVs.get(ST.id).get(1).ID;

mapST.get(ST.id).Trade_Reference_Report_3__c = mapExistingTRVs.get(ST.id).get(2).ID;

}

if (mapExistingTRVs.get(ST.id).size() == 0 )
{ 
 Contact TRVCompanyContact1 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 1');
 listTRVCompanyContact1.add(TRVCompanyContact1);
 
 Contact TRVCompanyContact2 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 2');
 listTRVCompanyContact2.add(TRVCompanyContact2);

Contact TRVCompanyContact3 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 3');
 listTRVCompanyContact3.add(TRVCompanyContact3);
       
}

}

insert listTRVCompanyContact1;
insert listTRVCompanyContact2;
insert listTRVCompanyContact3;


for (Integer i=0; i<Trigger.new.size(); i++) { 


if(listTRVCompanyContact1.size()> 0){ 
Trade_Reference_Report__c TRV1 = new Trade_Reference_Report__c(Account__c = Trigger.new[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact1[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(Trigger.new[i].id), TRV_Work_Category__c = Trigger.new[i].Category__c );    
listTRV1.add(TRV1);
}

if(listTRVCompanyContact2.size()> 0){ 
Trade_Reference_Report__c TRV2 = new Trade_Reference_Report__c(Account__c = Trigger.new[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact2[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(Trigger.new[i].id), TRV_Work_Category__c = Trigger.new[i].Category__c );    
listTRV2.add(TRV2);
}

if(listTRVCompanyContact3.size()> 0){ 
Trade_Reference_Report__c TRV3 = new Trade_Reference_Report__c(Account__c = Trigger.new[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact3[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(Trigger.new[i].id), TRV_Work_Category__c = Trigger.new[i].Category__c );    
listTRV3.add(TRV3);
}

} 



insert listTRV1;
insert listTRV2;
insert listTRV3;


for (Integer i=0; i<Trigger.new.size(); i++) { 

Con_Service_Task_Request__c ST = Trigger.new[i];

if(listTRV1.size()> 0){ 

ST.Trade_Reference_Report_1__c = listTRV1[i].id;

}

if(listTRV2.size()> 0){ 

ST.Trade_Reference_Report_2__c = listTRV2[i].id;

}


if(listTRV3.size()> 0){ 

ST.Trade_Reference_Report_3__c = listTRV3[i].id;

}
}


update mapST.values();

}



}

 

 

  • June 02, 2011
  • Like
  • 0

I am trying to figure out the VF syntax to display the input fields of my map.

 

For every Con_Service_Task_Request__c there are 3
Customer_Reference_Report__c and associated CustomerReferenceContact records.

 

I want to render each desired Con_Service_Task_Request__c record inputfield in a pageblock section with its 3 associated

Customer_Reference_Report__c inputfields.

 

I tried a few things based on examples from available resources but no luck, and not sure where to go next. Here is my page and controller, any direction is much appreciated.

 

 

<apex:repeat value="{!ST}" var="STasks" >  
<apex:pageBlockSection columns="3"  title="Service Task Verification Details: {!STasks.Service_Code__c}" collapsible="true" id="STList" >                    

<apex:inputField value="{!STasks.Associated_License__c}" rendered="{!STasks.LV_Required_Code__c==0}"/>
<apex:inputField value="{!STasks.Associated_Insurance_Policy__c}" rendered="{!STasks.GLIV_Required_Code__c==0}"/>
<apex:inputField value="{!STasks.Associated_Eco_Accreditation__c}" rendered="{!STasks.EFAV_Required_Code__c==0}"/>


<!--<apex:repeat value="{!mapST_Cusrefs[STasks.ID]}" var="CRV" >
 
<apex:inputField value="{!mapST_Cusrefs[CRV].CRV_Contact__r.LastName}" />-->

                 
<!--</apex:repeat>--> <!-- This was the most logical approach but tells me Map Key not found -->


<apex:inputField value="{!mapST_Cusrefs[STasks.ID][0].CRV_Contact__r.LastName}" /> <!--This works, but only gives me one Contact record -->

<apex:inputField value="{!mapST_Cusrefs[STasks.ID][1].CRV_Contact__r.LastName}" /> <!--Error: Subscript value 1 not valid. Must be between 0 and 0 -->


<apex:inputField value="{!mapST_Cusrefs[STasks.ID][2].CRV_Contact__r.LastName}" /> <!--Error: Subscript value 1 not valid. Must be between 0 and 0 -->

                            
</apex:pageBlockSection>                        
 </apex:repeat>

 

 

 

 

 

 

            public Map<ID, List<Customer_Reference_Report__c >> mapST_Cusrefs
{
    get
    {
       if(mapST_Cusrefs == null)
       {
mapST_Cusrefs= new Map<ID, List<Customer_Reference_Report__c >>();   
       }
       return mapST_Cusrefs;
    }
   set;
}
               
     public List<Con_Service_Task_Request__c> getST()     
       {        
         if ( (null!=getAccount().id) && (ST == null) )
              
       {            
        ST=[SELECT Id, Account__c, Service_Code__c, Associated_Eco_Accreditation__c,Associated_Insurance_Policy__c, Associated_License__c, LV_Required_Code__c, GLIV_Required_Code__c, EFAV_Required_Code__c                          
        FROM Con_Service_Task_Request__c                           
        WHERE Account__c = : getAccount().ID                          
        ORDER BY Service_Code__c];
          }
        
        for(Con_Service_Task_Request__c STasks : ST){
        
        cusrefs = [SELECT Id, CRV_Account__c, CRV_Contact__r.ID, CRV_Contact__r.Company_Name__c, CRV_Contact__r.Email, CRV_Contact__r.Phone, CRV_Contact__r.LastName,CRV_Contact__r.FirstName, CRV_Service_Performed__c, CRV_Service_Date__c, CRV_Service__r.Service__r.For_Business__c                           
        FROM Customer_Reference_Report__c                           
        WHERE CRV_Service__c = : STasks.ID                         
        ORDER BY CRV_Service_Performed__c];
        
        
        CustomerReferenceContact = new List<Contact>(); 
            for (Customer_Reference_Report__c CRV : cusrefs) {
                CustomerReferenceContact.add(CRV.CRV_Contact__r );
                } 
        
        if(cusrefs==null){
        mapST_Cusrefs.put(STasks.ID, new List<Customer_Reference_Report__c>());
        }
                   mapST_Cusrefs.put(STasks.ID, cusrefs);
                   
              }
                                                       
        return ST;  
        
         }
           

 

 

 

  • June 01, 2011
  • Like
  • 0

Hi,

 

I have been revising my trigger code as I had DML Insert statements inside my loop. I created a list and brought the DML statements outside of loop, but have ran into another issue as a result.  I need to create a contact and link the contact to the Bankruptcy_Judgements_Liens_Report__r custom object through the BJVLAgencyContact.ID lookup field.  When I insert outside of the loop, the actual contact ID is not captured since its not inserted.

 

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{
Set<ID> accID = new Set<ID>();
//map to contain Con_Service_Task_Request__c record's id as key and it's master Account record's ID as value
Map<ID, ID> mapST_Account = new Map<ID, ID>();
Map<ID, ID> mapPrincipalAcctCont = new Map<ID, ID>();
Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();

List <Contact> listBJLVAgencyContact = new List<Contact>();
List <Bankruptcy_Judgements_Liens_Report__c> listBJLV = new 


for(Con_Service_Task_Request__c ST : trigger.new){
         //This "Con_Service_Task_Request__c" should be API Name of Master Detail relationship with the Account 
         accID.add(ST.Account__c);
         mapST_Account.put(ST.id , ST.Account__c);
         
         Contact Principalcontact=[SELECT ID FROM Contact WHERE AccountId = : ST.Account__c AND Contact_Type__c = 'Acct Principal Contact' limit 1];
         mapPrincipalAcctCont.put(ST.id, Principalcontact.ID); 
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID FROM Trade_Reference_Report__c WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c limit 3]; 
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
    }
    
Map<Id,List<Account>> records = new Map<Id,List<Account>>();
for(Account a : [SELECT id , 
(select id from Bankruptcy_Judgements_Liens_Report__r) 

FROM Account 
WHERE id in : accID]) {
    if(!records.containsKey(a.id))  {
        records.put(a.id , new List<Account>());
    }
    records.get(a.id).add(a);   
}   

for (Con_Service_Task_Request__c ST : Trigger.new) {

//INSERT NEW BJLV RECORD IF REQUIRED AND DOES NOT YET EXIST 
if (records.get(mapST_Account.get(ST.id)).get(0).Bankruptcy_Judgements_Liens_Report__r.Size()  == 0) 

Contact BJLVAgencyContact = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'BJLV Agency', LastName = 'Enter Last Name');
 listBJLVAgencyContact.add(BJLVAgencyContact);

Bankruptcy_Judgements_Liens_Report__c BJLV = new Bankruptcy_Judgements_Liens_Report__c(Account__c = ST.Account__c , BJLV_Agency_Contact__c = BJLVAgencyContact.ID ); //BJVLAgencyContact.ID does not exist at this stage since Insert //outside of the loop now   
 listBJLV.add(BJLV);
 
}


}
insert listBJLVAgencyContact;
insert listBJLV; //Does not link to Contact on Insert. How would I get it to link?
}

 

 

  • June 01, 2011
  • Like
  • 0

Hi, I could use some help trying to figure out how to render mutiple child records within is associated parent record pagesection within a pageblock.

 

In one VF page I would like to render multiple Con_Service_Task_Request__c record fields and its associated Customer_Reference_Report__c fields.  There are 3 Customer_Reference_Report__c child records for every Con_Service_Task_Request__c master record, and multiple  Con_Service_Task_Request__c records for each account.

 

I have started by getting the list of Con_Service_Task_Request__c records and list of Customer_Reference_Report__c for the associated account, however I am having trouble with the idea of linking the two together so that the associated child records only show with its parent.  My reading tells me that I may need to use Maps, however not sure where to start and would appreciate some gudiance.  Here is the snippet of my page and controller.

 

 

<apex:pageBlock mode="mainDetail" id="ServiceTaskDetails" >         
<apex:pageBlockButtons location="top">               
<apex:commandButton action="{!save}" value="Save" />                          
</apex:pageBlockButtons>
                   
<apex:repeat value="{!ST}" var="STasks" >  
<apex:pageBlockSection columns="3"  title="Service Task Verification Details: {!STasks.Service_Code__c}" collapsible="true" id="STList" >                    

<apex:inputField value="{!STasks.Associated_License__c}" rendered="{!STasks.LV_Required_Code__c==0}"/>
<apex:inputField value="{!STasks.Associated_Insurance_Policy__c}" rendered="{!STasks.GLIV_Required_Code__c==0}"/>
<apex:inputField value="{!STasks.Associated_Eco_Accreditation__c}" rendered="{!STasks.EFAV_Required_Code__c==0}"/>
<apex:inputhidden rendered="{!STasks.LV_Required_Code__c==1}"/>
<apex:inputhidden rendered="{!STasks.GLIV_Required_Code__c==1}"/>
<apex:inputhidden rendered="{!STasks.EFAV_Required_Code__c==1}"/>


<apex:repeat value="{!custrefs}" var="CRV" >  

<apex:inputField value="{!CRV.CRV_Contact__r.Company_Name__c}" rendered="{!CRV.CRV_Service__r.Service__r.For_Business__c}" />
<apex:inputField value="{!CRV.CRV_Contact__r.FirstName}" /> 
<apex:inputField value="{!CRV.CRV_Contact__r.LastName}" />
<apex:inputField value="{!CRV.CRV_Contact__r.Email}" />
<apex:inputField value="{!CRV.CRV_Contact__r.Phone}" />   
<apex:inputField value="{!CRV.CRV_Service_Date__c}" />
<apex:inputHidden />
  
                 
</apex:repeat> 
                            
</apex:pageBlockSection>                        
 </apex:repeat>
            
</apex:pageblock>

 

//----------------------------SERVICE TASKS METHOD--------------------------------------->
     
      public List<Con_Service_Task_Request__c> getST()     
       {        
         if ( (null!=getAccount().id) && (ST == null) )
              
       {            
        ST=[SELECT Id, Account__c, Service_Code__c, Associated_Eco_Accreditation__c,Associated_Insurance_Policy__c, Associated_License__c, LV_Required_Code__c, GLIV_Required_Code__c, EFAV_Required_Code__c                          
        FROM Con_Service_Task_Request__c                           
        WHERE Account__c = : getAccount().ID                          
        ORDER BY Service_Code__c];
          }

                                                   
        return ST;   
       }         
       
                     
//----------------------------CUSTOMER REFERENCES METHOD----------------------------------->
     
      public List<Customer_Reference_Report__c> getcustrefs()     
       {        
         if ( (null!=getAccount().id) && (custrefs == null) )
              
       {            
        custrefs=[SELECT Id, CRV_Account__c, CRV_Contact__r.ID, CRV_Contact__r.Company_Name__c, CRV_Contact__r.Email, CRV_Contact__r.Phone, CRV_Contact__r.LastName,CRV_Contact__r.FirstName, CRV_Service_Performed__c, CRV_Service_Date__c, CRV_Service__r.Service__r.For_Business__c                           
        FROM Customer_Reference_Report__c                           
        WHERE CRV_Account__c = : getAccount().ID                          
        ORDER BY CRV_Service_Performed__c];
          }
            CustomerReferenceContact = new List<Contact>(); 
            for (Customer_Reference_Report__c CRV : custrefs) {
                CustomerReferenceContact.add(CRV.CRV_Contact__r );
}

                                                   
        return custrefs;   
       }     

 

 

 

 

 

  • May 29, 2011
  • Like
  • 0

Hi I pulled together the code below with some help on the discussion boards and some examples.  I am having trouble with the syntax to get my code to compile.

 

 

Con_Service_Task_Request__c is a child object of Account and the relationship name is Service_Tasks__r.  Account is a master detail lookup field in Con_Service_Task_Request Object, same goes for all my_custom_Object's referenced below.

 

In short when I enter a new Con_Service_Task_Request__c record, I want to check the size of several of the Account Related Custom Objects.  If the size is zero (i.e no records)  I want to create a new record in the corresponding Custom Object.

 

 

Any suggestions on how I can achieve my objective?

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{

Map<Id,List<Account>> records = new Map<Id,Account>();
for(Account a:[SELECT id, Con_Service_Task_Request__c, 
(select id from My_Custom_Object1__r), 
(select id from My_Custom_Object2__r), 
(select id from My_Custom_Object3__r), 
(select id from My_Custom_Object4__r), 
(select id from My_Custom_Object5__r), 
(select id from My_Custom_Object6__r), 
(select id from My_Custom_Object7__r), 
(select id from My_Custom_Object8__r), 
FROM Account 
WHERE Con_Service_Task_Request__c in :trigger.new]) {
    if(records.get(a.Con_Service_Task_Request__c)==null)  {
        records.put(a.Con_Service_Task_Request__c, new List<Account>());
    }
    records.get(a.Con_Service_Task_Request__c).add(a);
}   

for (Con_Service_Task_Request__c ST : Trigger.new) {


if (records.get(ST.id)[index].My_Custom_Object1__r.Size()  == 0 ) { 

 //Insert New Record Code Here     
}

if (records.get(ST.id)[index].My_Custom_Object2__r.Size()  == 0 ) {

 //Insert New Record Code Here   
}
 
if (records.get(ST.id)[index].My_Custom_Object3__r.Size()  == 0 ) {

 //Insert New Record Code Here   

}
// Continue through to My_Custom_Object8__r
 
}

 

  • May 27, 2011
  • Like
  • 0

Hi, First time working with a trigger and it is not assigning the Account ID from ST.Account__r.Id,  is there something I am missing?

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{

for (Con_Service_Task_Request__c ST : Trigger.new) {

if (!ST.Service__r.Bankruptcy_Judgements_Liens_Report__c) { 

Contact BJLVAgencyContact = new Contact(AccountId = ST.Account__r.Id , Contact_Type__c = 'BJLV Agency', LastName = 'Agency Contact');
insert BJLVAgencyContact;
 
Bankruptcy_Judgements_Liens_Report__c BJLV = new Bankruptcy_Judgements_Liens_Report__c(Account__c = ST.Account__r.Id , BJLV_Agency_Contact__c = BJLVAgencyContact.ID );    
insert BJLV;      

}
}

}

 

  • May 24, 2011
  • Like
  • 0
Hi, I am trying to display and update fields for an my License_Verification__c Object 
with a lookup with Contacts.  I want to update and save in one shot, however my 
contact fields are not being updated on Save and not sure what I am missing, please help.
public with sharing class ConAcctVerificationInfoControllerExt {
   
    
private ApexPages.StandardController std;           

// Associated Licenses
public List<License_Verification__c> licenses;

// License Agency Contact
Contact LicenseAgencyContact;

public ConAcctVerificationInfoControllerExt(ApexPages.StandardController stdCtrl)
    {      
    std=stdCtrl;     
    }           
    
    public Account getAccount()     
    {      
        return (Account) std.getRecord();    
    }    
     

//----------------------------LICENSES METHOD--------------------------------------->
     
      public List<License_Verification__c> getlicenses()     
       {        
         if ( (null!=getAccount().id) && (licenses == null) )
              
       {            
        licenses=[SELECT Id, Account__r.ID, Account__c, LV_Agency_Contact__r.ID, LV_Agency_Contact__r.Company_Name__c,LV_Agency_Contact__r.Email, LV_Agency_Contact__r.Phone, LV_Agency_Contact__r.LastName,LV_Agency_Contact__r.FirstName, LV_Agency_Contact__r.Fax, LV_License_Type__c, LV_License_Number__c,LV_License_Expiration_Date__c                          
        FROM License_Verification__c                           
        WHERE Account__c = : getAccount().ID                          
        ORDER BY CreatedDate];
                       }                                    
        return licenses;   
       }       
     
public PageReference save()     
  {      
  Boolean result=true;      
  PageReference pr=Page.TestParentChild;      
  if (null!=getAccount().id)      
  {       
  result=updateContacts();     
   }      
    else     
  {       
   pr.setRedirect(true);      
  }             
  if (result)      
  {         
// call standard controller save, but don't capture the return value which will redirect to view page         
  update Principalcontact;
  update IDV;
  update licenses; // ONLY FIELDS ON PARENT OBJECT ARE BEING UPDATED ON SAVE                                                
   std.save();            
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Changes saved'));      
 }         
pr.getParameters().put('id', getAccount().id);             
 return pr;     
 }  

 

 

<apex:page standardController="Account" extensions="ConAcctVerificationInfoControllerExt" title="Test Verification Info" >

<apex:pageMessages />     
<apex:form >         

<apex:pageBlock mode="mainDetail">             
<apex:pageBlockButtons location="top">                 
<apex:commandButton action="{!cancel}" value="Exit" />                 
<apex:commandButton action="{!save}" value="Save" />                 
</apex:pageBlockButtons> 

            
<apex:repeat value="{!licenses}" var="license" >                     

<apex:pageBlockSection columns="2"  title="License {!license.LV_License_Type__c}:{!license.LV_License_Number__c} Verification" collapsible="true">                         
                
<!--<apex:repeat value="{!$ObjectType.License_Verification__c.FieldSets.LV_Input_Info}" var="field">                      
<apex:inputField value="{!license[field]}" />                     
</apex:repeat>--> 
<apex:inputfield value="{!license.LV_Agency_Contact__r.ID}" /> 
<apex:inputfield value="{!license.Account__r.ID}" />
<apex:inputfield value="{!license.LV_License_Type__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.FirstName}" />
<apex:inputfield value="{!license.LV_License_Number__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.LastName}" />  
<apex:inputfield value="{!license.LV_License_Expiration_Date__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.Email}" />
<apex:inputfield value="{!license.LV_Agency_Contact__r.Company_Name__c}"/>
<apex:inputField value="{!license.LV_Agency_Contact__r.Phone}" />                       

<div style="text-align:center">                            
<apex:commandButton action="{!save}" value="Save" />
<!--<apex:commandButton action="{!AddNewLicense}" value="Add New" /> -->                            
</div>     
                                           
</apex:pageBlockSection>                        
               
</apex:repeat>             

 

  • May 23, 2011
  • Like
  • 0

Hi,  I am displaying a field set in a pageblock section in the standard account controller and for some reason the field help icon beside my custom fields is not showing.  Is there a special attribute I need to use to show the field level help icon?

 

This pageblock is nested within a form and tab

 

 <apex:tab label="Step 1 Company & Contact Info" name="Step1CompanyContactInfo" id="Step1" disabled="{!currentTab<>'1'}">
              
             <apex:sectionHeader title="Contractor Registration" subtitle="1 of 5 Company & Contact Information"/>   
         <apex:form >
          <apex:pageBlock mode="Detail" >
  
           <apex:pageBlockButtons location="both">
                <apex:commandButton action="{!Save}" value="Save & Exit" styleClass="btn" onclick="return confirmExit()" immediate="true"/>
                 <apex:commandButton action="{!Cancel}" value="Cancel" styleClass="btn" onclick="return confirmCancel()" immediate="true"/>
                <apex:commandButton value="Next" action="{!nextTab}" reRender="tabPanel" styleClass="btn" />
           </apex:pageBlockButtons>

<!--HELP! Need to render fields in fieldset top-bottom and not left-right.  Walkaround: rearranged order in fieldset -->

                <apex:pageblockSection columns="2" title="Company Information">
                    <apex:repeat value="{!$ObjectType.Account.FieldSets.Con_Account_Company_Info}" var="f">
                       <apex:inputfield value="{!account[f]}" required="true"  />
                    </apex:repeat> 
                </apex:pageblocksection> 
                
                
               
                   
             <apex:pageBlockSection columns="2" title="Primary Contact Information" >
                           <apex:repeat value="{!Account.Contacts}" var="c">
                              <apex:repeat value="{!$ObjectType.Contact.FieldSets.Con_Account_Contact_Info}" var="f">
                                  <apex:inputField rendered="{!c.Contact_Type__c ='Acct Primary Contact'}" value="{!c[f]}" required="true"/>
                              </apex:repeat> 
                         </apex:repeat>
                         
                    </apex:pageBlockSection> 
                    
             
  
        </apex:pageBlock>
   
    </apex:form>
         </apex:tab>

 

 

  • May 21, 2011
  • Like
  • 0

Hi, Does anyone know how to break up a datalist or pageblock table into multiple colums based on a max number of rows set?

 

For example my page code snap shot below returns a list of 89 rows in one column by default, I would like to break it up on my page into 4 colums of 25 rows max.  What is the easiest way to do this?  I also need to do this for a pageblock table, if the solution is different. I posted the snippet for the  pagebloack table below as well.  Please help!!

 

 

 <apex:pageBlockSection title="Work Categories">
                 
                  <apex:dataList value="{!Categories}" var="c" id="table" type="none" >
                      <apex:commandLink value="{!c.Name}" action="{!ViewST}" reRender="pb"  >
                          <apex:param name="param1" value="{!c.Name}" assignTo="{!category}"/>
                      </apex:commandlink>   
                  </apex:dataList>
                  
         </apex:pageBlockSection>

 

 

 

 <apex:pageBlockSection title="Service Tasks for {!category}" id="ST">
                
                               
                      <apex:pageBlockTable value="{!servicetasks}" var="a" id="table">
                          <apex:column headervalue="Select">
                              <apex:inputCheckbox value="{!a.selected}"/>
                          </apex:column>
                              <apex:column headerValue="{!category} Service Tasks" value="{!a.ST.Service_Name__c}" /> 
                       </apex:pageBlockTable> 
                       
                       <apex:commandButton value="Add Service Tasks" action="{!processSelected}" rerender="table"/>
                     
 </apex:pageBlockSection>

 

 

 

  • May 09, 2011
  • Like
  • 0

Hi,  I am a bit stuck trying to figure out how to properly use the assign to attribute in the param component.

 

I am trying to display a list of categories (using command link component) .  Based on the category the user selects in the list , I want to filter out the services and display the filtered list below on the same page.

 

Here is the controller:

 

 

public with sharing class wrapperClassController {


public String category {get; set;}


public pagereference viewST(){
return NULL;
}


//This query displays my categories
public List<Service_Categories__c> getCategories(){
return [SELECT Name FROM Service_Categories__c WHERE Service_Name__c = 'NULL'];

}

public List<aServiceTask> servicetaskList {get; set;}

// This query displays my services - however nothing is returned since I beleive my category variable is not being assigned properly throughout the process .
public List<aServiceTask> getServiceTasks() {
if(servicetaskList == null) {
servicetaskList = new List<aServiceTask>();
for(Service_Categories__c a: [select Id, Name, Service_Name__c from Service_Categories__c where Name = :category AND Service_Name__c <>'NULL']) {

servicetaskList.add(new aServiceTask(a));
}
}
return servicetaskList;

}


}

 

 

Here is the Page:

 

 

<apex:page controller="wrapperClassController">

<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Work Categories">

<apex:dataList value="{!Categories}" var="c" id="table" type="none" >
<apex:commandLink value="{!c.Name}" action="{!ViewST}" >
<apex:param value="{!c.Name}" assignTo="{!category}"/>

</apex:commandlink>

</apex:dataList>

</apex:pageBlockSection>

<apex:pageBlockSection title="Service Tasks">

<apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
<apex:outputText value="{!category}"/>
<apex:pageBlockTable value="{!servicetasks}" var="a" id="table">
<apex:column >
<apex:inputCheckbox value="{!a.selected}"/>
</apex:column>
<apex:column value="{!a.ST.Service_Name__c}" />
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Thank you in advance!

 

  • May 08, 2011
  • Like
  • 0

Hi,  The code below  uses the Standard Account Controll and allows me to do inline edit for the account fields however it does not work for the contact fields, not sure why, can anyone help?

 

 <apex:pageBlock >
                    <apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" hideOnEdit="updatewizardButton" />
                    <apex:pageBlockButtons >
                                  <apex:commandButton value="Save" action="{!quicksave}" id="saveButton" />
                        <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" />
                    </apex:pageBlockButtons>
                   
                        <apex:pageBlockSection columns="2" title="Account Information" >
                            <apex:repeat value="{!$ObjectType.Account.FieldSets.Con_Account_Company_Info}" var="f">
                                <apex:outputField value="{!Account[f]}"/>
                            </apex:repeat>
                        </apex:pageBlockSection>

                    <apex:pageBlockSection columns="2" title="Contact Information" >
                           <apex:repeat value="{!Account.Contacts}" var="c">
                              <apex:repeat value="{!$ObjectType.Contact.FieldSets.Con_Account_Contact_Info}" var="f">
                                          <apex:outputField rendered="{!c.Contact_Type__c ='Primary Contact'}" value="{!c[f]}"/>
                              </apex:repeat>
                         </apex:repeat>
                    </apex:pageBlockSection>
                    
                </apex:pageBlock>

  • May 04, 2011
  • Like
  • 0

Hi,

 

I am looking to display a fieldset from my Contacts Object within the visualforce page that uses the Standard Account Controller.  I am not sure what notation to use  to call the Fieldset in the Contact (Child) object?????

 

FieldSet Name linked  to Account Object: Con_Account_Company_Info

FieldSet Name linked  to Contact Object: Con_Account_Contact_Info

 

Here is an example of a fieldset in the Account Object that works fine, which I want to mimic for the Contacts Object.

 

<apex:page standardController="Account" showHeader="false" tabStyle="account" >

 

<apex:pageBlockSection columns="2" title="Account Information" >
<apex:repeat value="{!$ObjectType.Account.FieldSets.Con_Account_Company_Info}" var="f">
<apex:outputField value="{!Account[f]}"/>
</apex:repeat>

 

Following the Dot Notation for calling child objects I was thinking the notation may look something like what I have below:

 

<apex:pageBlockSection columns="2" title="Contact Information" >
<apex:repeat value="{!$ObjectType.Account.Contact.FieldSets.Con_Account_Contact_Info}" var="f">
<apex:outputField value="{!Account.Contact[f]}"/>
</apex:repeat>

 

Please let me know if you can  help.   I will need to repeat this notation a few times within some custom objects as well, so If there is anything I should know about doing this with custom child objects of custom parent objects, please advise also.

 

Thanks,


Ricky

 

  • May 03, 2011
  • Like
  • 0

When laoding my custom field Multi-Select Pickist Values from the IDE I receive the follwoing erorr: Picklist Value too long for the max size 40

 

Is there a way to increase the length of the Multi-Select Picklist values? (Considering I do not get the same length restriction for my picklist values)

  • April 25, 2011
  • Like
  • 0

I created custom text fields to use as labels to get around the 40 character field constraint.  I want to display this associated fields as labels using field sets.  I created two field sets, one with the fields and one with the inputtext fields as labels.

 

My initial thought was two use to repeat functions but it loops around the 2nd field set too many times. Any thoughts on how I can achieve my objective?

 

 

 <apex:form >  
       <apex:pageBlock title="Without Field Set Use">  
       <apex:pageBlockSection title="Dynamic Object">  
           
          <apex:repeat value="{!$ObjectType.Field_Holder_1__c.FieldSets.ST00192_Labels}" var="fieldlabelAPIName">
        <apex:repeat value="{!$ObjectType.Field_Holder_1__c.FieldSets.ST00192}" var="fieldAPIName">
         
             <apex:pageblockSectionItem >
                 <apex:outputfield value="{!sObjectToBind[fieldlabelAPIName]}"/> 
                 <apex:inputField value="{!sObjectToBind[fieldAPIName]}"/>
             </apex:pageblockSectionItem>
           </apex:repeat>
                 </apex:repeat> 
       </apex:pageBlockSection>  
       </apex:pageBlock>  
   </apex:form>  

 

 

  • June 13, 2011
  • Like
  • 0

Hi, does anyone have an example or sample code of how I can create a list of Cities grouped by Province/State and Country within Visual Force.

 

I have my data in Service_Area__c object with populated records that have Country__c, Province_State__c and City__c  fields the object Name is a unique combination of Country Code, Province Code and City combined. For example CAD_ON_TORONTO.

 

I would like the vf page to look like:

 

Country X

      Province/State A

           City 1

           City 2

           etc

 

       Province/State B

             City 1

             City 2

             etc

 

Country Y

      Province/State A

           City 1

           City 2

           etc

 

       Province B

             City 1

             City 2

             etc

 

 

  thanks

  • June 04, 2011
  • Like
  • 0

Hi,


My objective is to add 3 Trade_Reference_Reports__c Object records for every unique Category__c field in Con_Service_Task_Request__c Object. In other words add 3 Trade References for every Service Task Requested within a Category that  does not already have 3 trade references.


My trigger runs fine when I add 1 Con_Service_Task_Request__c record at a time for a category that does not yet have any trade references, however when I add more than 1 Con_Service_Task_Request__c from the same category that does not yet have Trade References, its creates 3 trade references for each record under that category instead of the intended 1.


I am a bit stuck on how do handle this scenerio and was hoping someone can suggest some ideas?


I copied my Trigger code and method that allows my to process multiple records at once.



trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{

if (FireTrigger.getRun()) {


Con_Service_Task_Request__c[] STS = Trigger.new.deepClone();


Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();
Set<String> uniqueCategories = new Set<String>();
Map<ID, Con_Service_Task_Request__c> mapST = new Map<ID, Con_Service_Task_Request__c>();



List <Trade_Reference_Report__c> listTRV1 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact1 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV2 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact2 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV3 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact3 = new List<Contact>();


for(Con_Service_Task_Request__c ST : STS){
        
         accID.add(ST.Account__c);
         mapST_Account.put(ST.id , ST.Account__c);
         
         Contact Principalcontact=[SELECT ID FROM Contact WHERE AccountId = : ST.Account__c AND Contact_Type__c = 'Acct Principal Contact' limit 1];
         mapPrincipalAcctCont.put(ST.id, Principalcontact.ID); 
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID, TRV_Work_Category__c FROM Trade_Reference_Report__c 
         WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c];
             
	 if(ExistingTRVs == NULL)  {
                ExistingTRVs = New List<Trade_Reference_Report__c>();
                }
             
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
         
         mapST.put(ST.id, ST);
         
         for(Trade_Reference_Report__c WC : ExistingTRVs){
         uniqueCategories.add(WC.TRV_Work_Category__c);
        }
    }
    


for (Con_Service_Task_Request__c ST : Trigger.new) {



//CHECK TO SEE IF TRADE REFERENCE FOR PARTICULAR CATEGORY EXISTS, IF SO ASSIGN ID'S TO ST, //IF NOT CREATE 3 NEW TRV RECORDS - WHEN ADDING MULTIPLE Con_Service_Task_Request__c //RECORDS AT THE SAME TIME, IT CREATES 3 TRV RECORDS FOR ALL Con_Service_Task_Request__c RECORDS
// INSTEAD OF JUST THE FIRST ONE. UNSURE OF EASIEST WAY TO HANDLE THIS SCENERIO.

if ((uniqueCategories.Contains(ST.Category__c))&&(mapExistingTRVs.get(ST.id).size() > 0) && !(ST.Service__r.Trade_Reference_Reports__c ))
{

mapST.get(ST.id).Trade_Reference_Report_1__c = mapExistingTRVs.get(ST.id).get(0).ID;

mapST.get(ST.id).Trade_Reference_Report_2__c = mapExistingTRVs.get(ST.id).get(1).ID;

mapST.get(ST.id).Trade_Reference_Report_3__c = mapExistingTRVs.get(ST.id).get(2).ID;

}

if ((!uniqueCategories.Contains(ST.Category__c)) && !(ST.Service__r.Trade_Reference_Reports__c ))
{ 
{ 
 Contact TRVCompanyContact1 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 1');
 listTRVCompanyContact1.add(TRVCompanyContact1);
 
 Contact TRVCompanyContact2 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 2');
 listTRVCompanyContact2.add(TRVCompanyContact2);

Contact TRVCompanyContact3 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 3');
 listTRVCompanyContact3.add(TRVCompanyContact3);
       
}

}

insert listTRVCompanyContact1;
insert listTRVCompanyContact2;
insert listTRVCompanyContact3;


for (Integer i=0; i<Trigger.new.size(); i++) { 


if(listTRVCompanyContact1.size()> 0){ 
Trade_Reference_Report__c TRV1 = new Trade_Reference_Report__c(Account__c = STS[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact1[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(STS[i].id), TRV_Work_Category__c = STS[i].Category__c, TRV_Number__c = 1 );    
listTRV1.add(TRV1);
}

if(listTRVCompanyContact2.size()> 0){ 
Trade_Reference_Report__c TRV2 = new Trade_Reference_Report__c(Account__c = STS[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact2[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(STS[i].id), TRV_Work_Category__c = STS[i].Category__c, TRV_Number__c = 2 );    
listTRV2.add(TRV2);
}

if(listTRVCompanyContact3.size()> 0){ 
Trade_Reference_Report__c TRV3 = new Trade_Reference_Report__c(Account__c = STS[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact3[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(STS[i].id), TRV_Work_Category__c = STS[i].Category__c, TRV_Number__c = 3 );    
listTRV3.add(TRV3);
}

} 



insert listTRV1;
insert listTRV2;
insert listTRV3;


for (Integer i=0; i<STS.size(); i++) { 

Con_Service_Task_Request__c ST = STS[i];

if(listTRV1.size()> 0){ 

ST.Trade_Reference_Report_1__c = listTRV1[i].id;

}

if(listTRV2.size()> 0){ 

ST.Trade_Reference_Report_2__c = listTRV2[i].id;

}


if(listTRV3.size()> 0){ 

ST.Trade_Reference_Report_3__c = listTRV3[i].id;

}


update mapST.values();

}



}




public PageReference processSelected() {

    List<Service_Categories__c> selectedServiceTasks = new List<Service_Categories__c>();
    
    for(aServiceTask aST : getServiceTasks() ) {
        if(aST.selected == true) {
        selectedServiceTasks.add(aST.ST);
        }
     }
     System.debug('These are the selected Service Tasks...');
     List<Con_Service_Task_Request__c >Strs = new List<Con_Service_Task_Request__c >();
     for(Service_Categories__c ST : selectedServiceTasks) {
           
     servicecode = ST.Service_Name__c + ' - ' + countrycode + ' - ' + provincestatecode + ' - ' + city;
     
     Product2 service = [SELECT id FROM Product2 WHERE ProductCode = : servicecode limit 1]; 
     
     Con_Service_Task_Request__c newSTR = new Con_Service_Task_Request__c(Account__c = acctID, Service__c = service.id, Service_Code__c = servicecode, Service_Name__c = ST.Service_Name__c, Service_Area__c = servicearea, Country__c = country, 
     Province_State__c = provincestate, City__c = city,  Postal_Zip_Code__c = postalzip, Category__c = category,  Service_Task_Request_Status__c = 'Not Verified'); //Service__c = serviceid, 
     
     Strs.add(newSTR);
      system.debug(ST);
      
     }
     try {
     upsert Strs;
     } 
     catch (DmlException e) {
        
        
     }
     return null;
     }





  • June 03, 2011
  • Like
  • 0

I realize that trigger.new is read only so I created a map to update the fields in my trigger but still getting a read-only error. I cut out most of my code and left the relevant parts.  My code compiles but gives and error when running.

 

Any suggestions?

 

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{

if (FireTrigger.getRun()) {


Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();
Map<ID, Con_Service_Task_Request__c> mapST = new Map<ID, Con_Service_Task_Request__c>();



List <Trade_Reference_Report__c> listTRV1 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact1 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV2 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact2 = new List<Contact>();

List <Trade_Reference_Report__c> listTRV3 = new List<Trade_Reference_Report__c>();
List <Contact> listTRVCompanyContact3 = new List<Contact>();


for(Con_Service_Task_Request__c ST : trigger.new){
         
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID FROM Trade_Reference_Report__c 
         WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c limit 3]; 
             if(ExistingTRVs == NULL)  {
                ExistingTRVs = New List<Trade_Reference_Report__c>();
                }
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
         mapST.put(ST.id, ST);
    }
    


for (Con_Service_Task_Request__c ST : Trigger.new) {



//CHECK TO SEE IF TRADE REFERENCE FOR PARTICULAR CATEGORY EXISTS, IF SO ASSIGN ID'S TO ST, IF NOT CREATE 3
//NEW TRV RECORDS
if (mapExistingTRVs.get(ST.id).size() > 0 )
{

mapST.get(ST.id).Trade_Reference_Report_1__c = mapExistingTRVs.get(ST.id).get(0).ID;

mapST.get(ST.id).Trade_Reference_Report_2__c = mapExistingTRVs.get(ST.id).get(1).ID;

mapST.get(ST.id).Trade_Reference_Report_3__c = mapExistingTRVs.get(ST.id).get(2).ID;

}

if (mapExistingTRVs.get(ST.id).size() == 0 )
{ 
 Contact TRVCompanyContact1 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 1');
 listTRVCompanyContact1.add(TRVCompanyContact1);
 
 Contact TRVCompanyContact2 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 2');
 listTRVCompanyContact2.add(TRVCompanyContact2);

Contact TRVCompanyContact3 = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'TRV Company', LastName = 'Enter Last Name 3');
 listTRVCompanyContact3.add(TRVCompanyContact3);
       
}

}

insert listTRVCompanyContact1;
insert listTRVCompanyContact2;
insert listTRVCompanyContact3;


for (Integer i=0; i<Trigger.new.size(); i++) { 


if(listTRVCompanyContact1.size()> 0){ 
Trade_Reference_Report__c TRV1 = new Trade_Reference_Report__c(Account__c = Trigger.new[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact1[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(Trigger.new[i].id), TRV_Work_Category__c = Trigger.new[i].Category__c );    
listTRV1.add(TRV1);
}

if(listTRVCompanyContact2.size()> 0){ 
Trade_Reference_Report__c TRV2 = new Trade_Reference_Report__c(Account__c = Trigger.new[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact2[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(Trigger.new[i].id), TRV_Work_Category__c = Trigger.new[i].Category__c );    
listTRV2.add(TRV2);
}

if(listTRVCompanyContact3.size()> 0){ 
Trade_Reference_Report__c TRV3 = new Trade_Reference_Report__c(Account__c = Trigger.new[i].Account__c , TRV_Company_Contact__c = listTRVCompanyContact3[i].ID, TRV_Principal_Contact__c = mapPrincipalAcctCont.get(Trigger.new[i].id), TRV_Work_Category__c = Trigger.new[i].Category__c );    
listTRV3.add(TRV3);
}

} 



insert listTRV1;
insert listTRV2;
insert listTRV3;


for (Integer i=0; i<Trigger.new.size(); i++) { 

Con_Service_Task_Request__c ST = Trigger.new[i];

if(listTRV1.size()> 0){ 

ST.Trade_Reference_Report_1__c = listTRV1[i].id;

}

if(listTRV2.size()> 0){ 

ST.Trade_Reference_Report_2__c = listTRV2[i].id;

}


if(listTRV3.size()> 0){ 

ST.Trade_Reference_Report_3__c = listTRV3[i].id;

}
}


update mapST.values();

}



}

 

 

  • June 02, 2011
  • Like
  • 0

Hi,

 

I have been revising my trigger code as I had DML Insert statements inside my loop. I created a list and brought the DML statements outside of loop, but have ran into another issue as a result.  I need to create a contact and link the contact to the Bankruptcy_Judgements_Liens_Report__r custom object through the BJVLAgencyContact.ID lookup field.  When I insert outside of the loop, the actual contact ID is not captured since its not inserted.

 

 

trigger ConVerificationRecordSetup on Con_Service_Task_Request__c (after insert, after update) 
{
Set<ID> accID = new Set<ID>();
//map to contain Con_Service_Task_Request__c record's id as key and it's master Account record's ID as value
Map<ID, ID> mapST_Account = new Map<ID, ID>();
Map<ID, ID> mapPrincipalAcctCont = new Map<ID, ID>();
Map<ID, List<Trade_Reference_Report__c>> mapExistingTRVs = new Map<ID, List<Trade_Reference_Report__c>>();

List <Contact> listBJLVAgencyContact = new List<Contact>();
List <Bankruptcy_Judgements_Liens_Report__c> listBJLV = new 


for(Con_Service_Task_Request__c ST : trigger.new){
         //This "Con_Service_Task_Request__c" should be API Name of Master Detail relationship with the Account 
         accID.add(ST.Account__c);
         mapST_Account.put(ST.id , ST.Account__c);
         
         Contact Principalcontact=[SELECT ID FROM Contact WHERE AccountId = : ST.Account__c AND Contact_Type__c = 'Acct Principal Contact' limit 1];
         mapPrincipalAcctCont.put(ST.id, Principalcontact.ID); 
         
         List<Trade_Reference_Report__c> ExistingTRVs = [SELECT ID FROM Trade_Reference_Report__c WHERE Account__c = : ST.Account__c AND TRV_Work_Category__c = : ST.Category__c limit 3]; 
         mapExistingTRVs.put(ST.id, ExistingTRVs); 
    }
    
Map<Id,List<Account>> records = new Map<Id,List<Account>>();
for(Account a : [SELECT id , 
(select id from Bankruptcy_Judgements_Liens_Report__r) 

FROM Account 
WHERE id in : accID]) {
    if(!records.containsKey(a.id))  {
        records.put(a.id , new List<Account>());
    }
    records.get(a.id).add(a);   
}   

for (Con_Service_Task_Request__c ST : Trigger.new) {

//INSERT NEW BJLV RECORD IF REQUIRED AND DOES NOT YET EXIST 
if (records.get(mapST_Account.get(ST.id)).get(0).Bankruptcy_Judgements_Liens_Report__r.Size()  == 0) 

Contact BJLVAgencyContact = new Contact(AccountId = ST.Account__c , Contact_Type__c = 'BJLV Agency', LastName = 'Enter Last Name');
 listBJLVAgencyContact.add(BJLVAgencyContact);

Bankruptcy_Judgements_Liens_Report__c BJLV = new Bankruptcy_Judgements_Liens_Report__c(Account__c = ST.Account__c , BJLV_Agency_Contact__c = BJLVAgencyContact.ID ); //BJVLAgencyContact.ID does not exist at this stage since Insert //outside of the loop now   
 listBJLV.add(BJLV);
 
}


}
insert listBJLVAgencyContact;
insert listBJLV; //Does not link to Contact on Insert. How would I get it to link?
}

 

 

  • June 01, 2011
  • Like
  • 0