function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sfdc SivaSfdc Siva 

Help to creating a new trigger

Hi Team,

Can any one please help me to create if contract enddate is changed manually then new opportunity needs to be create which is assosciate to lookup account on contract object.

Thanks

 
Best Answer chosen by Sfdc Siva
AvaneeshAvaneesh
 Hi

Writing a trigger for you that is working fine. trigger fire when the contract will be updated 
 
trigger ContractEndDateChange on Contract (after update) {

    List<Opportunity> allopprelated = new List<Opportunity>();
        for(Contract con : trigger.new)
        {
            if(!String.valueOf(Trigger.oldMap.get(Con.Id).EndDate).equals(String.valueOf(Trigger.newMap.get(Con.Id).enddate)))
            {
                Opportunity opp = new Opportunity();
                opp.Name='Contract' + con.ContractNumber;
                opp.CloseDate=Trigger.newMap.get(Con.Id).enddate;
                opp.StageName='Prospecting';
                opp.AccountId = con.AccountId;
                allopprelated.add(opp);                
            }
                
        }
    
        if(allopprelated.size() >0)
        {
            insert allopprelated;
        }
}

if you have any problem then you can ask me  and if this Please don't forget to mark as best answer 

Thank you
Avaneesh Singh

 

All Answers

AvaneeshAvaneesh
 Hi

Writing a trigger for you that is working fine. trigger fire when the contract will be updated 
 
trigger ContractEndDateChange on Contract (after update) {

    List<Opportunity> allopprelated = new List<Opportunity>();
        for(Contract con : trigger.new)
        {
            if(!String.valueOf(Trigger.oldMap.get(Con.Id).EndDate).equals(String.valueOf(Trigger.newMap.get(Con.Id).enddate)))
            {
                Opportunity opp = new Opportunity();
                opp.Name='Contract' + con.ContractNumber;
                opp.CloseDate=Trigger.newMap.get(Con.Id).enddate;
                opp.StageName='Prospecting';
                opp.AccountId = con.AccountId;
                allopprelated.add(opp);                
            }
                
        }
    
        if(allopprelated.size() >0)
        {
            insert allopprelated;
        }
}

if you have any problem then you can ask me  and if this Please don't forget to mark as best answer 

Thank you
Avaneesh Singh

 
This was selected as the best answer
Sfdc SivaSfdc Siva
Hi Avaneesh,

Thanks for your trigger.Will check and let you know.

ManyThanks

 
AvaneeshAvaneesh
Hii

Sure if still any problem then i will resolve that
Sfdc SivaSfdc Siva
Hi Avaneesh,

It's looks like working fine but i want to include some other trigger which are already having from Contract object.Can you please help me the same.

Thanks
AvaneeshAvaneesh
Hi

You want to say that you have a trigger which was on contract and you want to merge both triggers.
then send me your code I will merge them 


Thank you 
Avaneesh Singh