• jvelazquez
  • NEWBIE
  • 25 Points
  • Member since 2013

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 11
    Replies

Hi,

 

I am writing my first test class for visulaforce page Controller and I am facing problem to cover the test code.

Can any one recommen me how to do. Here is my Apex class and Test class

 

Apex Class:  

 

public List<Contact> SPFregistered{get; set;}    
    public String filterId{get; set;}
    private List<SelectOption> listoptions;    
     public Contact con{get; set;}  
    public ApexPages.StandardSetController controller{get; set;} 
    
      public List<Contact> contact
    {  
        get  
        {  
            if(controller!= null)  
                return (List<Contact>)controller.getRecords();  
            else  
                return null ;  
        }  
        set;} 
        
        public customCtrl(ApexPages.StandardSetController controller) { 
   
             contact = new List<Contact>() ;  
             con = new Contact() ;  
        
         }
  
    public customCtrl ()  
    {  
       
    }  
public PageReference getValues(){ if(filterId == 'All Contacts'){ if(UserInfo.getName() == 'Shane Theriault' || UserInfo.getName() == 'Lavanya Tangati'){ controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select AccountID,FirstName,Heat__c, LastName, Title, Status__c from Contact where Remove__c = false LIMIT 10000])); controller .setPageSize(50); }else if(UserInfo.getName() == 'Michael Lymburner'){

controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select AccountID,FirstName,Heat__c, LastName, Title, Status__c from Contact where Remove__c = false LIMIT 10000])); controller .setPageSize(50);

} }
public Boolean hasNext { get { return controller.getHasNext(); } set; }
public Boolean hasPrevious { get { return controller.getHasPrevious(); } set;
public Integer pageNumber { get { return controller.getPageNumber(); } set; }

}

 Test Class:

 

@isTest
private class customCtrlTestClass {
    static testMethod void validatecustomCtrl1() {
  
    List<Contact> lstOfContactsData = new List<Contact>{}; 
    List<User> users = new List<User>();      
  
       Account acc1 = new Account(Name='ABC',Sales_Country__c='USA',Site__c='XYZ',Type = 'Prospect',Podster__c = '005e0000000qFNy',SPF_Do_Not_Call__c=false);
       insert acc1;     
             
        for(Integer i = 0; i < 10; i++){
            Contact c = new Contact();
            c.LastName = 'Test Contact';
            c.Status__c = 'Active';
            c.Site__c = 'Headquarter Chicago';
            c.LeadSource='';
            c.Lead_Source_Most_Recent_Eloqua__c='Referral';
            c.AccountID = acc1.id;                       
            c.SPF_Registered__c = false;
            c.Status__c = 'Active';
            c.Remove__c = false;           
            lstOfContactsData.add(c);
             
        }
        insert lstOfContactsData; 
        
        Id profileid = [Select id from Profile where name = 'System Administrator'].id;   
        User BusinessUser = new User(email='business@test.com',                                     
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test2', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com',                                     
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test5', 
                                     LastName = 'TechnicalUser');
           users.add(BusinessUser );     
           users.add(TechnicalUser );
           //users.add(FinanceUser );
           //users.add(TreasuryUser );
           insert users;
  
              List<Contact> lstOfContacts = [SELECT AccountID,FirstName,Heat__c, LastName, Title, Status__c, Country__c,Email,Phone,Account_Type__c  FROM Contact where id In : lstOfContactsData ORDER BY Id Asc];
                   for(Contact cont : lstOfContacts){ 
                            PageReference pageRef = Page.contactsView;
                            pageRef .getParameters().put('id',cont.id);
                            Test.setCurrentPageReference(pageRef); 
                            } 
                     ApexPages.StandardSetController ctrl = new ApexPages.StandardSetController(lstOfContacts); 
                          // List<Contact> contact = (List<Contact>)ctrl.getRecords();                                       
                            //ctrl.setSelected(contact);                           
                                customCtrl cc = new customCtrl(ctrl);
                                customCtrl cc1 = new customCtrl();                                   
                                system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+cc);                                                                     
                                       System.RunAs(BusinessUser){
                                            cc.getValues();                                                     
                                            //cc.next();
                                            //cc.previous();
                                         }   
                                           
                }
 
 
  }

Hi,

 

I am writing my first test class for visulaforce page Controller and I am facing problem to cover the test code.

