• Venkat Reddy sfd
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 9
    Replies
Hi all,
Below error I am getting when I am trying to save my Trigger. please any one could  help me.
Error: Field is not writeable: METADATA_Source__c.SOURCE_CODE__c

My code is here:
trigger BrandTrigger on METADATA_Brand__c (After insert, after delete, after undelete,  before delete,after update, before insert, before update) {
  TACTHelper.setStatus();
  
   if(Trigger.isInsert && Trigger.isAfter){
    List<Metadata_Campaign__c> NewCampaign= new list<Metadata_Campaign__c>();
    List<METADATA_Source__c> NewSource= new list<METADATA_Source__c>();
    Map<string,string> Map1 = new Map<string,string>();
    List<Metadata_Program__c> Program= [select id,name from Metadata_Program__c where Program_ID__c='54'];
    List<METADATA_Therapy_Class__c> therapy=[select id,name from METADATA_Therapy_Class__c where Therapy_Class_ID__c='6'];
    String s1,s2,s3,s4;
    
    List<METADATA_Source__c> Sr=[SELECT SOURCE_CODE__c from METADATA_Source__c where SOURCE_CODE__c like 'CGI%' ORDER BY SOURCE_CODE__c DESC ];

     for(METADATA_Brand__c brand : Trigger.new){
      Metadata_Campaign__c camp= new Metadata_Campaign__c();
      METADATA_Source__c Sourc= new METADATA_Source__c();
        
        if(Program.size() > 0){
         camp.Program__c=Program[0].Id;
       }
        if(therapy.size() > 0){
         camp.Therapy_Class__c=therapy[0].Id;
       }
         camp.Name=brand.Name;
         camp.Campaign_Type__c='CIC';
         camp.Description__c=brand.Name +'CIC General Information';
         camp.Metadata_Status__c='A';
         camp.DISPLAY_FLAG__c='Y';
         camp.Branded__c='Yes';
         camp.USMM__c='No';
         camp.HCP__c='No' ;
         Newcampaign.add(camp);
         
         Integer k=1;
         for(METADATA_Source__c sorce: Sr){
         	Integer l=1;
         //	System.debug(sorce.);
         	S1= sorce.SOURCE_CODE__c;
         	S2=S1.Substring(5,S1.length());
         	Integer M= integer.valueof(S2);
         	Integer J=M+1;
         	
         if(Newcampaign.size() > 0){
         	Sourc.Campaign__c=Newcampaign[0].Id;
         }
         if(J.size()> 0){
         Sourc.SOURCE_CODE__c='CGIPH'+J;  // Showing ERROR Here

         Sourc.Name='Trigger'; // This has to be Delete. there is no Field called Source Name in Source Object
         Sourc.SOURCE_DESCRIPTION__c= brand.Name +'CIC General Information';
         Sourc.MEDIUM_TYPE__c='PH';
         Sourc.MEDIA_SOURCE_CODE__c='PHONE';
         Sourc.PURPOSE_CODE__c='CS';
         Sourc.ORIGIN__c='IRMA';
         Sourc.METADATA_STATUS__c='A'; // Probably this is default no need to mentioned here  
         NewSource.add(Sourc);
     }
     }
     }
      
  insert NewCampaign;
  insert NewSource;
   }
}

Trigger can able to insert record into Metadata_campaign__c and Unable to insert record into  METADATA_Source__c.
Please any one can help.. its Urgent
Advance Thanks...
Hi All,

Please help me, here i am facing one problem, i have retrieved Source_Code__c from my Custom object by descending Order.

I have to trim first five chanrecters and convert that value to number , below SOQL query is working but Iam facing problem with Converting and trimming. could anyone please help me.
List<METADATA_Source__c> Sr=[SELECT id,SOURCE_CODE__c from METADATA_Source__c where SOURCE_CODE__c like 'CGI%' ORDER BY SOURCE_CODE__c DESC ];

     String S= Sr;  // I stucked here
     String S1=S.Substring(5,S.length());
     Integer i= integer.valueOf(S1);
     //Integer j=i+1;

Thanks Advance!!!!
Hi All,

Here is my requirement: i have field called Source_code__c in Metadata_source__c Object. Field type is "Text". from Source_code__c Field I have to select Maximum value and i have to TRIM first 5 Charecters. after that with Remaining Value i have to add +1 to that Value. How can i achieve this, please anyone can help me.
Eg:  Values of the Source_code__c= ABCDE1234 and ABCDZ1234 that means I have to get the value ABCDZ1234, From this value i have to TRIM or remove ABCDZ and Add+1 to 1234.
The Out put will be=1235.

