• sushant sus
  • NEWBIE
  • 289 Points
  • Member since 2013

  • Chatter
    Feed
  • 8
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 139
    Replies
I am spending too much time on this - and I thought this would be REALLY easy.

GOAL:  Update USER custom fields with custom fields from TASK on TASK CREATE.  Here's what I tried - it compiles, but does not work:

trigger UpdateLastChkInOnUser on Task (after insert) {
for(Task t: Trigger.new)
{
   User u = [Select Id from User where Id = :t.whoId] ;
   u.LastChkIn_DateTime__c = t.Check_In_Date_Time__c ;
   u.LastChkIn_Latitude__c = t.Check_In_Latitude__c ; 
   u.LastChkIn_Longtitude__c = t.Check_In_Longtitude__c ;
   update u;
}

}

Hi,

 

Please help me to convert string to Byte code using apex.

In java we have Byte data type to convert string to Byte.  

 

 

Thanks Much...!

Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
Opportunity opp=[Select id,name,accountId from Opportunity];
 Map<String,string> valueMap=new Map<String,String>();

    for(opportunity o:opp)
           {
                for(String fieldName: fieldMap.keySet())
                {
                    **valueMap.put(fieldName,o);**
                }

           }

 I want to create a map of apiname and value pair..please help... 

i want record value...like if apiname of opportunity field is name..then i want record value..ie opportunity name...

I'm attempting to write a trigger to create a new custom object record, when a Contact record meets specific criteria.  The problem is, the trigger is creating 2 records instead of 1.

 

Code below:

trigger createPreferenceWeb on Contact (before update) {
    
    List <rethink3__Requirements__c> prefToInsert = new List <rethink3__Requirements__c> ();
   
    
    for (Contact c : Trigger.new) {

        if (c.Web_To_Lead__c = true){  
        
        rethink3__Requirements__c p = new rethink3__Requirements__c ();
        
        p.rethink3__Contact__c = c.Name;
        p.rethink3__Contact__c = c.Id;
        p.Down_Payment_Available__c = c.Down_Payment_Available__c;
        p.Maximum_Price__c = c.Maximum_Price__c;

        
        prefToInsert.add(p);
        
        
        }
        
    }
    try {
        insert prefToInsert; 
    } catch (system.Dmlexception e) {
        system.debug (e);
    }
    
}

 

Hi All,

 

Can any one help me,

 

I have a problem with the schedule jobs, i have total 50 jobs. in this I want to delete the firsh 25 jobs which were not scheduled next time. I am using timestamp wile scheduling the job.

Ex:

 

Job 1 cronExpression='0 5 10 5 2013 ';

Job 2 cronExpression='0 10 10 5 2013 ';

Job 3 cronExpression='0 15 10 5 2013 ';

Job 4 cronExpression='0 25 10 5 2013 ';

Job 5 cronExpression='0 30 10 5 2013 ';

....

like up to

job 20

I want to delete from job1 to job 10;

 

 

please suggest me.

I've got a custom VF page in which I'm trying to allow users to run a search from to find specific form numbers when ordering supplies.  However, I don't think I've set it up properly and could use some help trying to figure out where I've gone wrong because the search seems to at least execute, but not return any values to the intended table.

The lines from my controller governing the search are here:

public String query {get; set;}
public List<MG_Forms__c> inventory {get; set;}

public PageReference runQuery()
{
if(query.length() < 2){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Search string must be at least two characters.' );
ApexPages.addMessage(myMsg);
return null;
}
List<List<MG_Forms__c>> searchResults=[FIND :query IN ALL FIELDS RETURNING MG_Forms__c (Form_Number__c, Name, Form_Title__c, State_Specific__c, Cancellable__c, In_Use__c)];
inventory=searchResults[0];
return null;
}

 

 

The VF snippet for the search in the main page is here:

<script>
 var newWin=null;
 function openLookupPopup(name, id)
 {
  var url="/apex/Popup?namefield=" + name + "&idfield=" + id;
  newWin=window.open(url, 'Popup','height=500,width=600,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');
  if (window.focus)
  {
   newWin.focus();
  }
   return false;
    }
 function closeLookupPopup()
 {
    if (null!=newWin)
    {
       newWin.close();
    } 
 }
    </script>
      <apex:pageBlockSection >
          <apex:panelGroup >
          <apex:outputLabel for="item1">Select form number for Item 1:</apex:outputLabel>
         <apex:panelGroup >