Can any one recommen me how to do. Here is my Apex class and Test class

 

Apex Class:  

 

public List<Contact> SPFregistered{get; set;}    
    public String filterId{get; set;}
    private List<SelectOption> listoptions;    
     public Contact con{get; set;}  
    public ApexPages.StandardSetController controller{get; set;} 
    
      public List<Contact> contact
    {  
        get  
        {  
            if(controller!= null)  
                return (List<Contact>)controller.getRecords();  
            else  
                return null ;  
        }  
        set;} 
        
        public customCtrl(ApexPages.StandardSetController controller) { 
   
             contact = new List<Contact>() ;  
             con = new Contact() ;  
        
         }
  
    public customCtrl ()  
    {  
       
    }  
public PageReference getValues(){ if(filterId == 'All Contacts'){ if(UserInfo.getName() == 'Shane Theriault' || UserInfo.getName() == 'Lavanya Tangati'){ controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select AccountID,FirstName,Heat__c, LastName, Title, Status__c from Contact where Remove__c = false LIMIT 10000])); controller .setPageSize(50); }else if(UserInfo.getName() == 'Michael Lymburner'){

controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select AccountID,FirstName,Heat__c, LastName, Title, Status__c from Contact where Remove__c = false LIMIT 10000])); controller .setPageSize(50);

} }
public Boolean hasNext { get { return controller.getHasNext(); } set; }
public Boolean hasPrevious { get { return controller.getHasPrevious(); } set;
public Integer pageNumber { get { return controller.getPageNumber(); } set; }

}

 Test Class:

 

@isTest
private class customCtrlTestClass {
    static testMethod void validatecustomCtrl1() {
  
    List<Contact> lstOfContactsData = new List<Contact>{}; 
    List<User> users = new List<User>();      
  
       Account acc1 = new Account(Name='ABC',Sales_Country__c='USA',Site__c='XYZ',Type = 'Prospect',Podster__c = '005e0000000qFNy',SPF_Do_Not_Call__c=false);
       insert acc1;     
             
        for(Integer i = 0; i < 10; i++){
            Contact c = new Contact();
            c.LastName = 'Test Contact';
            c.Status__c = 'Active';
            c.Site__c = 'Headquarter Chicago';
            c.LeadSource='';
            c.Lead_Source_Most_Recent_Eloqua__c='Referral';
            c.AccountID = acc1.id;                       
            c.SPF_Registered__c = false;
            c.Status__c = 'Active';
            c.Remove__c = false;           
            lstOfContactsData.add(c);
             
        }
        insert lstOfContactsData; 
        
        Id profileid = [Select id from Profile where name = 'System Administrator'].id;   
        User BusinessUser = new User(email='business@test.com',                                     
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test2', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com',                                     
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test5', 
                                     LastName = 'TechnicalUser');
           users.add(BusinessUser );     
           users.add(TechnicalUser );
           //users.add(FinanceUser );
           //users.add(TreasuryUser );
           insert users;
  
              List<Contact> lstOfContacts = [SELECT AccountID,FirstName,Heat__c, LastName, Title, Status__c, Country__c,Email,Phone,Account_Type__c  FROM Contact where id In : lstOfContactsData ORDER BY Id Asc];
                   for(Contact cont : lstOfContacts){ 
                            PageReference pageRef = Page.contactsView;
                            pageRef .getParameters().put('id',cont.id);
                            Test.setCurrentPageReference(pageRef); 
                            } 
                     ApexPages.StandardSetController ctrl = new ApexPages.StandardSetController(lstOfContacts); 
                          // List<Contact> contact = (List<Contact>)ctrl.getRecords();                                       
                            //ctrl.setSelected(contact);                           
                                customCtrl cc = new customCtrl(ctrl);
                                customCtrl cc1 = new customCtrl();                                   
                                system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+cc);                                                                     
                                       System.RunAs(BusinessUser){
                                            cc.getValues();                                                     
                                            //cc.next();
                                            //cc.previous();
                                         }   
                                           
                }
 
 
  }

 

 

Hi,

 

In my organisation an Opportunity is created from Contact related list. I have two feilds

LeadSource on Contact

LeadSource on Opportunity

 

 I have a requirement where I am supposed to update a feild value Lead Source in opportunity from Contact field Lead Source

 

I have written the below trigger which is not working since I am using after insert, after update in my trigger call.

 