I tried with creating new formula field For TRIM the Value but How can I select wich is the highest value and i dont know how to convert this string to Number in one Formula.

Formula is 
TRIM(RIGHT(SOURCE_CODE__c,4))
I want add the Formula Covert along with this Formula.

anyone can please help me.

Advance Thanks!!

                                                       

 

 
Hi All,

when i insert record in Metadata_brand__c object, automatically record should insert in Metadata_campaign__c. for that i have written trigger please check. i am stuck in the lookup fields value passing. please anyone can help me. this is trigger
 
trigger BrandTrigger on METADATA_Brand__c (after insert, after delete, after undelete,  before delete,after update, before insert, before update) {
  TACTHelper.setStatus();
  
  List<Metadata_Campaign__c> NewCampaign= new list<Metadata_Campaign__c>();
  
  List<Metadata_Program__c> Program= [select id,name from Metadata_Program__c where Program_ID__c='54'];
  
  List<METADATA_Therapy_Class__c> therapy=[select id,name from METADATA_Therapy_Class__c where Therapy_Class_ID__c='6'];
   
   for(METADATA_Brand__c brand : Trigger.new){
   	
  Metadata_Campaign__c camp= new Metadata_Campaign__c();
  
    camp.Name=brand.Name;
    camp.Program__c=Program.Id;  // I stucked here.
    camp.Therapy_Class__c=therapy.Id; // i stucked here.
    camp.Campaign_Type__c='CIC';
    camp.Description__c=brand.Name + 'CIC General Information';
    camp.Metadata_Status__c='A';
    camp.DISPLAY_FLAG__c='Y';
    camp.Branded__c='Yes';
    camp.USMM__c='No';
    camp.HCP__c='No' ;	
  	Newcampaign.add(camp);
  }
   insert NewCampaign;
  }

 // there is no relationship with each objects. how can i achieve this.

Error Message:System.StringException: Invalid id: Program.Id: Trigger.BrandTrigger: line 15, column 1 
I have Custom Field called Start_Date__c in my Custom Object. I have written Validation Rule for that. my requirement is whenever user creating a record the Start_Date__c shouldnt be past date, for this i have given validation rule: START_DATE__c < Today() 
Validation Working fine,

My requirement is, when user Edits the record in future without editing the start date, at that time validation triggering, it shouldnot fire at that time...
Example: user created record on 1st  nov 2014 and user Edited record on 5th november 2014 without editing the start date, validation rule not allowing user to save record with 01st november 2014. its shouldnot happen like this, could you please help me out.

Thanks in Advance...
Error: Invalid Data.
Review all error messages below to correct your data.
Update failed. First exception on row 0 with id a46K0000000D2YJIA0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This Item is Locked for Approval.: []

When i Submit for Approve. the above error iam getting. but the field is in status='created' only. but its giving that field allready in locked for approval
Hi all,

   I have approval process in Custom object.  There is a field called Status. If the status is equal to Closed, I want all fields on this custom object to be readonly i.e non editable.

that means, whenever final approval action compleates  record get approved. after record approved that record shouldnt be editable. how can we achieve this. please suggest me

Thanks in Advance...
hi I am getting this Error Colud you Please Check... Error:System.QueryException: List has no rows for assignment to SObject
Class.Mysecondcontroller.<init>: line 4, column 1


here is My Apex Class and VF Code
public class Mysecondcontroller {
 Public Opportunity opp;
  Public Mysecondcontroller(){
    Opp=[select id, name,CloseDate,StageName from 
          Opportunity where id=:ApexPages.currentpage().getParameters().get('Id')];
          
}
 Public Opportunity getOpportunity(){
   return opp;
  }
       Public pageReference SaveMethod(){
       Update Opp;
         return null;
  } 
}
<apex:page controller="Mysecondcontroller" tabStyle="Opportunity">
<apex:form >
<apex:pageBlock title="Opportunity Detail">
<apex:pageBlockButtons >
<apex:commandButton value="Save The Opportunity" action="{!SaveMethod}"/>
</apex:pageBlockButtons>
<apex:pageblockSection title="Opportunity" Columns="2" collapsible="False">
<apex:inputField value="{!Opportunity.Name}"/>
<apex:inputField value="{!Opportunity.CloseDate}"/>
<apex:inputField value="{!Opportunity.StageName}"/>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>


 