<apex:outputLabel for="item1">Select form number for Item 1:</apex:outputLabel>
<apex:inputHidden value="{!MG_Forms__c.Name}" id="targetId" />
<apex:inputText size="70" value="{!MG_Forms__c.Form_Number__c}" id="targetName" onFocus="this.blur()" disabled="false"/> <a href="#" onclick="openLookupPopup('{!$Component.targetName}', '{!$Component.targetId}'); return false">Lookup</a>

 And the VF for the Popup to conduct the search here:

<apex:page StandardController="MG_Forms__c" extensions="SupplyOrderController" sidebar="false" showheader="false">
<script language="javascript">
window.onload = new function()
{
// bring popup window to front
window.focus();
var ele=document.getElementById('{!$Component.form.block.section.query}');
if (ele)
{
ele.focus();
}
}

function fillIn(name, id)
{
var winMain=window.opener;
if (null==winMain)
{
winMain=window.parent.opener;
}
var ele=winMain.document.getElementById('{!$CurrentPage.parameters.namefield}');
ele.value=name;
ele=winMain.document.getElementById('{!$CurrentPage.parameters.idfield}');
ele.value=id;
CloseWindow();
}

function CloseWindow()
{
var winMain=window.opener;
if (null==winMain)
{
winMain=window.parent.opener;
}
winMain.closeLookupPopup();
}
</script>

<apex:messages />
<apex:form id="form" >

<div style="width 100%">
<apex:pageBlock title="Lookup" id="block">

<apex:pageBlockSection id="section">
Enter search text and click Go<br/>
<apex:inputText value="{!query}" id="query"/>
<apex:commandButton value="Go" action="{!runQuery}"/>
</apex:pageBlockSection>
</apex:pageBlock>

<apex:pageBlock >
<apex:pageBlockSection columns="1">
<apex:pageBlockTable value="{!inventory}" var="MG_Forms__c">
<apex:column headerValue="Form Number">
<apex:outputLink value="#" onclick="fillIn('{!MG_Forms__c.Form_Number__c}', '{!MG_Forms__c.Name}')">{!MG_Forms__c.Form_Title__c}</apex:outputLink>
</apex:column>
<apex:column headerValue="State Specific" value="{!MG_Forms__c.State_Specific__c}"/>
<apex:column headerValue="Cancellable" value="{!MG_Forms__c.Cancellable__c}"/>
<apex:column headerValue="In Use" value="{!MG_Forms__c.In_Use__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<button type="button" onclick="CloseWindow();">Close Window</button>
</div>
</apex:form>
</apex:page>

Need some help please.

 

We have a related record on the opportunity called "prospect". The prospect simply connects the opportunity to contacts. We have a related list for prospects, but the users want an easy way to create multiple "prospects" at one time. 

 

I want to create a button on the related list that takes you to a VF page with a list of contacts by name.  I will need to select multiple names then submit, creating a prospect record for each selected contact.  

 

Any Ideas?

I have created a site to enter email and password.  The object used is contact, the fields used is contact.email and contact.password__c.

 

After the user enter the email and password, I have already placed to check for the existance of email, blank values etc.

 

I would like to check whether the password entered by the user is the same as what is there in the record corresponding to the email entered.

 

Not sure how to figure the logic.  any body can advice?

I have to send a report attached as csv in email. i am using work flow with visual force email template 
Visual forceTemplate code 

<messaging:emailTemplate subject="SFDC AUTO EMAIL : CAP SUMMARY" recipientType="User" >
<messaging:plainTextEmailBody >
Hi,
</messaging:plainTextEmailBody>

<messaging:attachment filename="CapSummary.csv" >

<c:ReportExportController xstrRptname="00O0k000000SNDn"/>  // hard coded value in class for testing please refer below 
</messaging:attachment>
</messaging:emailTemplate>

Vf Component :
<apex:component controller="CSVStream" access="global">
     <apex:attribute name="xstrRptname" description="report ID" type="String" assignTo="{!strRptname}"/>
     
      <apex:outputText value="{!CSVStreamvalue}" escape="false"/>
</apex:component>

