• Vempally
  • NEWBIE
  • 395 Points
  • Member since 2014


  • Chatter
    Feed
  • 4
    Best Answers
  • 2
    Likes Received
  • 3
    Likes Given
  • 55
    Questions
  • 66
    Replies
Hi everyone...
 
trigger CustomRollupSummary on Contact (after insert, after update, after delete, after undelete) {
	
    if(trigger.isInsert && Trigger.isAfter){
    List<Account> lst_accounts = new list<Account>();
    //decimal Value =0;
    set<id> account_ids = new set<id>();
    for(Contact c : trigger.new){
        account_ids.add(c.accountid);
        system.debug('account_ids' + account_ids);
    }
    Map<id, Account> map_accounts = new Map<id, Account>([select id, name from Account where id in : account_ids]);
    system.debug('map_accounts' + map_accounts);
    system.debug('map_accounts' + map_accounts.values());
        for(Account a : map_accounts.values()){
        system.debug('account' + a);
        a.Amount_Sum__c = 0;
    	//for(Contact c :[select id, name, amount__c from contact where accountid =: a.Id])
        for(Contact c : a.contacts)
    {
       system.debug('Contact' + c);
       
       a.Amount_Sum__c += c.amount__c;
    
    }
            lst_accounts.add(a);
    }
    system.debug('updated accounts' + lst_accounts);
    update lst_accounts;
    }
   /* List<Contact> lst_contacts = new  List<Contact>();
    for(Account a : lst_account){
        lst_contacts.add(a.contacts);
    	system.debug('lst_contacts');
    */
}

In the for loop where iam retrieving contacts based on an account, when SOQL is used its working fine but when the soql is replaced with a a.contacts the for loop is not getting executed... Why...?

 
Hi Everyone,

Can anyone give the code and explanation where i need to udate parent field with the value calculated with child fields.

Eg: Rollup Summary for Sum(). Need trigger code fro this for understanding.
public with sharing class WrapPractice {

     public List<Wrapper> wrap_lst {get; set;}

    public List<Account> acc_lst {get; set;}
    
    public List<Wrapper> selected_lst {get; set;}


    public PageReference showSelected() {
    
        selected_lst = new List<Wrapper>();
        
        for(Wrapper w: wrap_lst)
            if(w.chk == true)
                selected_lst.add(w);
        system.debug(selected_lst);
        
        String lst_serialize = json.serialize(selected_lst);
        system.debug('serialised string  ' + lst_serialize);
        
        Pagereference pg = page.show_accounts;
        pg.getParameters().put('lst_serialize', lst_serialize);
        return pg;
    }

    

    public WrapPractice(){
    
        acc_lst = new List<Account>();
        
        acc_lst = [select id, name, accountnumber from Account];
        
        system.debug('Account List :'+ acc_lst);
        
        wrap_lst = new List<Wrapper>();
        
        for(Account acc : acc_lst)
         wrap_lst.add(new Wrapper(acc));
         
         system.debug('wraplist'+ wrap_lst);
        
    
    }
    
    Public Class Wrapper{
    
        public Boolean chk {get; set;}
        public Account acc {get; set;}
        
        public Wrapper (Account acc){
        
        this.acc = acc;
        chk = false;
        
        
        }
    
    }


}

VisualForce
 
<apex:page controller="WrapPractice">
<apex:form >
 <apex:pageBlock >
     <apex:pageBlockSection >
     
         <apex:commandButton value="show" action="{!showSelected}"/>
         <apex:pageBlockTable value="{!wrap_lst}" var="w">
             <apex:column >
             
                 <apex:inputCheckbox value="{!w.chk}"/>
             </apex:column>
             
             <apex:column >
             
                 <apex:outputField value="{!w.acc.id}"/>
             </apex:column>
             <apex:column >
             
                 <apex:outputField value="{!w.acc.name}"/>
             </apex:column>
             <apex:column >
             
                 <apex:outputField value="{!w.acc.accountnumber}"/>
             </apex:column>
         
         </apex:pageBlockTable>
     
     <apex:pageBlockTable value="{!selected_lst}" var="slst">
             <apex:column >
             
                 <apex:inputCheckbox value="{!slst.chk}"/>
             </apex:column>
             
             <apex:column >
             
                 <apex:outputField value="{!slst.acc.id}"/>
             </apex:column>
             <apex:column >
             
                 <apex:outputField value="{!slst.acc.name}"/>
             </apex:column>
             <apex:column >
             
                 <apex:outputField value="{!slst.acc.accountnumber}"/>
             </apex:column>
         
         </apex:pageBlockTable>
     </apex:pageBlockSection>
 
 </apex:pageBlock>
 </apex:form>