i have problem with my apex class.. iam unable get the Fieldnames like(In Brand object Name of the Brand field).. i have 4 custom objects . that 4 custom objects one field(Name field) i have to display in the pick list and i have to give field dependence. for field dependency it will work above VF code.i am  unable get that object fields. problem with my class. can u please look in to that. 

Thanks in advance....
 
public class objectController
{
    public Map <String, list<METADATA_Campaign__c>> CampMap = [select name from METADATA_Campaign__c];
    public Map<string, List<METADATA_Franchise__c>> FranMap =[select name from METADATA_Franchise__c];
    public Map<string, List<METADATA_Program__c>> ProgMap =[select name from METADATA_Program__c];
    public Map<string, List<METADATA_Brand__c>> BranMap =[select name from METADATA_Brand__c];

    public String franchise {get; set;}
    public String program {get; set;}
    public String campaign {get; set;}
    public String brand {get; set;}

    Public objectController()
    {   
        selectedObject = 'METADATA_Campaign__c';
    }

    public List<SelectOption> getcampaigns() 
    {
        List<SelectOption> campaignnames = new List<SelectOption>();
        List<String> entities = new List<String>(campMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            campaignnames.add(new SelectOption(name,name));
        }
        return campaignnames;
     }
     
     Public objectController()
    {   
        selectedObject = 'METADATA_Franchise__c';
    }
     
    public List<SelectOption> getfranchise() 
    {
        List<SelectOption> franchisenames = new List<SelectOption>();
        List<String> entities = new List<String>(FranMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            franchisenames.add(new SelectOption(name,name));
        }
        return franchisenames;
     }

 Public objectController()
    {   
        selectedObject = 'METADATA_Program__c';
    }
     
    public List<SelectOption> getProgram() 
    {
        List<SelectOption> Programnames = new List<SelectOption>();
        List<String> entities = new List<String>(ProgMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            Programnames.add(new SelectOption(name,name));
        }
        return Programnames;
     }
     
      Public objectController()
    {   
        selectedObject = 'METADATA_Brand__c';
    }
     
    public List<SelectOption> getbrand() 
    {
        List<SelectOption> brandnames = new List<SelectOption>();
        List<String> entities = new List<String>(BranMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            brandnames.add(new SelectOption(name,name));
        }
        return brandnames;
     }
 }

My VF Code...
 
<apex:page controller="objectController">
<apex:form > 
      <apex:pageBlock >
          <apex:pageBlockSection columns="4">

              <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Franchise :"/> 
                      <apex:actionRegion >      
                           <apex:selectList value="{!Franchise}" size="1">
                                    <apex:selectOptions value="{!franchisenames}"/>
                                    <apex:actionSupport event="onchange" rerender="Brand"/>
                            </apex:selectList>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
              
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Brand :"/>   
                      <apex:outputPanel id="Brand">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Brand}" size="1" disabled="{!ISBLANK(Franchise)}">
                                <apex:selectOptions value="{!Brandnames}"/>
                               <apex:actionSupport event="onchange" rerender="Program"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Program :"/>   
                      <apex:outputPanel id="Program">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Program}" size="1" disabled="{!ISBLANK(Brand)}">
                                <apex:selectOptions value="{!Programnames}"/>
                                 <apex:actionSupport event="onchange" rerender="Program"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Campaign :"/>   
                      <apex:outputPanel id="Campaign">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Campaign}" size="1" disabled="{!ISBLANK(Program)}">
                                <apex:selectOptions value="{!Objectnames}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>
Hi,
When I am saving my record i am getting this Error:
Attempted to upsert a null list
Error is in expression '{!save}' in component <apex:commandButton> in page brandpage: Class.Brandvfcontroller.save: line 15, column 1


here i am attaching my Apex code and VFcode. please correct it...
Thanks in Advance 
 
