• nitinkhunal.ax1786
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies

I want to write a trigger:

 

I've one 'Account' object and 'Contact' is its child object. In 'Account Object' there is a custom field Name 'Contact_Name__c'.

 

If i inserts any record in 'Contact' object than its 'First Name'  field value copies into the 'Contact_Name__c' field.

 

I wants that all 'Contact' Object records 'First Name' copies into 'Contact_Name__c' field those are in relationship with that 'Account' Object.

 

For Example:

 

If Account Name-'Acc' and in Child 'Contact' have 3 records.

and First Name of these records are- 'Nitin', 'Rahul', 'Ashwani'

 

Now i want these field values in Contact_Name__c field

Contact Name: Nitin, Rahul, Ashwani

 

So how i can do this. Please help me to write trigger for it.

trigger Incr on Service1__c (before insert) {

Increment__c incr=new Increment__c(name='Service1__c', In_Guarantee__c=1001, Out_of_Guarantee__c=2001, etc__c=3001);

for(Increment__c inc:[select id, name, In_Guarantee__c, Out_of_Guarantee__c, etc__c from Increment__c where name='Service1__c'])

incr=inc;

for(Service1__c ser:Trigger.new)
{
if(ser.Status__c=='In Guarantee')
{
ser.S_No__c=Integer.valueOf(incr.In_Guarantee__c++);
}
if(ser.Status__c=='Out of Guarantee')
{
ser.S_No__c=Integer.valueOf(incr.Out_of_Guarantee__c++);
}
if(ser.Status__c=='etc')
{
ser.S_No__c=Integer.valueOf(incr.etc__c++);
}
}
upsert incr;

}

trigger SONo1 on Service__c (before insert) {
   
    AutoNumber__c au=new AutoNumber__c(name='Service__c', In_Grantee__c=1001, Out_Of_Grantee__c=2001, etc__c=3001);
   
    for(AutoNumber__c auto:[select id, name,In_Grantee__c,Out_Of_Grantee__c,etc__c from AutoNumber__c where name='Service__c'])
   
    au=auto;
   
    for(Service__c ser:Trigger.new)
    {
        if(ser.Status__c=='INGrantee')
        {
            ser.SONO__c=Integer.valueOf(au.In_Grantee__c++);
        }
        if(ser.Status__c=='OutofGrantee')
        {
            ser.SONO__c=Integer.valueOf(au.Out_Of_Grantee__c++);
        }
        if(ser.Status__c=='etc')
        {
            ser.SONO__c=Integer.valueOf(au.etc__c++);
        }
       
    }
    upsert au;
}

Please tell me how to resolve this error..

public class RegistrationMethod
{
public string fnameI{get; set;}
public string lnameI{get; set;}
public string phoneI{get; set;}
public string emailI{get; set;}

 

public void Register()
{
Candidate__c c=new Candidate__c();
c.First_Name__c=fnameI;
c.Last_Name__c=lnameI;
c.Phone__c=phoneI;
c.Email__c=emailI;
insert c;

}

}

I've created the trigger below and now i'm having issues creating a test class. Can someone please help? trigger Parent_Name_Trigger on Account (after insert) { List sr = new List(); for (Account newAccount: Trigger.New) if (newAccount.Student_Name__c <> ''){ sr.add (new Student__c( Account__c = newAccount.ID, Name = newAccount.Student_Name__c)) ; } insert sr; }

Hi Everyone,

                              I am new to apex so this should be a simple question. I have a custom object with string fields. No duplicate should occur in any of these fields(before insert and before update).

                              I just want to add the duplictes to a list and in the end allow insert only if the list is NULL.

  • September 24, 2013
  • Like
  • 0

Hi Friends,

 

I have been stuck in one issue where I'm creating a mergefield in a apex controller's property and displaying it on the page.

 

Below is the code for reference:

 

public with sharing class emailtempcls {
public string temps {get;set;}
public emailtempcls()
{
    temps='{!$user.username}';
}
}

 

<apex:page Controller="emailtempcls">
{!temps}
{!$User.Username}
</apex:page>

Actual  Output:  {!$user.username}   xyz@gmail.com

Desired Output :  xyz@gmail.com  xyz@gmail.com

How can i convert temps value as the mergefield value on page?

 

Can anyone please help me in converting merge field value dynamically. Is it possible? Any Suggestions would be really appreciated.

 

 

Thanks!

 

Trigger: When a custom field picklist value in Opp = Yes, I want to create a new Project, make new Project name the same as the Opp name:

 

 

 

trigger CreateM1Project on Opportunity (after insert) {
    
    
   List<Milestone1_Project__c> NewProjects = new List<Milestone1_Project__c>();

    for (Opportunity opp: trigger.new)  {
        
 

 

 if (opp.Start_Project_Site_Id_Stage__c == 'Yes') {
        
            Milestone1_Project__c freshProject = new Milestone1_Project__c();
            freshProject.Name = opp.Name;
            
        }
    }
    insert NewProjects;
        
   }

trigger SONo1 on Service__c (before insert) {
   
    AutoNumber__c au=new AutoNumber__c(name='Service__c', In_Grantee__c=1001, Out_Of_Grantee__c=2001, etc__c=3001);
   
    for(AutoNumber__c auto:[select id, name,In_Grantee__c,Out_Of_Grantee__c,etc__c from AutoNumber__c where name='Service__c'])
   
    au=auto;
   
    for(Service__c ser:Trigger.new)
    {
        if(ser.Status__c=='INGrantee')
        {
            ser.SONO__c=Integer.valueOf(au.In_Grantee__c++);
        }
        if(ser.Status__c=='OutofGrantee')
        {
            ser.SONO__c=Integer.valueOf(au.Out_Of_Grantee__c++);
        }
        if(ser.Status__c=='etc')
        {
            ser.SONO__c=Integer.valueOf(au.etc__c++);
        }
       
    }
    upsert au;
}

Please tell me how to resolve this error..