trigger OpportunityLeadSourceUpdate on Opportunity (after insert, after update) {

    List<Contact> conList = new List<Contact>();
          
                
              
                    
                    OpportunityContactRole ContactRoles = [select OpportunityID, ContactID from OpportunityContactRole where OpportunityID =: trigger.new];
                    
                       System.debug('@@@@@@@@@@@@@@@@@@@@@'+ContactRoles );
                    
                        Contact c= [Select id, LeadSource from Contact where id =: ContactRoles.ContactID ];
                        Opportunity opp = [Select LeadSource from Opportunity where id =: ContactRoles.OpportunityID];
                                                                            
                           opp.LeadSource = c.LeadSource;
                                                                                                      
                     System.debug('@@@@@@@@@@@@@@@@@@@@@'+ opp.LeadSource);
                     
           
                        
         
}

 

I am not able to capture the value into opp.LeadSource since the trigger is firing after insertion.

 

Is there any workaround for this

 

Please help me

 

Thanks

Hi,

 

In my organisation an Opportunity is created from Contact related list. I have two feilds

LeadSource on Contact

LeadSource on Opportunity

 

 I have a requirement where I am supposed to update a feild value Lead Source in opportunity from Contact field Lead Source

 

I have written the below trigger which is not working since I am using after insert, after update in my trigger call.

 

trigger OpportunityLeadSourceUpdate on Opportunity (after insert, after update) {
List<Contact> conList = new List<Contact>();
OpportunityContactRole ContactRoles = [select OpportunityID, ContactID from OpportunityContactRole where OpportunityID =: trigger.new]; System.debug('@@@@@@@@@@@@@@@@@@@@@'+ContactRoles ); Contact c= [Select id, LeadSource from Contact where id =: ContactRoles.ContactID ]; Opportunity opp = [Select LeadSource from Opportunity where id =: ContactRoles.OpportunityID]; opp.LeadSource = c.LeadSource; System.debug('@@@@@@@@@@@@@@@@@@@@@'+ opp.LeadSource); }

 I am not able to capture the value into opp.LeadSource since the trigger is firing after insertion.

 

Is there any workaround for this

 

Please help me

 

Thanks

Hi, 

I have trigger that rolls up total number of contacts on Account, This trigger was working fine in sandbox, But when moved to production it is throwing errors at the backend  saying 'System.LimitException: Too many code statements: 200001'. My company production enviroment is integrated with 3rd party system. So everytime there is an update from external system this trigger is firing errors.

 

Below is my code:

 

trigger ContactRollUpOnAccounts on Contact (after delete, after insert, after update) {
        
  
  set<ID> AccountIds = new set<ID>();
  set<ID> conIDs = new Set<ID>();
 
  
  if(trigger.isInsert || trigger.isUpdate){
    for(Contact c : trigger.new){
      AccountIds.add(c.AccountId);
    }
  }
 
  
  if(trigger.isDelete){
    for(Contact c : trigger.old){
      AccountIds.add(c.AccountId);
    }
  }
 
 
   Map<ID, Contact> AccountMap = new Map<ID, Contact>([select id,AccountId
    from Contact where AccountId IN :AccountIds]);
 
  List<Account> AccountsToUpdate = new  List<Account>();
 
 
  for(Account a : [Select Id, Contacts__c from Account where Id IN :AccountIds ]){
        
      for (Contact con : AccountMap.values()) {
            if (con.AccountId == a.Id)
                conIDs.add(con.Id);
        }   
       if (a.Contacts__c!= conIDs.size())
            a.Contacts__c= conIDs.size();
              AccountsToUpdate.add(a);
    } 
 
  update AccountsToUpdate;
 }

 

 I understand the problem is because I am writing for loop within a for loop, but I am not aware of the workaround to avoid this.

 

Please help me with your valuiable thoughts

Hi, 

I have trigger that rolls up total number of contacts on Account, This trigger was working fine in sandbox, But when moved to production it is throwing errors at the backend  saying 'System.LimitException: Too many code statements: 200001'. My company production enviroment is integrated with 3rd party system. So everytime there is an update from external system this trigger is firing errors.

 

Below is my code:

 