public with sharing class Brandvfcontroller {

 public METADATA_Brand__c bran;

  public void insertBrandvfcontroller(){
             bran = [SELECT Id, Name, BRAND_ABBR__c,BRAND_CODE__c,BRAND_END_DATE__c,BRAND_ID__c,BRAND_START_DATE__c,
                    DEFAULT_CAMPAIGN__c,Description__c,DISPLAY_FLAG__c,DISPLAY_SEQUENCE__c,Franchise__c,FRANCHISE_ID__c,
                       SRC_SYS_KEY__c,STATUS__c FROM METADATA_Brand__c WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
      }
       public METADATA_Brand__c getbran(){
       return bran;
       
       }
          public PageReference save() {
             Upsert bran;
             PageReference pref = new ApexPages.StandardController(bran).view();
               return pref;    
  }
}
 
<apex:page controller="Brandvfcontroller" showHeader="false" sidebar="false">
  <style>
        body .bPageBlock .pbBody .red .pbSubheader{
            background-color:#c00000;
        }
        body .bPageBlock .pbBody .grey .pbSubheader{
            background-color:#c0c0c0;
        }
        body .bPageBlock .pbBody .grey .pbSubheader h3{
            color:#000;
        }
        body .bPageBlock .pbBody .blue .pbSubheader{
            background-color:#0000FF;
        }        
    </style>
       <apex:form >     
    <apex:pageBlock title="Brand">
                <apex:outputPanel styleClass="blue" >
                <apex:pageblockSection title="Brand Details" columns="2" collapsible="false">
     <apex:inputField value="{!bran.Name}"/>
     <apex:inputField value="{!bran.Franchise__c}"/>
     <apex:inputField value="{!bran.BRAND_ABBR__c}"/>
     <apex:inputField value="{!bran.BRAND_CODE__c}"/>
     <apex:inputField value="{!bran.Description__c}"/>
     <apex:inputField value="{!bran.BRAND_ID__c}"/>
     <apex:inputField value="{!bran.BRAND_END_DATE__c}"/>
     <apex:inputField value="{!bran.BRAND_START_DATE__c}"/>
     <apex:inputField value="{!bran.DEFAULT_CAMPAIGN__c}"/>
     <apex:inputField value="{!bran.DISPLAY_FLAG__c}"/>
     <apex:inputField value="{!bran.DISPLAY_SEQUENCE__c}"/>
     <apex:inputField value="{!bran.FRANCHISE_ID__c}"/>
     <apex:inputField value="{!bran.SRC_SYS_KEY__c}"/>
     <apex:inputField value="{!bran.STATUS__c}"/>
                    </apex:pageblockSection>
            </apex:outputPanel>
     <apex:pageBlockButtons location="bottom" >
    <apex:commandButton value="Save" action="{!save}"/>

    
   </apex:pageBlockButtons>
  </apex:pageBlock>
  </apex:form> 
</apex:page>

 
I want selcted 4 Custom objects name fied as pick list value in my VF page. this is my code.. its not working...
 
<apex:page controller="objectController">
<apex:form > 
      <apex:pageBlock >
          <apex:pageBlockSection columns="4">

              <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Franchise :"/> 
                      <apex:actionRegion >      
                           <apex:selectList value="{!Franchise}" size="1">
                                    <apex:selectOptions value="{!franchisenames}"/>
                                    <apex:actionSupport event="onchange" rerender="Brand"/>
                            </apex:selectList>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
              
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Brand :"/>   
                      <apex:outputPanel id="Brand">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Brand}" size="1">
                                <apex:selectOptions value="{!Brandnames}"/>
                               <apex:actionSupport event="onchange" rerender="Program"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Program :"/>   
                      <apex:outputPanel id="Program">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Program}" size="1">
                                <apex:selectOptions value="{!Programnames}"/>
                                 <apex:actionSupport event="onchange" rerender="Program"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Campaign :"/>   
                      <apex:outputPanel id="Campaign">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Campaign}" size="1">
                                <apex:selectOptions value="{!Objectnames}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>

          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

and my apex class is below.. I think i have problem with Apex class. Please correct it.. 

Thanks In Advance.....
 
public class objectController
{
    public Map <String, list<METADATA_Campaign__c>> CampMap = [select name from METADATA_Campaign__c];
    public Map<string, List<METADATA_Franchise__c>> FranMap =[select name from METADATA_Franchise__c];
    public Map<string, List<METADATA_Program__c>> ProgMap =[select name from METADATA_Program__c];
    public Map<string, List<METADATA_Brand__c>> BranMap =[select name from METADATA_Brand__c];

    public String franchise {get; set;}
    public String program {get; set;}
    public String campaign {get; set;}
    public String brand {get; set;}

    Public objectController()
    {   
        selectedObject = 'METADATA_Campaign__c';
    }

    public List<SelectOption> getcampaigns() 
    {
        List<SelectOption> campaignnames = new List<SelectOption>();
        List<String> entities = new List<String>(campMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            campaignnames.add(new SelectOption(name,name));
        }
        return campaignnames;
     }
     
     Public objectController()
    {   
        selectedObject = 'METADATA_Franchise__c';
    }
     