Apex class:
public without sharing class CSVStream {

    public static Boolean isTest;
    public static String strEmailAddr;
    public static String strOut{get;set;}
    public static Boolean restRequested;
    public String strEmail{get;set;}
    public String strRptname{get;set;}

    void CSVStream () {

            strOut = '';
            
                   
     }

    public String getCSVStreamvalue() {

        restRequested = System.isFuture() || System.isScheduled();
        executeRpt();
        return strOut;
    }

    public void executeRpt() {

        String requestURL;
       // requestURL = '/00O0k000000SNDn' + strRptname + '?csv=1&exp=1';
        requestURL = '/00O0k000000SNDn'+'?export=1&enc=UTF-8&xf=csv'; // hard coded report id 
        strOut = new PageReference(requestURL).getContent().toString();
        System.debug('CALLING executeRpt:  output= ' + strOut );
    }

}

I fire workflow base on condition which call this email alert with vf email template ...

Thing that figure out 
in vf component if i comment this line 
<apex:outputText value="{!CSVStreamvalue}" escape="false"/>
i am getting blank csv . other wise i am not receving any mail .

Other thing i debug apex code in console and it return data. i was able to get debug log of "CALLING executeRpt:  output"

I request developer community to help me on this ..Thanks 

 
For testing purpose, i have commented all code and only embedded css of bootstrap. But it reduces size of lightning tab.

<aura:component controller="ServiceproviderController" implements="force:appHostable" access="global">
    <ltng:require  styles="/resource/bootstrap337/bootstrap-3.3.7-dist/css/bootstrap.min.css,/resource/bootstrap337/bootstrap-3.3.7-dist/css/bootstrap.min.css.map"
      scripts='/resource/jquery224,/resource/bootstrap337/bootstrap-3.3.7-dist/js/bootstrap.min.js'
</aura component>

