0
public with sharing class Apparel_PageController {

    public List<Trendsters_Order__c> orders{get;set;}
    public String contactId{get;set;}
    public Case objCase{get;set;}

    public Decimal totalAmount{get;set;}
    public Decimal cartSize{get;set;}
    public String currentProductId{get;set;}

    public List<Trendsterz_Inventory__c> inventries {get;set;}

    public List<Trendsters_Order__c> cart{get;set;}


    public Apparel_PageController(){
        totalAmount = 0;
        cartSize = 0;
        cart = new List<Trendsters_Order__c>();
        User objUser = [select ContactId 
                        from User 
                        where Id = :UserInfo.getUserId()];
        contactId = objUser.ContactId;
        //contactId = '0037F00000a8HVg';
        objCase = new Case(ContactId=contactId);

        inventries = [select Id,Brand__c, Designer_Name__c, Design_Name__c, Price__c,Image_Url__c
                      from Trendsterz_Inventory__c 
                      LIMIT 10];    
    }

    public void fetchOrders(){

        orders = [SELECT Id,Name,Brand__c,Contact__c,Contact__r.Name, Contact__r.Email, 
                                            Designer_Name__c,Design_Name__c,Email__c,Price__c,Order_Status__c
                  FROM Trendsters_Order__c 
                  WHERE Contact__c = :contactId];

    }

    public void submitFeedback(){
        insert objCase;
    }

    public void addToCart(){        
        for(Trendsterz_Inventory__c inventry : inventries){
            if(currentProductId !=null && inventry.Id == currentProductId){
                Trendsters_Order__c order = new Trendsters_Order__c();
                system.debug('contactid -->'+contactId);
                order.Contact__c = contactId;
                order.Design_Name__c = inventry.Design_Name__c;
                order.Price__c= inventry.Price__c;
                                                          cart.add(order);
                break;
            }
        }
        cartSize = cart.size();
       // totalAmount = cart.size();
    }
    public void payProduct(){
              system.debug('cart -> ' + cart.size());
        insert cart;
    }


}
  • Error is preity clear. Contact is required and blank. Are you facing any challenge. – Tushar Sharma May 12 '18 at 7:58
  • In my system debug....it is fetching Contact ID.... – Saniya Virmani May 12 '18 at 8:06
  • After sometime it showed success.....it was happening yesterday also.....it failed and then after sometime automatically it got success – Saniya Virmani May 12 '18 at 8:10
  • You are getting ContactId always. – Tushar Sharma May 12 '18 at 8:22
  • M really new on this....it's just been 1 week that I have started working on salesforce.....can u please explain...what could the error be?.....coz exactly as u said Contact Id is getting fetched...but then y Required field Missing error is coming? – Saniya Virmani May 12 '18 at 8:28
1

One possibility to consider is that you are checking the code using different logins (users).

The User.ContactId is populated for user's that have setup their login via Self-Registration for Your Community because that mechanism starts from a Contact and hooks up a User to that Contact. But it is not populated for users that have a standard login created by a System Administrator.

If that is the case, your page should just output a message such as "Only community users can use this page". Or the page logic should be otherwise reconsidered for that case.

  • Thanku so much....but it is from a registered user. – Saniya Virmani May 12 '18 at 10:30
  • @SaniyaVirmani Ah OK. One other thing to check is that there are no triggers or workflows on Trendsters_Order__c that are resetting the ContactId. – Keith C May 12 '18 at 10:32
  • nop....@Keith C....there are no triggers and workflows – Saniya Virmani May 12 '18 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.