    public List<SelectOption> getfranchise() 
    {
        List<SelectOption> franchisenames = new List<SelectOption>();
        List<String> entities = new List<String>(FranMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            franchisenames.add(new SelectOption(name,name));
        }
        return franchisenames;
     }

 Public objectController()
    {   
        selectedObject = 'METADATA_Program__c';
    }
     
    public List<SelectOption> getProgram() 
    {
        List<SelectOption> Programnames = new List<SelectOption>();
        List<String> entities = new List<String>(ProgMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            Programnames.add(new SelectOption(name,name));
        }
        return Programnames;
     }
     
      Public objectController()
    {   
        selectedObject = 'METADATA_Brand__c';
    }
     
    public List<SelectOption> getbrand() 
    {
        List<SelectOption> brandnames = new List<SelectOption>();
        List<String> entities = new List<String>(BranMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            brandnames.add(new SelectOption(name,name));
        }
        return brandnames;
     }
 }

 
<apex:page standardcontroller="METADATA_Campaign__c" extensions="CampaignPage" showHeader="false" sidebar="false">
  <style>
        body .bPageBlock .pbBody .red .pbSubheader{
            background-color:#c00000;
        }
        body .bPageBlock .pbBody .grey .pbSubheader{
            background-color:#c0c0c0;
        }
        body .bPageBlock .pbBody .grey .pbSubheader h3{
            color:#000;
        }
        body .bPageBlock .pbBody .blue .pbSubheader{
            background-color:#0000FF;
        }        
    </style>
       <apex:form >
    <apex:pageBlock title="Campaign Details">
  
                <apex:outputPanel styleClass="Red" >
                <apex:pageblockSection title="Campaign Information">
                        <apex:inputField value="{!camp.Name}"/>
     <apex:inputField value="{!camp.BRANDED__c}"/>
     <apex:inputField value="{!camp.METADATA_Status__c}"/>
     <apex:inputField value="{!camp.Program__c}"/>
     <apex:inputField value="{!camp.Therapy_Class__c}"/>
     <apex:inputField value="{!camp.Campaign_Code__c}"/>
     <apex:inputField value="{!camp.Campaign_ID__c}"/>
     <apex:inputField value="{!camp.Campaign_Type__c}"/>
     <apex:inputField value="{!camp.EndDate__c}"/>
     <apex:inputField value="{!camp.HCP__c}"/>
     <apex:inputField value="{!camp.Objective__c}"/>
     <apex:inputField value="{!camp.Description__c}"/>
     
     <apex:inputField value="{!camp.Program_ID__c}"/>
     <apex:inputField value="{!camp.StartDate__c}"/>
    
     <apex:inputField value="{!camp.Status__c}"/>
     <apex:inputField value="{!camp.Therapy_ClassID__c}"/>
     
     <apex:inputField value="{!camp.UA_CAMPAIGN_ID__c}"/>
     <apex:inputField value="{!camp.USMM__c}"/> 
                </apex:pageblockSection>
            </apex:outputPanel>
     <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlockButtons>

  </apex:pageBlock> 
  </apex:form> 
</apex:page>

//

Above VF Page is my Custom page, when i click sava the  record not saving and showing error that 'Attempted to upsert a null list
Error is in expression '{!save}' in component <apex:commandButton> in page metadatacampaignpage: Class.CampaignPage.save: line 14, column 1


here i am attaching my Apex class please saove this... Its urgent..

Thanks in Advance

public class CampaignPage {

    public CampaignPage(ApexPages.StandardController controller) {
    }
  public Metadata_Campaign__c camp;

   public void insertcampaign(){
   camp = [select id,BRANDED__c,Campaign_Code__c,Campaign_ID__c,Campaign_Type__c,Description__c,EndDate__c,HCP__c,Objective__c,Program__c,Program_ID__c,StartDate__c,  METADATA_Status__c,Status__c,Therapy_ClassID__c,Therapy_Class__c,UA_CAMPAIGN_ID__c,USMM__c from METADATA_Campaign__c where id =: ApexPages.currentPage().getParameters().get('id')];
   }
    public Metadata_Campaign__c getcamp(){
    return camp;
 }
   public system.PageReference save() {
    Upsert camp;
  PageReference pref = new ApexPages.StandardController(camp).view();
   return pref;
  }
  }
'
Hi All,

In Cases, I have 20 Images in Notes& Attachments, I need to Display one perticular Image on Visual Force page.. For that I need code..Please Help...!!
Hi all,
Below error I am getting when I am trying to save my Trigger. please any one could  help me.
Error: Field is not writeable: METADATA_Source__c.SOURCE_CODE__c