Any body faces same issue while using bootstrap.I want to use bootstrap only for my functionality.
in map ,map<id,list<attachment>> attach=new map<id,list<attachment>>(); i am having id as parent id of attachment as opportunity . opportunity has one field type number count default set as 0
for(id ids: attach.keyset()){
list<attachment> acc= attach.get(ids);
opportunity op= new opportunity(id=ids);
1.system.debug('bbttttttt'+(Integer)acc.size()+'jjjj'+op);
2.op.count__c=op.count__c+(integer)acc.size();
3.system.debug('bbttttttt'+(Integer)acc.size()+'jjjj'+opCount__c);
2 line i am getting null pointer exception
1 line returns me acc size and opportunity id
3 line written me acc.size and null
why this is happening
it use to work when you initalise object as opportunity op= new opportunity(id=ids);
it create instance of that
but now its not working
.................................................

 

Please help .............

 

my line of debug

 

 system.debug('11111111133311'+sumcheck);    
                                system.debug('1111111111767771'+sumchek2);  
                                system.debug('00000000000000'+sumchekaborted);  
                                
                                system.debug('11111111199999911'+parentmap.get(c2.parentid).BudgetedCost);
                                sumchek3 = (sumcheck + sumchek2);
                                system.debug('1111115555555555'+sumchek3); 

 

sumcheck3 should show 50,000 but is showing 85000 as sumchek2 is 0.0 and sumcheck is 50,000

 

 

now debug log

 

17:17:18.077 (77731000)|USER_DEBUG|[319]|DEBUG|1111111113331150000.0
17:17:18.077 (77736000)|SYSTEM_METHOD_EXIT|[319]|System.debug(ANY)
17:17:18.077 (77746000)|SYSTEM_METHOD_ENTRY|[320]|String.valueOf(Object)
17:17:18.077 (77759000)|SYSTEM_METHOD_EXIT|[320]|String.valueOf(Object)
17:17:18.077 (77768000)|SYSTEM_METHOD_ENTRY|[320]|System.debug(ANY)
17:17:18.077 (77773000)|USER_DEBUG|[320]|DEBUG|11111111117677710.0
17:17:18.077 (77778000)|SYSTEM_METHOD_EXIT|[320]|System.debug(ANY)
17:17:18.077 (77786000)|SYSTEM_METHOD_ENTRY|[321]|String.valueOf(Object)
17:17:18.077 (77800000)|SYSTEM_METHOD_EXIT|[321]|String.valueOf(Object)
17:17:18.077 (77809000)|SYSTEM_METHOD_ENTRY|[321]|System.debug(ANY)
17:17:18.077 (77814000)|USER_DEBUG|[321]|DEBUG|0000000000000035000.0
17:17:18.077 (77819000)|SYSTEM_METHOD_EXIT|[321]|System.debug(ANY)
17:17:18.077 (77841000)|SYSTEM_METHOD_ENTRY|[323]|MAP<Id,Campaign>.get(Object)
17:17:18.077 (77862000)|SYSTEM_METHOD_EXIT|[323]|MAP<Id,Campaign>.get(Object)
17:17:18.077 (77916000)|SYSTEM_METHOD_ENTRY|[323]|String.valueOf(Object)
17:17:18.077 (77928000)|SYSTEM_METHOD_EXIT|[323]|String.valueOf(Object)
17:17:18.077 (77937000)|SYSTEM_METHOD_ENTRY|[323]|System.debug(ANY)
17:17:18.077 (77943000)|USER_DEBUG|[323]|DEBUG|11111111199999911100000
17:17:18.077 (77948000)|SYSTEM_METHOD_EXIT|[323]|System.debug(ANY)
17:17:18.077 (77971000)|SYSTEM_METHOD_ENTRY|[325]|String.valueOf(Object)
17:17:18.077 (77989000)|SYSTEM_METHOD_EXIT|[325]|String.valueOf(Object)
17:17:18.077 (77998000)|SYSTEM_METHOD_ENTRY|[325]|System.debug(ANY)
17:17:18.078 (78003000)|USER_DEBUG|[325]|DEBUG|111111555555555585000.0

i have two object A and B

 

object B  has 2 mater detail and 2 lookup relation

 

now when in object A I want to create master detail relation ship with object B . But in second stepof creating (choose the related object )

 

it is not showing object B .. to choose

 

please give me some reason for this  why it is not showing

i have two object A and B

 

object B  has 2 mater detail and 2 lookup relation

 

now when in object A I want to create master detail relation ship with object B . But in second stepof creating (choose the related object )

 

it is not showing object B .. to choose

 

please give me some reason for this  why it is not showing

 

 

I have to send a report attached as csv in email. i am using work flow with visual force email template 
Visual forceTemplate code 

<messaging:emailTemplate subject="SFDC AUTO EMAIL : CAP SUMMARY" recipientType="User" >
<messaging:plainTextEmailBody >
Hi,
</messaging:plainTextEmailBody>

<messaging:attachment filename="CapSummary.csv" >

<c:ReportExportController xstrRptname="00O0k000000SNDn"/>  // hard coded value in class for testing please refer below 
</messaging:attachment>
</messaging:emailTemplate>

Vf Component :
<apex:component controller="CSVStream" access="global">
     <apex:attribute name="xstrRptname" description="report ID" type="String" assignTo="{!strRptname}"/>
     
      <apex:outputText value="{!CSVStreamvalue}" escape="false"/>
</apex:component>

Apex class:
public without sharing class CSVStream {

    public static Boolean isTest;
    public static String strEmailAddr;
    public static String strOut{get;set;}
    public static Boolean restRequested;
    public String strEmail{get;set;}
    public String strRptname{get;set;}

    void CSVStream () {

            strOut = '';
            
                   
     }

    public String getCSVStreamvalue() {

        restRequested = System.isFuture() || System.isScheduled();
        executeRpt();
        return strOut;
    }

    public void executeRpt() {

        String requestURL;
       // requestURL = '/00O0k000000SNDn' + strRptname + '?csv=1&exp=1';
        requestURL = '/00O0k000000SNDn'+'?export=1&enc=UTF-8&xf=csv'; // hard coded report id 
        strOut = new PageReference(requestURL).getContent().toString();
        System.debug('CALLING executeRpt:  output= ' + strOut );
    }

}

I fire workflow base on condition which call this email alert with vf email template ...

Thing that figure out 
in vf component if i comment this line 
<apex:outputText value="{!CSVStreamvalue}" escape="false"/>
i am getting blank csv . other wise i am not receving any mail .

Other thing i debug apex code in console and it return data. i was able to get debug log of "CALLING executeRpt:  output"

I request developer community to help me on this ..Thanks 

 
I am spending too much time on this - and I thought this would be REALLY easy.

GOAL:  Update USER custom fields with custom fields from TASK on TASK CREATE.  Here's what I tried - it compiles, but does not work:

trigger UpdateLastChkInOnUser on Task (after insert) {
for(Task t: Trigger.new)
{
   User u = [Select Id from User where Id = :t.whoId] ;
   u.LastChkIn_DateTime__c = t.Check_In_Date_Time__c ;
   u.LastChkIn_Latitude__c = t.Check_In_Latitude__c ; 
   u.LastChkIn_Longtitude__c = t.Check_In_Longtitude__c ;
   update u;
}

}
I created a search method called search_now that is used to search for the matching ID inputted into the search box. The code is below.

 public PageReference search_now(){
    results=(List<Work_Item__c>)[FIND:ID IN ALL FIELDS RETURNING Work_Item__c(Work_Item_ID__c, Name,Accountable_IT_leader__c,Percent_Complete__c,LSEF_Stage_del__c)][0];
    return null;
    }

I want to be able to leave the input field blank and when I search it would populate all the records in that object. What code would I insert to make that possible? 
What is the Best way to handle email war or infinite loop which creates a large number of cases, caused due to Automatic Reply or Auto Response or Out of Office replies in Email to Case?

Couple of ways i explored that might work.

1: Write a Trigger before insert for the case , here you check if the subject has key words like automatic reply or OOR and if found then do not create a case for such emails. This will avoid any new cases being created after the 1st one, no email will be sent back to the sender as no new case was created and this will stop the loop.
Cons: If the email comes with keyword other than the ones you are checking in the subject then it might not work, will have to try to capture all such keywords to stop it from creating more cases.

2: I read some blogs where people suggested to write a tigger which will check if more than 3 emails are received from the same email id with the same subject in a short duration of time if found then kill the loop and not create more cases.
Cons: I see that the biggest drawback here is that it will still create a 3 cases before it decides that this is a auto reply email frenzy.
2nd con i see is that sometime due to various network/organisation/outlook problems the auto reply email might not be received immd and this might make the system beleive that its a valid response and create a new case.

3: We currently do not have the Thread id or the case id on the subject on the template that we use to send emails back to customer for cases created , will adding the thread id on the subject link it in a way that when an auto reply email is received it knows that its the same thread id and not create an addional case. We do have a thread and case id in the body of the email. 

Does anybody have the most efficient way to handle this common problem?
Hi,

Scenario is, In Account object I have "Legal Entity" field, as we all know that there must be a relationship between Oppurtunity and Account objects.
So in Oppurtunity I have created one formula field like "Account Legal Entity" (formula is TEXT(Account.Legal_Entity__c)). Here I need to make this field as mandatory by using Validation rule. can anyone help me on this?
Thanks.
 **hi guys . i am getting blob as response   when i am using notes and attachments   its working fine its getting attached  now i  just want to display in next tab or next vf page** .
in map ,map<id,list<attachment>> attach=new map<id,list<attachment>>(); i am having id as parent id of attachment as opportunity . opportunity has one field type number count default set as 0
for(id ids: attach.keyset()){
list<attachment> acc= attach.get(ids);
opportunity op= new opportunity(id=ids);
1.system.debug('bbttttttt'+(Integer)acc.size()+'jjjj'+op);
2.op.count__c=op.count__c+(integer)acc.size();
3.system.debug('bbttttttt'+(Integer)acc.size()+'jjjj'+opCount__c);
2 line i am getting null pointer exception
1 line returns me acc size and opportunity id
3 line written me acc.size and null
why this is happening
it use to work when you initalise object as opportunity op= new opportunity(id=ids);
it create instance of that
but now its not working
.................................................

 
Hi ,

I want to create a task with the following info in my batch class , Please let me know how to do it



•Create a Task on the Contact with the following info -
1.    Subject = 'Bounceback Correction'
2.    Due Date = Today + 5
3.    Your assignment = 'Please update the email address for this Contact.'
4.    Owner = AE
5.    CreatedBy = Set it as test(user)
6.    Comment = 'The bounced email subject = ' + IndividualEmailResult.Subject


Thanks in Advance
trigger Attachmentant on Student_Profile__c (before insert, after insert,after update) {

if(trigger.isupdate)
{

list<Referral_Points__c> referral=new list<Referral_Points__c>();

for(Student_Profile__c s: trigger.new){
 
if(stoprecurssion.runonce()){

// when courcse_program name is updated, Create a new record of Referral Points///////

if(s.Course_Program__c !=null)
{
Referral_Points__c rp=new Referral_Points__c();
//////// Get the id and emailid of Referral from student_Profile //////////
Student_Profile__c referedpersonid=[select id ,Student_Profile__c.email__c from Student_Profile__c where UserName__c=:s.Referred_By_email__c limit 1];

rp.Member__c=referedpersonid.id;
rp.Refered_Person__c =s.id;
rp.Referred_by_Email__c=s.UserName__c;

referral.add(rp);
}
}
if ( !referral.isEmpty())
        insert referral;
}          
}

Hi,

Here I need to create a child record when only s.Course_Program__c  is changed but now its creating a child record every time when other fields are updated.
I need to creat a new child record only when s.Course_Program__c is updated... Pl help me to sortout this..
Thanks
hi friends
this is the controller code:
public class NewAndExistingController {

    public Customer__c customer{ get; private set; }

    public NewAndExistingController() {
        Id id = ApexPages.currentPage().getParameters().get('id');
        customer= (id == null) ? new Customer__c() :
            [SELECT Name, address__c, full_name__c FROM Customer__c WHERE Id = :id];
    }
     public String idNumber{
        get;
        // *** setter is NOT being called ***
        set {
            idNumber= value;
        }
    }
     public Customer__c getCustomer() {
        return customer;
    }
   
     public PageReference getCustomer1() {
    
        customer=
            [SELECT Name, address__c, full_name__c FROM Customer__c WHERE Name = :idNumber];
           if(customer==null)
           {
             customer=new Customer__c();
           }
            PageReference acctPage = new ApexPages.StandardController(customer).view();
        acctPage.setRedirect(true);
        return acctPage;
   
    }
    public PageReference save() {
        try {
            upsert(customer);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        //  After Save, navigate to the default view page:
        return (new ApexPages.StandardController(customer)).view();
    }
    public PageReference getSpecificCustomer()
    {
    PageReference pageRef = new PageReference('partialURL');
    return pageRef;
    }
    public PageReference gotoCompetitorSearch() {
    save();
    return Page.Shop;
}
}

this is the view code
<apex:page controller="NewAndExistingController">
    <apex:form >
        <apex:pageBlock mode="edit">
            <apex:pageMessages />
            <apex:pageBlockSection >
                <apex:inputField value="{!customer.Name}"/>
                <apex:commandButton action="{!getCustomer1}" value="find">
                  <apex:param name="idNumber"
                value="{!customer.Name}"
                assignTo="{!idNumber}"/>
               </apex:commandButton>
                <apex:inputField value="{!customer.address__c}" required="false"/>
                <apex:inputField value="{!customer.full_name__c}" required="false"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton action="{!gotoCompetitorSearch}" value="go shopping!" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

the find with getcustomer1 action isnt working.
i am a total beginner and any help will be grateful.
thanks, Liron. 
Hey  
I have a multipicklist on VF page  which has 4 values. Is there a way to set all the 4 values as default values in the multipicklist whenever anyone opens the VF page. I know we can set only one value as default value but I want all 4 values to be default.

Thanks
Hey all, 

Having some difficulty deploying this trigger. The code coverage is at 100% and it works if I set it as After Update, but i'm getting this error message when i swap the name to After Insert:

Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AutoContract: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AccountId]: [Accoun...

Trigger: 

trigger AutoContract on Zuora__SubscriptionProductCharge__c (After Insert) {
List<Contract> listContracts= new List<Contract>();
for(Zuora__SubscriptionProductCharge__c S: Trigger.new){
Contract C= new Contract();
C.Description=S.Zuora__ProductDescription__c;
C.accountid=S.Zuora__Account__r.Id;
C.Type_of_Sale__c=S.Zuora__ProductName__c;
C.Payment_Plan__c=S.Zuora__BillingPeriod__c;
C.Extended_Amount__c=S.Zuora__ExtendedAmount__c;
C.StartDate=S.Zuora__EffectiveStartDate__c;
C.AccountId = S.Zuora__Account__c;
C.RecordTypeId = '01230000000975K';
C.Contract_Total__c=S.Zuora__TotalContractValue__c;
C.Subscription_Charge_Name__c=S.Name;
C.Payment_Terms__c=S.Zuora__BillingPeriod__c;
C.UOM__c=S.Zuora__UOM__c;
C.Monthly_Payment__c=S.Zuora__MonthlyRecurringRevenue__c;
C.SubscriptionName__c=S.Zuora__Subscription__c;
C.Price__c=S.Zuora__Price__c;
C.Quantity__c=S.Zuora__Quantity__c;
C.Period_Start_Date__c=S.Zuora__BillingPeriodStartDay__c;
C.Type__c=S.Zuora__Type__c;
C.Model__c=S.Zuora__Model__c;
C.Rate_Plan_Name__c=S.Zuora__RatePlanName__c;
C.Product_SKU__c=S.Zuora__ProductSKU__c;
C.Rate_Plan_Description__c=S.Zuora__RatePlanDescription__c;
C.Product_Description__c=S.Zuora__ProductDescription__c;
C.Email__c=S.Zuora__Subscription__r.Zuora__CustomerAccount__r.Zuora__BillToWorkEmail__c;
C.Phone_Number__c=S.Zuora__Subscription__r.Zuora__CustomerAccount__r.Zuora__BillToWorkPhone__c;
C.Account_Number__c=S.Account_Number__c;
C.Bill_To_Name__c=S.Bill_To_Name__c;
C.Credit_Card_Expiration__c=S.Credit_Card_Expiration__c;
c.Credit_Card_Number__c=S.Credit_Card_Number__c;
c.Credit_Card_Type__c=S.Credit_Card_Type__c;
C.Email__c=S.Email__c;
C.Phone_Number__c=S.Phone__c;
C.Subscription_Status__c=S.Subscription_Status__c;
C.Subscription_Product_Charge__c=S.Id;
listContracts.add(c);
}

   if(listContracts.isEmpty()== false)
{Database.insert(listContracts);

}


  }

---------------------------


Test Class:

@isTest(SeeAllData=True)

public class AutoContract
{
Static testMethod void insertnewcontract() {

// Switch to the runtime context




List<Contract> ListContract = new List<Contract>();
Contract C = new Contract();
C.Type_of_Sale__c = 'Website';
C.Type__c ='Recurring';
C.StartDate = System.Today();

Account acc = new Account();
acc.Name =  'TestAcc' ;
acc.Customer_Status__c  = 'Active Client';
Insert acc;
Update acc;


Zuora__SubscriptionProductCharge__c spc = new Zuora__SubscriptionProductCharge__c();
spc.Name='Test';
spc.Zuora__ProductName__c = 'Website' ;
spc.Zuora__Type__c = 'Recurring';
spc.Zuora__EffectiveStartDate__c = System.Today();
spc.Zuora__Account__c= acc.Id;
Insert spc;

spc.Name='Test1';
Update spc;

insert ListContract;


}

}

Any tips would be greatly appreciated!
Hi All,
Generic Question:
In a visualforce page I have a custom component.I would like to know when it gets invoked or refreshed.
Like on every time page load or refresh constructor get called.
In the similar way on what all instances the component is invoked.

My Requirement:
I have a table which holds the records.
upon click of each record i want to invoke the component.
How do I acheive this?

Many thanks in advance!
Hi,


I want to get if Opportunity has an Field set of it's Fields, by knowing only that it's an opportunity record.


if any one know it than please let me know . thanks in advance ...... :)
I have created a vf Page..In that Account lookup is created when we select the account then it shows the all the contacts info of particular Account..How can we achieve this??
All,

I have a requirement in which I have a lookup filed and a multiselect picklist and based on the Account object(lookup) selected it should display main account and all its child account on the multiselect picklist.Is it possible to do it using standard salesforce functionalty. I know we can do this using vsiulaforce and apex but for only this functionality I do not want to create a new vf page and controller class.

Thanks

Looking at writing a simple Apex trigger to update a lead or contact field based on a task being added.

 

Have written an after insert Task trigger.  Quick question...

 

What is the best way to determine if the WhatID references a lead or contact?  Can the ID field be treated as a string and what are the ID prefixes for the Lead and Contact table?

 

Thanks!