+ Start a Discussion
Tyler CaseyTyler Casey 

Default Text

Hi I am fairly new to salesforce so I apologize if this is an obvious question.

 

I am working on a Quote tool. There is both a Quote and Quote Request object. I need to have some of the info from the Quote Request show up as the default text in the quote, the quantity for example. I would do a formula but it doesn't show up when creating a new quote and its read only.

 

I have a master detail setup between the quote and quote request. I tried using the syntax from the formula field type, but it told me it was spelled wrong or didn't exist.

 

Thanks in advanced

 

Tyler

HusseyHussey

Hi Tyler,

 

As per your question i understood that  "Quote is the child object of Quote Reuest".

This can be done by writing a trigger on Quote__c(Let's say) object.

Here is the trigger to copy the value form Parent-to-child.

 

trigger copyQuantity on Quote__c(before insert, before update){

  List<Quote__c> qtList = List<Quote__c>();   
   for(Quote__c q : trigger.new){
      for(Quote_Request__c qr : [Select id, Name,Quantity__c from Quote_Request__c Where Id =:q.Quote_Request__c]){
          c.Quantity__c= qr.Quantity__c;
            qtList.add(q);
        }
       }
  update (qtList);

}

 

Tyler CaseyTyler Casey

Thanks so much for your help when I try to save it it gives me this error.

 

 Error: Compile Error: unexpected token: 'List' at line 3 column 26
Janet GuoJanet Guo

It'll be hard to help debug the code without seeing it, in the instance.

 

If you are having trouble with Apex, have you considered just using a workflow rule to update the field you need on creation of the Quote record? You would be guided by the Salesforce UI and you wouldn't need to worry about Apex or setting the security for an Apex class.

HusseyHussey

you can use the following code:

 

 trigger copyQuantity on Quote__c(before insert, before update){
     List<Quote__c> qtList = new List<Quote__c>();
       for(Quote__c q : trigger.new){
            for(Quote_Request__c qr : [Select id, Name,Quantity__c from Quote_Request__c Where Id =:q.Quote_Request__c]){
                    q.Quantity__c= qr.Quantity__c;
                   qtList.add(q);
            }
      }
  }