My code is here:
trigger BrandTrigger on METADATA_Brand__c (After insert, after delete, after undelete,  before delete,after update, before insert, before update) {
  TACTHelper.setStatus();
  
   if(Trigger.isInsert && Trigger.isAfter){
    List<Metadata_Campaign__c> NewCampaign= new list<Metadata_Campaign__c>();
    List<METADATA_Source__c> NewSource= new list<METADATA_Source__c>();
    Map<string,string> Map1 = new Map<string,string>();
    List<Metadata_Program__c> Program= [select id,name from Metadata_Program__c where Program_ID__c='54'];
    List<METADATA_Therapy_Class__c> therapy=[select id,name from METADATA_Therapy_Class__c where Therapy_Class_ID__c='6'];
    String s1,s2,s3,s4;
    
    List<METADATA_Source__c> Sr=[SELECT SOURCE_CODE__c from METADATA_Source__c where SOURCE_CODE__c like 'CGI%' ORDER BY SOURCE_CODE__c DESC ];

     for(METADATA_Brand__c brand : Trigger.new){
      Metadata_Campaign__c camp= new Metadata_Campaign__c();
      METADATA_Source__c Sourc= new METADATA_Source__c();
        
        if(Program.size() > 0){
         camp.Program__c=Program[0].Id;
       }
        if(therapy.size() > 0){
         camp.Therapy_Class__c=therapy[0].Id;
       }
         camp.Name=brand.Name;
         camp.Campaign_Type__c='CIC';
         camp.Description__c=brand.Name +'CIC General Information';
         camp.Metadata_Status__c='A';
         camp.DISPLAY_FLAG__c='Y';
         camp.Branded__c='Yes';
         camp.USMM__c='No';
         camp.HCP__c='No' ;
         Newcampaign.add(camp);
         
         Integer k=1;
         for(METADATA_Source__c sorce: Sr){
         	Integer l=1;
         //	System.debug(sorce.);
         	S1= sorce.SOURCE_CODE__c;
         	S2=S1.Substring(5,S1.length());
         	Integer M= integer.valueof(S2);
         	Integer J=M+1;
         	
         if(Newcampaign.size() > 0){
         	Sourc.Campaign__c=Newcampaign[0].Id;
         }
         if(J.size()> 0){
         Sourc.SOURCE_CODE__c='CGIPH'+J;  // Showing ERROR Here

         Sourc.Name='Trigger'; // This has to be Delete. there is no Field called Source Name in Source Object
         Sourc.SOURCE_DESCRIPTION__c= brand.Name +'CIC General Information';
         Sourc.MEDIUM_TYPE__c='PH';
         Sourc.MEDIA_SOURCE_CODE__c='PHONE';
         Sourc.PURPOSE_CODE__c='CS';
         Sourc.ORIGIN__c='IRMA';
         Sourc.METADATA_STATUS__c='A'; // Probably this is default no need to mentioned here  
         NewSource.add(Sourc);
     }
     }
     }
      
  insert NewCampaign;
  insert NewSource;
   }
}

Trigger can able to insert record into Metadata_campaign__c and Unable to insert record into  METADATA_Source__c.
Please any one can help.. its Urgent
Advance Thanks...
Hi All,

Here is my requirement: i have field called Source_code__c in Metadata_source__c Object. Field type is "Text". from Source_code__c Field I have to select Maximum value and i have to TRIM first 5 Charecters. after that with Remaining Value i have to add +1 to that Value. How can i achieve this, please anyone can help me.
Eg:  Values of the Source_code__c= ABCDE1234 and ABCDZ1234 that means I have to get the value ABCDZ1234, From this value i have to TRIM or remove ABCDZ and Add+1 to 1234.
The Out put will be=1235.

I tried with creating new formula field For TRIM the Value but How can I select wich is the highest value and i dont know how to convert this string to Number in one Formula.

Formula is 
TRIM(RIGHT(SOURCE_CODE__c,4))
I want add the Formula Covert along with this Formula.

anyone can please help me.

Advance Thanks!!

                                                       

 

 
Hi All,

when i insert record in Metadata_brand__c object, automatically record should insert in Metadata_campaign__c. for that i have written trigger please check. i am stuck in the lookup fields value passing. please anyone can help me. this is trigger
 
