• Girbson Bijou
  • NEWBIE
  • 20 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 6
    Replies
I want to update some field child with the same value of the parent anytime the parent is updated. With this below code, it fire only when a record is create. But it does not update the field on child when the parent is update. I remind that , the contition to just update it i
trigger AutoOutput on 	Output__c (after insert, after update) {
    if(Trigger.isInsert){
    List<Output__c> Output = new List<Output__c>();
 
    for (Output__c NewOut : Trigger.New) {
        if ( NewOut.Project_Type__c =='House'&& NewOut.Housing_If_Sanitation__c==NULL) {
            Output__c OutputChild = new Output__c();
            OutputChild.Housing_If_Sanitation__c= NewOut.Id;
            OutputChild.Project_Type__c = 'Sanitition';
            OutputChild.RecordTypeId=NewOut.RecordTypeId;
            OutputChild.Description__c=NewOut.Description__c;
            OutputChild.Locality__c=NewOut.Locality__c;
            OutputChild.Milestone__c= NewOut.Milestone__c;
            OutputChild.Address__c = NewOut.Address__c;
            OutputChild.claust__c=NewOut.claust__c;
            OutputChild.A__c=NewOut.A__c;
            OutputChild.Besem__c = NewOut.Besem__c;
            Output.add(OutputChild);
            }     
       
        }
        upsert Output;   
    }  
      
}

s when  NewOut.Housing_If_Sanitation__c !=NULL
Where do you thank the problem is. the trigger is save but does not fire.  The idee is to create a child record on a self relationship when outputType is House. Help me please
trigger AutoOutput on 	Output__c (after insert, after update) {
    List<Output__c> Output = new List<Output__c>();

     
    for (Output__c NewOut : Trigger.New) {
        if ( NewOut.OutputType__c =='House') {
            Output__c OutputChild = new Output__c();
            OutputChild.Housing_If_Sanitation__c= NewOut.Id;
            OutputChild.Project_Type__c = 'Sanitition';
            OutputChild.RecordTypeId='Infrastructure';
            OutputChild.Description__c='Discrption';
            OutputChild.Locality__c='ghjggh';
            Output.add(OutputChild);
        }
    }
    upsert Output;
}
I have a lookup relationship between Contract(Parent) and Expenses__c
want to summarize the value of the field called Amout in Expenses__c to a custom field in Contract called Tot_instalment__c.  Please help me to find where the errors are in the code. Attached is the list of the problem.
trigger UpdateTotInstalment on Expenses__c (after insert, after delete, after undelete, after update) {
    set<id> ids=new set<id>();
    for(Expenses__c exp: trigger.new)
        ids.add(exp.ContractNumber__c);
    List<contract> contractToUpdate=new List<Contract>();
    Map<ID, contract> cont = new Map<ID, contract>([select id ,Tot_Instalment__c from Contract where id:=ids]);
    AggregateResult[] groupedResults = [SELECT ContractNumber__c,SUM(Amount__c)amt FROM Expenses__c where ContractNumber__c in:ids group by ContractNumber__c];

    for(AggregateResult Results: groupedResults){
         Id ContractNumber__c =(id) Results.get('ContractNumber__c');         
         Contract c = cont.get(ContractNumber__c);
         c.Tot_Instalment__c=(integer)Results.get('amt');
         contractToUpdate.add(c);
    }    
  update contractToUpdate;
}

User-added image
Please Help me to write class or trigger to send  the list of campaign associated to contact Campaign Member by email every week. I want to notice that campaign member does not have a loging on Salesforce. Each contact should receive only  the list of Campaign associate to them.  
Duplicate Value in field updateed by trigger.
My objective is to have the names of the campaign member in a field called Acteurs in Campaign separate by comma. 
 The code belows works, but i have the following issue:
   - All the campaignMember Name, are not displays in the campaign Custom field(Acteurs__c)
   - when i update the campaign members, it re-copy the name of all to the campaign member  to the Custom field(Acteurs__c) which cause duplicate name.
     
     Below are my Code:
Trigger allActors on CampaignMember (after update, after insert, after delete, after undelete){
    List <CampaignMember> cm = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;
    
    List <Id> campId = new List<Id> ();
    
    for (CampaignMember AllMember : cm) {
           campId.add(AllMember.CampaignId);
   }
   
   List< Campaign> campaignList = [ SELECT id, Acteurs__c, (SELECT Name  from  CampaignMembers) From Campaign 
                                    Where id in:campId];
                                    
    for (Campaign camp: campaignList){
        if (camp.CampaignMembers.size()>0){
            //camp.Name = string.valueOf(camp.CampaignMembers[0].Name);
            for(integer i =1; i < camp.CampaignMembers.size(); i++)
                camp.Acteurs__c = camp.Acteurs__c+';'+string.valueOf(camp.CampaignMembers[i].Name);
        }
            else
            camp.Acteurs__c = null;
        }   
                    update campaignList;

    }
	
	
	//Test Class
	
	@isTest Private class AllActorsTest{
   
    @isTest static void InsetCm(){
    Campaign c = new Campaign ();
    c.Name = 'My Campaign';
    Insert c;
        
    CampaignMember cm = new CampaignMember();
    contact cont = new Contact (firstName='Bijou', lastName ='Girbson');
    Upsert cont;  
    cm.CampaignId = c.Id;
    cm.ContactId = cont.Id;


    insert cm;
        
 
    Delete cm;

   }
}

 
I need to have the first name of the the campaign member in a field called Acteurs in Campaign separate by comma. 
Se the attached picture. 
User-added image

the main error i get in this peice of code is: 
Method does not exist or incorrect signature: void add(Campaign) from the type List<Id> at line 7 column 19
 
Trigger allActors on CampaignMember (after update, after insert, after delete, after undelete){
    List <CampaignMember> cm = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;
    
    List <Id> campId = new List<Id> ();
    
    for (CampaignMember AllMember : cm) {
           campId.add(AllMember.Campaign);
   }
   
   List< Campaign> campaignList = [ SELECT id, (SELECT FirstName from  CampaignMembers) From Campaign 
                                    Where id in:campId];
                                    
    for (Campaign camp: campaignList){
        if (camp.CampaignMember.size()>0){
            camp.Name = string.valueOf(camp.CampaignMember[0].Acteurs__c);
            for(integer i =1; i < camp.CampaignMember.size(); i++)
                camp.Acteurs__c = camp.Acteurs__c+';'+string.valueOf(camp.CampaignMembers[i].Acteurs__c);
        }
            else
            camp.Acteurs__c = null;
        }
        
        
            update campaignList;

    }

 
I need to concatenate the individual CampaignMember Contact names into a single field for each Campaign (again, as below).
User-added image
The Controller:Here is what the page display

public class FuelReportController {
 public List<Gas_Cargo__c> fuel{get;set;}

     public FuelReportController() {

   fuel = [
          
      SELECT Tank__r.Name, Name,  Date_Receive__c ,    Number_Of_Gallons__c, Cost_in_HTG__c,  Old_Cargo_Balance__c, BeginingCargo__c,  Given__c, Available__c , Status__c
      FROM Gas_Cargo__c
      WHERE Date_Receive__c = THIS_MONTH
      ORDER BY Date_Receive__c];
      
            }
}

VF is:
<apex:page showHeader="false" sidebar="false"  standardStylesheets="false" Controller="FuelReportController"  applyBodyTag="false" >
      
    <table style="width:100%;border-collapse: collapse;">     
      
      <tr>
                  <td> <b>Id Cargo </b></td>
                  <td> <b>Tank </b></td>
                  <td> <b>Date Received </b></td>
                  <td> <b># Gallons </b></td>
                  <td> <b>Cost(HTG) </b></td>
                  <td> <b>Old Balance </b></td>
                  <td> <b>Begining Stock</b></td>
                  <td> <b>Given</b></td>
                  <td> <b>Available</b></td>
                  <td> <b>Status</b></td>
                  
              </tr>
  
          
       
          <apex:repeat value="{!fuel}" var="c">  
              <tr>
                 
                  <td>!c.Name</td>
                  <td>!c.Date_Receive__c</td>
                  <td>!c.Number_Of_Gallons__c</td>
                  <td>!c.Cost_in_HTG__c</td>
                  <td>!c.Old_Cargo_Balance__c</td>
                  <td>!c.BeginingCargo__c</td>
                  <td>!c.Given__c</td>
                  <td>!c.Available__c</td>
                  <td>!c.Status__c</td>              
              </tr>      
               
             </apex:repeat>  
          
      </table>
      
