+ Start a Discussion
Nandigam RajeshNandigam Rajesh 

need to update a field in another custom object using only apex trigger.

hi here while updating the picklist field from to active to inactive need to insert a record in the invoice. Please find below code is not working.
trigger newinvoice on Contact (after update) {
    List<Invoice__c> recordsToupdate = new List<Invoice__c>();
    for (Contact c : [select id,name,status__c from Contact where status__c='active']) {
        if (Trigger.isupdate) {
            Invoice__c ln = new Invoice__c();
ln.name = 'aaa' ;           
        }
    }
    update recordsToupdate;
}

Regards
Rajesh
Raj VakatiRaj Vakati
What is the relation bwterrn contact and invoice  ?? can you give me an API NAMES

 
trigger newinvoice on Contact (after update) {
	
	  List<Invoice__c> recordsToupdate = new List<Invoice__c>();
   
	Map<Id,Contact> olgcons = Trigger.oldMap;
	for( Contact c :Trigger.new){
		If(c.status__c=='active' && olgcons.get(c.Id).status__c=!'active'){
			 Invoice__c ln = new Invoice__c();
ln.name = 'aaa' ;
		}
	}

    insert recordsToupdate;
}

 
Raj VakatiRaj Vakati
Here is the code for insert 
 
trigger newinvoice on Contact (after update) {
	
	  List<Invoice__c> recordsToupdate = new List<Invoice__c>();
   
	Map<Id,Contact> olgcons = Trigger.oldMap;
	for( Contact c :Trigger.new){
		If(c.status__c=='active' && olgcons.get(c.Id).status__c=!'active'){
			 Invoice__c ln = new Invoice__c();
ln.name = 'aaa' ;
recordsToupdate.add(ln);
		}
	}

    insert recordsToupdate;
}