trigger BrandTrigger on METADATA_Brand__c (after insert, after delete, after undelete,  before delete,after update, before insert, before update) {
  TACTHelper.setStatus();
  
  List<Metadata_Campaign__c> NewCampaign= new list<Metadata_Campaign__c>();
  
  List<Metadata_Program__c> Program= [select id,name from Metadata_Program__c where Program_ID__c='54'];
  
  List<METADATA_Therapy_Class__c> therapy=[select id,name from METADATA_Therapy_Class__c where Therapy_Class_ID__c='6'];
   
   for(METADATA_Brand__c brand : Trigger.new){
   	
  Metadata_Campaign__c camp= new Metadata_Campaign__c();
  
    camp.Name=brand.Name;
    camp.Program__c=Program.Id;  // I stucked here.
    camp.Therapy_Class__c=therapy.Id; // i stucked here.
    camp.Campaign_Type__c='CIC';
    camp.Description__c=brand.Name + 'CIC General Information';
    camp.Metadata_Status__c='A';
    camp.DISPLAY_FLAG__c='Y';
    camp.Branded__c='Yes';
    camp.USMM__c='No';
    camp.HCP__c='No' ;	
  	Newcampaign.add(camp);
  }
   insert NewCampaign;
  }

 // there is no relationship with each objects. how can i achieve this.

Error Message:System.StringException: Invalid id: Program.Id: Trigger.BrandTrigger: line 15, column 1 
I have Custom Field called Start_Date__c in my Custom Object. I have written Validation Rule for that. my requirement is whenever user creating a record the Start_Date__c shouldnt be past date, for this i have given validation rule: START_DATE__c < Today() 
Validation Working fine,

My requirement is, when user Edits the record in future without editing the start date, at that time validation triggering, it shouldnot fire at that time...
Example: user created record on 1st  nov 2014 and user Edited record on 5th november 2014 without editing the start date, validation rule not allowing user to save record with 01st november 2014. its shouldnot happen like this, could you please help me out.

Thanks in Advance...
Error: Invalid Data.
Review all error messages below to correct your data.
Update failed. First exception on row 0 with id a46K0000000D2YJIA0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, This Item is Locked for Approval.: []

When i Submit for Approve. the above error iam getting. but the field is in status='created' only. but its giving that field allready in locked for approval
Hi,
When I am saving my record i am getting this Error:
Attempted to upsert a null list
Error is in expression '{!save}' in component <apex:commandButton> in page brandpage: Class.Brandvfcontroller.save: line 15, column 1


here i am attaching my Apex code and VFcode. please correct it...
Thanks in Advance 
 
public with sharing class Brandvfcontroller {

 public METADATA_Brand__c bran;

  public void insertBrandvfcontroller(){
             bran = [SELECT Id, Name, BRAND_ABBR__c,BRAND_CODE__c,BRAND_END_DATE__c,BRAND_ID__c,BRAND_START_DATE__c,
                    DEFAULT_CAMPAIGN__c,Description__c,DISPLAY_FLAG__c,DISPLAY_SEQUENCE__c,Franchise__c,FRANCHISE_ID__c,
                       SRC_SYS_KEY__c,STATUS__c FROM METADATA_Brand__c WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
      }
       public METADATA_Brand__c getbran(){
       return bran;
       
       }
          public PageReference save() {
             Upsert bran;
             PageReference pref = new ApexPages.StandardController(bran).view();
               return pref;    
  }
}
 
<apex:page controller="Brandvfcontroller" showHeader="false" sidebar="false">
  <style>
        body .bPageBlock .pbBody .red .pbSubheader{
            background-color:#c00000;
        }
        body .bPageBlock .pbBody .grey .pbSubheader{
            background-color:#c0c0c0;
        }
        body .bPageBlock .pbBody .grey .pbSubheader h3{
            color:#000;
        }
        body .bPageBlock .pbBody .blue .pbSubheader{
            background-color:#0000FF;
        }        
    </style>
       <apex:form >     
    <apex:pageBlock title="Brand">
                <apex:outputPanel styleClass="blue" >
                <apex:pageblockSection title="Brand Details" columns="2" collapsible="false">
     <apex:inputField value="{!bran.Name}"/>
     <apex:inputField value="{!bran.Franchise__c}"/>
     <apex:inputField value="{!bran.BRAND_ABBR__c}"/>
     <apex:inputField value="{!bran.BRAND_CODE__c}"/>
     <apex:inputField value="{!bran.Description__c}"/>
     <apex:inputField value="{!bran.BRAND_ID__c}"/>
     <apex:inputField value="{!bran.BRAND_END_DATE__c}"/>
     <apex:inputField value="{!bran.BRAND_START_DATE__c}"/>
     <apex:inputField value="{!bran.DEFAULT_CAMPAIGN__c}"/>
     <apex:inputField value="{!bran.DISPLAY_FLAG__c}"/>
     <apex:inputField value="{!bran.DISPLAY_SEQUENCE__c}"/>
     <apex:inputField value="{!bran.FRANCHISE_ID__c}"/>
     <apex:inputField value="{!bran.SRC_SYS_KEY__c}"/>
     <apex:inputField value="{!bran.STATUS__c}"/>
                    </apex:pageblockSection>
            </apex:outputPanel>
     <apex:pageBlockButtons location="bottom" >
    <apex:commandButton value="Save" action="{!save}"/>

    
   </apex:pageBlockButtons>
  </apex:pageBlock>
  </apex:form> 
</apex:page>

 
I want selcted 4 Custom objects name fied as pick list value in my VF page. this is my code.. its not working...
 
<apex:page controller="objectController">
<apex:form > 
      <apex:pageBlock >
          <apex:pageBlockSection columns="4">

              <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Franchise :"/> 
                      <apex:actionRegion >      
                           <apex:selectList value="{!Franchise}" size="1">
                                    <apex:selectOptions value="{!franchisenames}"/>
                                    <apex:actionSupport event="onchange" rerender="Brand"/>
                            </apex:selectList>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
              
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Brand :"/>   
                      <apex:outputPanel id="Brand">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Brand}" size="1">
                                <apex:selectOptions value="{!Brandnames}"/>
                               <apex:actionSupport event="onchange" rerender="Program"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Program :"/>   
                      <apex:outputPanel id="Program">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Program}" size="1">
                                <apex:selectOptions value="{!Programnames}"/>
                                 <apex:actionSupport event="onchange" rerender="Program"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
              
              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Campaign :"/>   
                      <apex:outputPanel id="Campaign">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!Campaign}" size="1">
                                <apex:selectOptions value="{!Objectnames}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>

          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>