trigger ContactRollUpOnAccounts on Contact (after delete, after insert, after update) {
        
  
  set<ID> AccountIds = new set<ID>();
  set<ID> conIDs = new Set<ID>();
 
  
  if(trigger.isInsert || trigger.isUpdate){
    for(Contact c : trigger.new){
      AccountIds.add(c.AccountId);
    }
  }
 
  
  if(trigger.isDelete){
    for(Contact c : trigger.old){
      AccountIds.add(c.AccountId);
    }
  }
 
 
   Map<ID, Contact> AccountMap = new Map<ID, Contact>([select id,AccountId
    from Contact where AccountId IN :AccountIds]);
 
  List<Account> AccountsToUpdate = new  List<Account>();
 
 
  for(Account a : [Select Id, Contacts__c from Account where Id IN :AccountIds ]){
        
      for (Contact con : AccountMap.values()) {
            if (con.AccountId == a.Id)
                conIDs.add(con.Id);
        }   
       if (a.Contacts__c!= conIDs.size())
            a.Contacts__c= conIDs.size();
              AccountsToUpdate.add(a);
    } 
 
  update AccountsToUpdate;
 }

 I understand the problem is because I am writing for loop within a for loop, but I am not aware of the workaround to avoid this.

 

Please help me with your valuiable thoughts

Hi,

 

I have a requirement where a pageblock table is being rendered based on the picklist value. And the values in the page block table are inline edited. Now my problem is when I try to do inline edit command buttons SAVE and CANCEL are not displaying . If I remove the pageblock rendering then i can see the command buttons. Please see below code

 

Visualforce Page:

 

<apex:actionRegion > 

<apex:selectList value="{!selectedList}" size="1">
<apex:selectOptions value="{!listoptions}"/>
<apex:actionSupport event="onchange" reRender="Panel"/>
</apex:selectList> 
</apex:actionRegion>

 

<apex:outputpanel id="Panel">
<apex:pageBlock rendered="{!selectedList == 'All Contacts'}"> 
<apex:pageBlockButtons >
<apex:commandButton action="{!saveme}" id="saveButton" value="Save" style="display: none;"/> 
<apex:commandButton id="cancelButton" value="Cancel" style="display: none;"/> 
</apex:pageBlockButtons> 
<apex:pageBlockTable value="{!contact}" var="c" rows="50">

<apex:column headerValue="Job Title">
<apex:actionRegion >
<apex:outputField value="{!c.Title}">
<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" />
</apex:outputField>
</apex:actionRegion>
</apex:column>

</apex:pageBlockTable> 
</apex:pageBlock>

</apex:outputpanel>     

 

I am not sure hwre I am missing out. I have gone through many blogs but couldnt find a case for inline editing

Please help me out with this

 

Hi,

 

I have a requirement where a pageblock table is being rendered based on the picklist value. And the values in the page block table are inline edited. Now my problem is when I try to do inline edit command buttons SAVE and CANCEL are not displaying . If I remove the pageblock rendering then i can see the command buttons. Please see below code

 

Visualforce Page:

 

<apex:actionRegion > 

<apex:selectList value="{!selectedList}" size="1">
<apex:selectOptions value="{!listoptions}"/>
<apex:actionSupport event="onchange" reRender="Panel"/>
</apex:selectList> 
</apex:actionRegion>

 

<apex:outputpanel id="Panel">
<apex:pageBlock rendered="{!selectedList == 'All Contacts'}"> 
<apex:pageBlockButtons >
<apex:commandButton action="{!saveme}" id="saveButton" value="Save" style="display: none;"/> 
<apex:commandButton id="cancelButton" value="Cancel" style="display: none;"/> 
</apex:pageBlockButtons> 
<apex:pageBlockTable value="{!contact}" var="c" rows="50">

<apex:column headerValue="Job Title">
<apex:actionRegion >
<apex:outputField value="{!c.Title}">
<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" />
</apex:outputField>
</apex:actionRegion>
</apex:column>

</apex:pageBlockTable> 
</apex:pageBlock>

</apex:outputpanel>     

 

I am not sure hwre I am missing out. I have gone through many blogs but couldnt find a case for inline editing

Please help me out with this

 

Hi 

 

I have scenario where PartnerNew is a Child object to Account. When I am trying to create PartnersNew record from the related list of account I am not able to capture the parentID of that related record. I am only getting the parentID of the record to which it is looking up.

 

 For example I clicked on an Account ABC . ABC account has a related list PartnerNew with no records. I click on New PartnersNew , What I want is to capture the ParentID of ABC record into PartnersNew. Is this Possible. I tried to capture this through visualforce and Javascript  but not through salesforce triggers.

 