</apex:page>

 
How can you help me please?
I have two objects: Employee and Leave. Leave is a child of Employee.
I want write a trigger to assign leave type to each employee depending on some specific criteria.
for example:
if the gender of an employee is Female  && his status is fulltime , the trigger should create the following the record on the leave object:
- Maternity Leave
- Annual Leave
- Personal Leave
- unpaid leave

if the gender of an employee is Male  && his status is fulltime , the trigger should create the 3 following the record on the leave object:

- Paternity Leave
- Annual Leave
- Personal Leave
- Unpaid Leave

if the gender of an employee is Male || Female and  his status is part time , the trigger should create the  following the record on the leave object:
- Unpaid Leave

NB: I have already write a confitional formula to assign the Number of day for each type of Leave.

Here the sample of code that I have. I create a separate trigger for each trigger,  but i can not create multiple childs record with specific criteria in one trigger.


trigger CreateLeave3 on Employee__c (after insert ) {
List<Leave__c> Leaves = new List<Leave__c>();


    for(Employee__c l : trigger.new)
    {
     if(l.Status__c =='Emplyee' && l.Gender__c =='Female' ){
       Leave__c Child = new Leave__c ();
       Child.Employee__c = l.id;
       Child.Leave_Type__c = 'Maternity Leaves'; 
       Leaves.add(Child);      
    }
}
    insert Leaves;
    
}
I want to update some field child with the same value of the parent anytime the parent is updated. With this below code, it fire only when a record is create. But it does not update the field on child when the parent is update. I remind that , the contition to just update it i
trigger AutoOutput on 	Output__c (after insert, after update) {
    if(Trigger.isInsert){
    List<Output__c> Output = new List<Output__c>();
 
    for (Output__c NewOut : Trigger.New) {
        if ( NewOut.Project_Type__c =='House'&& NewOut.Housing_If_Sanitation__c==NULL) {
            Output__c OutputChild = new Output__c();
            OutputChild.Housing_If_Sanitation__c= NewOut.Id;
            OutputChild.Project_Type__c = 'Sanitition';
            OutputChild.RecordTypeId=NewOut.RecordTypeId;
            OutputChild.Description__c=NewOut.Description__c;
            OutputChild.Locality__c=NewOut.Locality__c;
            OutputChild.Milestone__c= NewOut.Milestone__c;
            OutputChild.Address__c = NewOut.Address__c;
            OutputChild.claust__c=NewOut.claust__c;
            OutputChild.A__c=NewOut.A__c;
            OutputChild.Besem__c = NewOut.Besem__c;
            Output.add(OutputChild);
            }     
       
        }
        upsert Output;   
    }  
      
}

s when  NewOut.Housing_If_Sanitation__c !=NULL
Where do you thank the problem is. the trigger is save but does not fire.  The idee is to create a child record on a self relationship when outputType is House. Help me please
trigger AutoOutput on 	Output__c (after insert, after update) {
    List<Output__c> Output = new List<Output__c>();

     
    for (Output__c NewOut : Trigger.New) {
        if ( NewOut.OutputType__c =='House') {
            Output__c OutputChild = new Output__c();
            OutputChild.Housing_If_Sanitation__c= NewOut.Id;
            OutputChild.Project_Type__c = 'Sanitition';
            OutputChild.RecordTypeId='Infrastructure';
            OutputChild.Description__c='Discrption';
            OutputChild.Locality__c='ghjggh';
            Output.add(OutputChild);
        }
    }
    upsert Output;
}
I have a lookup relationship between Contract(Parent) and Expenses__c
want to summarize the value of the field called Amout in Expenses__c to a custom field in Contract called Tot_instalment__c.  Please help me to find where the errors are in the code. Attached is the list of the problem.
trigger UpdateTotInstalment on Expenses__c (after insert, after delete, after undelete, after update) {
    set<id> ids=new set<id>();
    for(Expenses__c exp: trigger.new)
        ids.add(exp.ContractNumber__c);
    List<contract> contractToUpdate=new List<Contract>();
    Map<ID, contract> cont = new Map<ID, contract>([select id ,Tot_Instalment__c from Contract where id:=ids]);
    AggregateResult[] groupedResults = [SELECT ContractNumber__c,SUM(Amount__c)amt FROM Expenses__c where ContractNumber__c in:ids group by ContractNumber__c];

    for(AggregateResult Results: groupedResults){
         Id ContractNumber__c =(id) Results.get('ContractNumber__c');         
         Contract c = cont.get(ContractNumber__c);
         c.Tot_Instalment__c=(integer)Results.get('amt');
         contractToUpdate.add(c);
    }    
  update contractToUpdate;
}