and my apex class is below.. I think i have problem with Apex class. Please correct it.. 

Thanks In Advance.....
 
public class objectController
{
    public Map <String, list<METADATA_Campaign__c>> CampMap = [select name from METADATA_Campaign__c];
    public Map<string, List<METADATA_Franchise__c>> FranMap =[select name from METADATA_Franchise__c];
    public Map<string, List<METADATA_Program__c>> ProgMap =[select name from METADATA_Program__c];
    public Map<string, List<METADATA_Brand__c>> BranMap =[select name from METADATA_Brand__c];

    public String franchise {get; set;}
    public String program {get; set;}
    public String campaign {get; set;}
    public String brand {get; set;}

    Public objectController()
    {   
        selectedObject = 'METADATA_Campaign__c';
    }

    public List<SelectOption> getcampaigns() 
    {
        List<SelectOption> campaignnames = new List<SelectOption>();
        List<String> entities = new List<String>(campMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            campaignnames.add(new SelectOption(name,name));
        }
        return campaignnames;
     }
     
     Public objectController()
    {   
        selectedObject = 'METADATA_Franchise__c';
    }
     
    public List<SelectOption> getfranchise() 
    {
        List<SelectOption> franchisenames = new List<SelectOption>();
        List<String> entities = new List<String>(FranMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            franchisenames.add(new SelectOption(name,name));
        }
        return franchisenames;
     }

 Public objectController()
    {   
        selectedObject = 'METADATA_Program__c';
    }
     
    public List<SelectOption> getProgram() 
    {
        List<SelectOption> Programnames = new List<SelectOption>();
        List<String> entities = new List<String>(ProgMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            Programnames.add(new SelectOption(name,name));
        }
        return Programnames;
     }
     
      Public objectController()
    {   
        selectedObject = 'METADATA_Brand__c';
    }
     
    public List<SelectOption> getbrand() 
    {
        List<SelectOption> brandnames = new List<SelectOption>();
        List<String> entities = new List<String>(BranMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            brandnames.add(new SelectOption(name,name));
        }
        return brandnames;
     }
 }

 
I have created a custom object 'CaseTask__c'  and it has master detail relation ship with Case object.
When the case status is 'In-Progress', i need to lock the related list custom object record.

As you all know there are 3 ways to lock a record, 

1) Trigger
2) workflow rules
3) Validation rules

Please go through below link.

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


I have created a record type and associated to a read only page layout. 
And also i have written a workflow rule field update to change the record type of a custom object, when the case status is 'In-Progress'.
Finally activated the workflow rule.

But record type is not changing to read only page layout, after case status changes to In-Progress.  why?