Please provide me with inputs

 

Thanks in Advance

Hi,

 

I am writing my first test class for visulaforce page Controller and I am facing problem to cover the test code.

Can any one recommen me how to do. Here is my Apex class and Test class

 

Apex Class:  

 

public List<Contact> SPFregistered{get; set;}    
    public String filterId{get; set;}
    private List<SelectOption> listoptions;    
     public Contact con{get; set;}  
    public ApexPages.StandardSetController controller{get; set;} 
    
      public List<Contact> contact
    {  
        get  
        {  
            if(controller!= null)  
                return (List<Contact>)controller.getRecords();  
            else  
                return null ;  
        }  
        set;} 
        
        public customCtrl(ApexPages.StandardSetController controller) { 
   
             contact = new List<Contact>() ;  
             con = new Contact() ;  
        
         }
  
    public customCtrl ()  
    {  
       
    }  
public PageReference getValues(){ if(filterId == 'All Contacts'){ if(UserInfo.getName() == 'Shane Theriault' || UserInfo.getName() == 'Lavanya Tangati'){ controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select AccountID,FirstName,Heat__c, LastName, Title, Status__c from Contact where Remove__c = false LIMIT 10000])); controller .setPageSize(50); }else if(UserInfo.getName() == 'Michael Lymburner'){

controller = new ApexPages.StandardSetController(Database.getQueryLocator([Select AccountID,FirstName,Heat__c, LastName, Title, Status__c from Contact where Remove__c = false LIMIT 10000])); controller .setPageSize(50);

} }
public Boolean hasNext { get { return controller.getHasNext(); } set; }
public Boolean hasPrevious { get { return controller.getHasPrevious(); } set;
public Integer pageNumber { get { return controller.getPageNumber(); } set; }

}

 Test Class:

 

@isTest
private class customCtrlTestClass {
    static testMethod void validatecustomCtrl1() {
  
    List<Contact> lstOfContactsData = new List<Contact>{}; 
    List<User> users = new List<User>();      
  
       Account acc1 = new Account(Name='ABC',Sales_Country__c='USA',Site__c='XYZ',Type = 'Prospect',Podster__c = '005e0000000qFNy',SPF_Do_Not_Call__c=false);
       insert acc1;     
             
        for(Integer i = 0; i < 10; i++){
            Contact c = new Contact();
            c.LastName = 'Test Contact';
            c.Status__c = 'Active';
            c.Site__c = 'Headquarter Chicago';
            c.LeadSource='';
            c.Lead_Source_Most_Recent_Eloqua__c='Referral';
            c.AccountID = acc1.id;                       
            c.SPF_Registered__c = false;
            c.Status__c = 'Active';
            c.Remove__c = false;           
            lstOfContactsData.add(c);
             
        }
        insert lstOfContactsData; 
        
        Id profileid = [Select id from Profile where name = 'System Administrator'].id;   
        User BusinessUser = new User(email='business@test.com',                                     
                                     profileid = profileid, 
                                     UserName='business@test.com', 
                                     alias='bususer', CommunityNickName='bususer',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test2', 
                                     LastName = 'BusinessUser');
        User TechnicalUser = new User(email='technical@test.com',                                     
                                     profileid = profileid, 
                                     UserName='technical@test.com', 
                                     alias='tecuser', CommunityNickName='tecuser',
                                     TimeZoneSidKey='America/New_York', 
                                     LocaleSidKey='en_US', 
                                     EmailEncodingKey='ISO-8859-1',
                                     LanguageLocaleKey='en_US', 
                                     FirstName = 'Test5', 
                                     LastName = 'TechnicalUser');
           users.add(BusinessUser );     
           users.add(TechnicalUser );
           //users.add(FinanceUser );
           //users.add(TreasuryUser );
           insert users;
  
              List<Contact> lstOfContacts = [SELECT AccountID,FirstName,Heat__c, LastName, Title, Status__c, Country__c,Email,Phone,Account_Type__c  FROM Contact where id In : lstOfContactsData ORDER BY Id Asc];
                   for(Contact cont : lstOfContacts){ 
                            PageReference pageRef = Page.contactsView;
                            pageRef .getParameters().put('id',cont.id);
                            Test.setCurrentPageReference(pageRef); 
                            } 
                     ApexPages.StandardSetController ctrl = new ApexPages.StandardSetController(lstOfContacts); 
                          // List<Contact> contact = (List<Contact>)ctrl.getRecords();                                       
                            //ctrl.setSelected(contact);                           
                                customCtrl cc = new customCtrl(ctrl);
                                customCtrl cc1 = new customCtrl();                                   
                                system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+cc);                                                                     
                                       System.RunAs(BusinessUser){
                                            cc.getValues();                                                     
                                            //cc.next();
                                            //cc.previous();
                                         }   
                                           
                }
 
 
  }

