+ Start a Discussion
MikeyOMikeyO 

Checkbox in one object (cases) triggers a project in another object

I have a checkbox in cases that says "Accept Project" if checked I want it to create a Project within a custom object that is part of PM Milestone downloaded from the AppExchange.
Any ideas on how to do that?
James LoghryJames Loghry
MikeyO,

I'm not too familiar with the Milestone package, but take a quick look to see if it doesn't already do this for you.

If not, it's a pretty simple trigger on the Case object.  In a nutshell, it would be a after insert, after update trigger that checks whether or not Accept Project has been inserted with or changed to true.  If Accept Project has been checked, then create a new Milestone record.  

As with any trigger, you'll want to do this in a bulkified manner, in case multiple cases are updated.

Below is a quick and dirty example of how you might go about this.  The example assumes that accept_project__c will never be unchecked the rechecked, so you might need to put some validation logic around that case.
 
trigger caseTrigger on Case(after insert, after update){

    List<sobject__c> projects = new List<sobject__c>();
    for(Case c : Trigger.new){
        if((Trigger.oldMap == null || !Trigger.oldMap.get(c.Id).Accept_Project__c) && c.Accept_Project__c){
            //Create new milestone record
            projects.add(new sobject__c());
        }
    }
    insert projects;
}

 
Sumitkumar_ShingaviSumitkumar_Shingavi
It should be pretty straighforward like below (Algorithm):
trigger CaseTrigger(after update) {
	
	Set<Id> sCaseIds = new Set<Id>();
	for(Case cs : Trigger.new) {
		if(cs.Accept_Project__c == TRUE
		&& cs.Accept_Project__c != Trigger.oldMap(cs.Id).Accept_Project__c) {
			sCaseIds.add(cs.Id);
		}
	}
	
	List<Project__c> lProjects = new List<Project__c>();
	
	for(Case cs : [SELECT Id, CaseNumber FROM Case WHERE Id in :sCaseIds]) {
		//Step 1: Put all required fields from Case in above URL in "for"
		//Step 2: Create Project Record like Project__c proj = new Project__c(Status__c = 'New', ..other fields..);
		//Step 3: lProjects.add(proj)
	}
	
	if(!lProjects.isEmpty()) {
		insert lProjects;
	}
}
Hope this helps! If yes, then mark it as solutions.
RamuRamu (Salesforce Developers) 
Follow the sample code as explained in the below article

https://developer.salesforce.com/forums/ForumsMain?id=906F00000008yuFIAQ