</apex:page>

 
Hi all,
Can you pls help me with the below errors i am getting. I am just trying to replace a field with a different field in the VF page. I have made all the necessary changes in Controller and helper class but i get this error in the first line :- Compile Error: unexpected token: 'public with sharing class  at line 1 column 0 both controller and helper classs pls help.
User-added image
User-added image

Pls Help.. Thanks in advance.Any help is highly appreciated
Thanks!!
 

public class A{
  public class B {
  }
  public class C {
       public A.B show(){}
  }
}

------------
Look above exampe. I have one inner class C.I need to create instance of that class.
Can any one help me to create instance of class C and call method show of class C.

 
Hello friends

I have workflow rule on Opportunity . In Account , I have custom field IsStage, Data Type=Text
In workflow , action item =field Update, if  StageName=Closed Won then this value should reflect in IsStage.

I have wriiten as follows but is show error. Can anyone let me know?
Account.IsStage__c =  CONTAINS(StageName, "Closed Won") 

Regards
Krishna
Hi folks,
         Can anyone tell me how to get the dependent picklist values based on the Controlling picklist value in Apex?
I need a sample code for that..


Thanks in advance
Karthick
Hi guys.
I started to learn Apex recently.
Then I found that many things can be write with case insensitive character.
Such as:
  • Object name:
    • You can write 
      public pagereference method1() { ..}
      instead of 
    • public PageReference method1() { ..}
  • Variable name
    • This will be compile error
    • Integer I;
      Integer i;
  • SOQL and SOSL statements
    • Account[] accts = [sELect ID From ACCouNT where nAme = 'fred'];
I refering to this : http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_variables.htm

Just to make sure, are there other case-insensitive things that can be happen on Apex ?
Hi,

i am trying to print the campaign member list in my vf page but it's giving me an error
Can anyone please help me?
below is my code..
<apex:page StandardController="Campaign"  extensions="CampaignMemController">
    <apex:form >
        <apex:pageBlock title="Campaign Members Details" mode="maindetail">
            <apex:pageBlockSection title="Campaign Members"  id="cm3">
                <apex:pageblocktable value="{!cm}" var="lead">
                        <apex:column headerValue="Name">
                            <apex:outputfield value="{!lead.Id}" />
                        </apex:column>
    
   </apex:pageblocktable>
                      </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
 
public with sharing class CampaignMemController {

    public Campaign camp {get; set; }
    list<contact> con = [SELECT id FROM contact];
    
    list<campaignmember> cmlist = [SELECT id, contactid FROM campaignmember];
    list<contact> conlist = new list<contact>();
     public CampaignMemController(ApexPages.StandardController controller) {
         camp  = (Campaign)controller.getRecord();
  
  
    for(campaignmember cm : cmlist)
{
     for(contact c : con)
    {
             if(c.id == cm.contactid)
                              conlist.add(c);
     }
    
//System.debug('All the campaignmemebers under contact '+con.name+'are'+camList );
        }  
    } 

}
Hi Team

I have a question so i am using <apex:outputlable> to display a label in the UI. So how can i make the background of entire lable to Black.??
Should i write css or is there any attribue in outputlable that support my requirement..Please let me know..Thanks in advance

User-added image

i reuire that when i click  on edit button (on right hand side) then only it shud show save button  but its showing save button before only.
how to do that.


<apex:commandLink value="Edit" action="{!enabledEditMode1}" style="margin-left: 69%">
     <apex:actionSupport event="onclick" reRender="panel1"/>
     </apex:commandLink>
    
   </div>
   <div class="panel-body">
   Email
  
  
 
    <apex:outputPanel id="panel1">
    <apex:commandButton action="{!save}" value="Save"/>
        <apex:outputfield value="{!account.Email__c}" style="margin-left: 60%"></apex:outputfield>
      <apex:inputField value="{!account.Email__c}"  rendered="{!isEdit1}" style="margin-left: 60%"></apex:inputField>

     </apex:outputPanel>
   </div>
Hi,

Could anyone prapose any setting/solution for below?
While writing the "Visualforce" page code given a controller & methods which are not created.
After it shown the error and option to create,Clicked on the option to created the expected code.
When move that tab the autogenerated code is overlapping & not in readable format.

  code overlappingCode
Hi All,

I want to access campaign field from lead object  to visualforce using custom controller. For this,is the right way to write trigger? Suppose If I write trigger then how to call trigger from visualforce?

Kindly support and suggest.

Thank You.