Hi,

 

In my organisation an Opportunity is created from Contact related list. I have two feilds

LeadSource on Contact

LeadSource on Opportunity

 

 I have a requirement where I am supposed to update a feild value Lead Source in opportunity from Contact field Lead Source

 

I have written the below trigger which is not working since I am using after insert, after update in my trigger call.

 

trigger OpportunityLeadSourceUpdate on Opportunity (after insert, after update) {

    List<Contact> conList = new List<Contact>();
          
                
              
                    
                    OpportunityContactRole ContactRoles = [select OpportunityID, ContactID from OpportunityContactRole where OpportunityID =: trigger.new];
                    
                       System.debug('@@@@@@@@@@@@@@@@@@@@@'+ContactRoles );
                    
                        Contact c= [Select id, LeadSource from Contact where id =: ContactRoles.ContactID ];
                        Opportunity opp = [Select LeadSource from Opportunity where id =: ContactRoles.OpportunityID];
                                                                            
                           opp.LeadSource = c.LeadSource;
                                                                                                      
                     System.debug('@@@@@@@@@@@@@@@@@@@@@'+ opp.LeadSource);
                     
           
                        
         
}

 

I am not able to capture the value into opp.LeadSource since the trigger is firing after insertion.

 

Is there any workaround for this

 

Please help me

 

Thanks

Hi,

 

In my organisation an Opportunity is created from Contact related list. I have two feilds

LeadSource on Contact

LeadSource on Opportunity

 

 I have a requirement where I am supposed to update a feild value Lead Source in opportunity from Contact field Lead Source

 

I have written the below trigger which is not working since I am using after insert, after update in my trigger call.

 

trigger OpportunityLeadSourceUpdate on Opportunity (after insert, after update) {
List<Contact> conList = new List<Contact>();
OpportunityContactRole ContactRoles = [select OpportunityID, ContactID from OpportunityContactRole where OpportunityID =: trigger.new]; System.debug('@@@@@@@@@@@@@@@@@@@@@'+ContactRoles ); Contact c= [Select id, LeadSource from Contact where id =: ContactRoles.ContactID ]; Opportunity opp = [Select LeadSource from Opportunity where id =: ContactRoles.OpportunityID]; opp.LeadSource = c.LeadSource; System.debug('@@@@@@@@@@@@@@@@@@@@@'+ opp.LeadSource); }

 I am not able to capture the value into opp.LeadSource since the trigger is firing after insertion.

 

Is there any workaround for this

 

Please help me

 

Thanks

Hi, 

I have trigger that rolls up total number of contacts on Account, This trigger was working fine in sandbox, But when moved to production it is throwing errors at the backend  saying 'System.LimitException: Too many code statements: 200001'. My company production enviroment is integrated with 3rd party system. So everytime there is an update from external system this trigger is firing errors.

 

Below is my code:

 

trigger ContactRollUpOnAccounts on Contact (after delete, after insert, after update) {
        
  
  set<ID> AccountIds = new set<ID>();
  set<ID> conIDs = new Set<ID>();
 
  
  if(trigger.isInsert || trigger.isUpdate){
    for(Contact c : trigger.new){
      AccountIds.add(c.AccountId);
    }
  }
 
  
  if(trigger.isDelete){
    for(Contact c : trigger.old){
      AccountIds.add(c.AccountId);
    }
  }
 
 
   Map<ID, Contact> AccountMap = new Map<ID, Contact>([select id,AccountId
    from Contact where AccountId IN :AccountIds]);
 
  List<Account> AccountsToUpdate = new  List<Account>();
 
 
  for(Account a : [Select Id, Contacts__c from Account where Id IN :AccountIds ]){
        
      for (Contact con : AccountMap.values()) {
            if (con.AccountId == a.Id)
                conIDs.add(con.Id);
        }   
       if (a.Contacts__c!= conIDs.size())
            a.Contacts__c= conIDs.size();
              AccountsToUpdate.add(a);
    } 
 
  update AccountsToUpdate;
 }

 

 I understand the problem is because I am writing for loop within a for loop, but I am not aware of the workaround to avoid this.

 