User-added image
Please Help me to write class or trigger to send  the list of campaign associated to contact Campaign Member by email every week. I want to notice that campaign member does not have a loging on Salesforce. Each contact should receive only  the list of Campaign associate to them.  
Duplicate Value in field updateed by trigger.
My objective is to have the names of the campaign member in a field called Acteurs in Campaign separate by comma. 
 The code belows works, but i have the following issue:
   - All the campaignMember Name, are not displays in the campaign Custom field(Acteurs__c)
   - when i update the campaign members, it re-copy the name of all to the campaign member  to the Custom field(Acteurs__c) which cause duplicate name.
     
     Below are my Code:
Trigger allActors on CampaignMember (after update, after insert, after delete, after undelete){
    List <CampaignMember> cm = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;
    
    List <Id> campId = new List<Id> ();
    
    for (CampaignMember AllMember : cm) {
           campId.add(AllMember.CampaignId);
   }
   
   List< Campaign> campaignList = [ SELECT id, Acteurs__c, (SELECT Name  from  CampaignMembers) From Campaign 
                                    Where id in:campId];
                                    
    for (Campaign camp: campaignList){
        if (camp.CampaignMembers.size()>0){
            //camp.Name = string.valueOf(camp.CampaignMembers[0].Name);
            for(integer i =1; i < camp.CampaignMembers.size(); i++)
                camp.Acteurs__c = camp.Acteurs__c+';'+string.valueOf(camp.CampaignMembers[i].Name);
        }
            else
            camp.Acteurs__c = null;
        }   
                    update campaignList;

    }
	
	
	//Test Class
	
	@isTest Private class AllActorsTest{
   
    @isTest static void InsetCm(){
    Campaign c = new Campaign ();
    c.Name = 'My Campaign';
    Insert c;
        
    CampaignMember cm = new CampaignMember();
    contact cont = new Contact (firstName='Bijou', lastName ='Girbson');
    Upsert cont;  
    cm.CampaignId = c.Id;
    cm.ContactId = cont.Id;


    insert cm;
        
 
    Delete cm;

   }
}

 
I need to have the first name of the the campaign member in a field called Acteurs in Campaign separate by comma. 
Se the attached picture. 
User-added image

the main error i get in this peice of code is: 
Method does not exist or incorrect signature: void add(Campaign) from the type List<Id> at line 7 column 19
 
Trigger allActors on CampaignMember (after update, after insert, after delete, after undelete){
    List <CampaignMember> cm = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;
    
    List <Id> campId = new List<Id> ();
    
    for (CampaignMember AllMember : cm) {
           campId.add(AllMember.Campaign);
   }
   
   List< Campaign> campaignList = [ SELECT id, (SELECT FirstName from  CampaignMembers) From Campaign 
                                    Where id in:campId];
                                    
    for (Campaign camp: campaignList){
        if (camp.CampaignMember.size()>0){
            camp.Name = string.valueOf(camp.CampaignMember[0].Acteurs__c);
            for(integer i =1; i < camp.CampaignMember.size(); i++)
                camp.Acteurs__c = camp.Acteurs__c+';'+string.valueOf(camp.CampaignMembers[i].Acteurs__c);
        }
            else
            camp.Acteurs__c = null;
        }
        
        
            update campaignList;

    }