Please help me with your valuiable thoughts

Hi,

 

I have a requirement where a pageblock table is being rendered based on the picklist value. And the values in the page block table are inline edited. Now my problem is when I try to do inline edit command buttons SAVE and CANCEL are not displaying . If I remove the pageblock rendering then i can see the command buttons. Please see below code

 

Visualforce Page:

 

<apex:actionRegion > 

<apex:selectList value="{!selectedList}" size="1">
<apex:selectOptions value="{!listoptions}"/>
<apex:actionSupport event="onchange" reRender="Panel"/>
</apex:selectList> 
</apex:actionRegion>

 

<apex:outputpanel id="Panel">
<apex:pageBlock rendered="{!selectedList == 'All Contacts'}"> 
<apex:pageBlockButtons >
<apex:commandButton action="{!saveme}" id="saveButton" value="Save" style="display: none;"/> 
<apex:commandButton id="cancelButton" value="Cancel" style="display: none;"/> 
</apex:pageBlockButtons> 
<apex:pageBlockTable value="{!contact}" var="c" rows="50">

<apex:column headerValue="Job Title">
<apex:actionRegion >
<apex:outputField value="{!c.Title}">
<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" />
</apex:outputField>
</apex:actionRegion>
</apex:column>

</apex:pageBlockTable> 
</apex:pageBlock>

</apex:outputpanel>     

 

I am not sure hwre I am missing out. I have gone through many blogs but couldnt find a case for inline editing

Please help me out with this

 

Hi,

 

I have a requirement where a pageblock table is being rendered based on the picklist value. And the values in the page block table are inline edited. Now my problem is when I try to do inline edit command buttons SAVE and CANCEL are not displaying . If I remove the pageblock rendering then i can see the command buttons. Please see below code

 

Visualforce Page:

 

<apex:actionRegion > 

<apex:selectList value="{!selectedList}" size="1">
<apex:selectOptions value="{!listoptions}"/>
<apex:actionSupport event="onchange" reRender="Panel"/>
</apex:selectList> 
</apex:actionRegion>

 

<apex:outputpanel id="Panel">
<apex:pageBlock rendered="{!selectedList == 'All Contacts'}"> 
<apex:pageBlockButtons >
<apex:commandButton action="{!saveme}" id="saveButton" value="Save" style="display: none;"/> 
<apex:commandButton id="cancelButton" value="Cancel" style="display: none;"/> 
</apex:pageBlockButtons> 
<apex:pageBlockTable value="{!contact}" var="c" rows="50">

<apex:column headerValue="Job Title">
<apex:actionRegion >
<apex:outputField value="{!c.Title}">
<apex:inlineEditSupport event="ondblClick" showOnEdit="saveButton,cancelButton" />
</apex:outputField>
</apex:actionRegion>
</apex:column>

</apex:pageBlockTable> 
</apex:pageBlock>

</apex:outputpanel>     

 

I am not sure hwre I am missing out. I have gone through many blogs but couldnt find a case for inline editing

Please help me out with this

 

Hey guys,

 

Ran into an issue which looks like a bug to me.

 

So I have some controls for a VF page at the top inside an output panel. The output panel is rendered based on a certain value in the custom controller I am using. Now when i try and use the command buttons inside the panel, the page just refreshes and the action method is not hit at all.

 

<apex:outputPanel rendered="{!statusCode == 200}">
<table style="width:100%;">
<tr>
<td style="vertical-align: middle;">

<apex:commandButton action="{!RedirectToReports}" title="PDF" value="PDF" ></apex:commandButton>

</td>

</tr>

</table>

</apex:outputPanel>

 

If I remove [ rendered="{!statusCode == 200}" ] then the page works correctly and the buttons do what they are meant to.

 

Is this by design or have i stumbled upon a really basic bug?

 

Cheers

Hi all,

Here the situation, There are dropdown menu and pageblocktable. I want to change the values of pageblocktable when cha change the value of dorp down. plz someone explain with a example.

 

Thanx

Chamil Madusanka